[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua and toLua++: Passing C++ created objects as arguments to Lua functions
- From: Bogusław Dziewierz <b.dziewierz@...>
- Date: Sun, 19 Mar 2006 12:41:05 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I've got a small problem concerning Lua 5.1 and toLua++.
I've set up my CLogicCore class to start up it's own lua state in the
constructor and then evaluate the following LUA function passing
itself (the CLogicCore object) as an argument:
function on_init_game (core_object)
new_map = CLogicMap:new()
core_object:addMap(new_map)
end
I use the following C++ code to pass CLogicCore object to
abovementioned Lua function:
[...]
void CLogicCore::init_game () {
lua_getglobal(this->lua_state, "on_init_game");
lua_pushlightuserdata(this->lua_state, (void*) this);
lua_call(this->lua_state, 1, 0);
}
[...]
Of course I've created proper toLua++ bindings before and I am able to
create and use my C++ objects in Lua (i.e. new_map = CLogicMap:new()
works perfectly okay, also all methods of new_map do work). The
problem is, that I can't use objects created in C++ and passed to Lua
functions as arguments (i.e. CLogicCore object)! I get "attempt to
index local 'core_object' (a userdata value)" error.
What is wrong?
Regards,
B.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEHUNQhIvbwGWxWWARAjMyAKCP90FAaCsoznr93wCDybVeO7Jl8QCfZAG9
7lFgDRm1Xn3JCexTMM4oACc=
=b3z4
-----END PGP SIGNATURE-----