[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Newbie: passing a userdata to Lua
- From: "etabubu" <marco@<a href="/cgi-bin/echo.cgi?d-sign.it">...</a>>
- Date: Mon, 11 Feb 2002 09:56:05 -0000
Hi, I'm a newbie in Lua and I'm trying to use it for our little game.
I used tolua to wrap my C++ class and it works fine... I can instantiate the class in Lua and use it. Ok, but I need to instantiate it in C++ and THEN pass the pointer to the Lua so it can use it.
Example: I have my little class Hello that has a SayIt() method.
After setting up all with tolua I can write in Lua:
and it works fine. But I want to do this:
... and then pass myhello to the Lua!
I tried defining a C Function for Lua:
int GetHello(lua_State *L)
lua_pushusertag(L, (void *) myhello, LUA_ANYTAG);
I registered this function with lua_register(...) and it works, but
when I try in Lua:
it throws an error, saying it attempted to access global variable 'h'
Maybe I didn't understand anything... so, what's the right way?
Thank yuo very much!