I have a problem with luabind, or at least i expect its a problem
I have an entity class that ive registered with lua,
ideally i want to subclass it and override its functions, from there i want to send it back to c++ and store it
additionally i want to be able to call its new functions from c++ from the stored object/pointer
however im currently struggling to even get c++ to take the object of type cEntity* back? in the lua script i can load the class, call its variables and functions, i try and send it to takeClass or takebOject but it comes out as a blank class with nothing set on it
for example foo->name is "" rather than "Entity1" and id is 0 rather than 1
anyideas what im doing wrong? ive searched on google for at least a week now with no luck of understanding this problem and its completely halting my progress on my project?
//#######################################################################
// Test function
//#######################################################################
void luaTest::TakeClass(cEntity* foo)
{
cout << foo->name << endl;
}
void luaTest::TakeObject(luabind::object foo)
{
cEntity* foobar = luabind::object_cast<cEntity*>(foo);
cout << foobar->name << endl;
}
void luaTest::luabindClass(lua_State* L)
{
//Somewhere else
module(L)
[
class_<luaTest>("luaTest")
.def(constructor<>())
.def("TakeClass", &luaTest::TakeClass)
.def("TakeObject", &luaTest::TakeObject)
];
globals(L)["test"] = this;
}
//#######################################################################
// Entiy Class
//#######################################################################
class cEntity
{
public:
string name;
int id;
cEntity();
~cEntity();
static void luabindClass(lua_State* L);
};
//#######################################################################
cEntity::cEntity()
{
name = "NotSet";
id = 0;
}
cEntity::~cEntity()
{
}
void cEntity::luabindClass(lua_State* L)
{
module(L)
[
class_<cEntity>("cEntity")
.def(constructor<>())
.def_readwrite("name", &cEntity::name)
.def_readwrite("id", &cEntity::id)
];
}
//#######################################################################
// Lua File
//#######################################################################
entity = cEntity();
entity.name = "Entity1";
entity.id = 1;
test:TakeClass(entity);
test:TakeObject(entity);
//#######################################################################
//#######################################################################
// main
//#######################################################################
....
/* run the script */
if (luaL_dofile(L, "avg.lua")) {
std::cout << lua_tostring(L, -1) << std::endl; // Print out the error message
}
....
//#######################################################################