(sidenote: This is game programming)
Binding entire classes to Lua using LuaBind is easy:
class test
{
test()
{
std::cout<<"constructed!"<<std::endl;
}
void print()
{
std::cout<<"works!"<<std::endl;
}
}
And then we can do:
module[some_lua_state]
[
class_<test>("test")
.def(constructor<>())
.def("print",&test::print)
];
Now I can create instances of the class in Lua and use it:
lua_example.lua
foo = test() //will print "constructed!" on the console
foo:print() //will print "works!" on the console
However, now I'd like to bind a specific instance of test to Lua. This would enable me to pass objects down to Lua, e.g. an instance of the Player-class and do something like:
Player:SetPosition(200,300)
As opposed to going the hard way and having something like
SetPosition("Player",200,300)
where the corresponding C++ SetPosition function needs to look up a std::map<std::string,Entity *> to find the player.
Is this even possible and if so, how can I do it in LuaBind?