|
James Porter wrote:
derefed wrote:I've just recently picked up Lua and have been exploring its potential as a possible game scripting engine for any future projects. For better integration with C++ I've chosen to play around with Luabind. So far, I've been quite impressed with its capabilities and ease of use. I have, however, run into a seemingly minor problem that I cannot, for the life of me, figure out.std::vector::at is an overloaded method (for const containers), so a function pointer to it is ambiguous. You need to explicitly cast it to the type you want:... .def("at",(int&(std::vector<int>::*)(size_t))&std::vector<int>::at) ...I'm going from memory on the above code, but it (or something like it) should work.- Jim
This compiles, but whenever I try to assign the value returned by v:at(0), for instance, I get an assertion error.
In the meantime, I've decided to provide an IntVector wrapper class around a vector<int> to see if I can get the desired functionality that way. This appears to work fine, except that I cannot figure out how to get references/pointers to work within Lua. Here's the Lua code I'm trying:
function makeivector() v = ivector() v:push_back(3) v:push_back(13) v:at(0) = 99 print("At(0): " .. v:at(0)) return v endWhere print is bound to a C++ function that will print the value to the screen, and where IntVector::at is defined as:
const int& IntVector::at(int i) { return v.at(i); }You see, what I would like is to have the ability to grab a value out of the vector, manipulate it, and have the change be reflected in the vector. I can't seem to find any resources on the web as to how Lua mimics pointer/reference types... how is this accomplished?
Thanks again!