[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Newbie: passing a userdata to Lua
- From: Nick Trout <Nick.Trout@...>
- Date: Mon, 11 Feb 2002 11:10:00 -0000
> I registered this function with lua_register(...) and it works, but
> when I try in Lua:
>
> h=GetHello()
> h:SayIt()
>
> it throws an error, saying it attempted to access global variable 'h'
I think the problem is that you have mismatched tags. You have to something
like :-
lua_pushusertag(L, (void *) myhello, tolua_tag(L,"Hello"));
Or, you could use toLua to create the Hello object. Just expose the
constructor Hello::Hello()
eg. toLua pkg:
class Hello {
Hello();
~Hello();
void SayIt();
};
then Lua code:
h = Hello:new() -- Hello::Hello()
h:SayIt()
h:delete() -- Hello::~Hello()
Nick