luabind 0.8.1 + lua 5.1.4: passe d object pointers are userdata
Dmitriy Mazovka <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, I've faced the problem with passing registered class object's pointer to lua. It is not resolved to table somewhy. I've traced with a debugger and the algorithm seems went well - there were proper calls of lua_setmetatable and lua_settable.
The code is like in the basic example:
class TestClass
{
public:
TestClass() {}
void Test() { printf("Hello\n"); }
};
TestClass obj;
lua_State *state = lua_open();
luabind::open(state);
luabind::module(state)[
luabind::class_<TestClass>("TestClass")
.def(luabind::constructor<>())
.def("Test", &TestClass::Test)
];
if (luaL_loadstring(state, "function main(c) c:Test() end") != 0 ||
lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
{
ErrorHandle(state);
}
if (luaL_loadstring(state, "obj = TestClass(); main(obj)") != 0 ||
lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
{
ErrorHandle(state);
}
luabind::globals(state)["tmp"] = &obj;
if (luaL_loadstring(state, "main(tmp)") != 0 ||
lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
{
ErrorHandle(state);
}
lua_close(state);
-----------------------
Output:
Hello
[string "function main(c) c:Test() end"]:1: attempt to index local 'c' (a userda
ta value)
Could you please give me some hint how to overcome this problem? :)
Regards,
_dm
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference