lua-users home
lua-l archive

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


> 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