lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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:

c=new Hello()

and it works fine. But I want to do this:
in C++:
Hello *myhello;
myhello=new Hello();
... 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);
    return 1;

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!

    Bye Bye