lua-users home
lua-l archive

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

On Mon, May 07, 2007 at 09:14:19AM -0700, Jose Marin wrote:
> Is there any tutorial/sample on how to use light userdata to bind C++
> classes to Lua?

What are you trying to do?

> I used the sample on
> as a base to
> learn how to bind using lua_newuserdata, but I would like to use
> lua_pushlightuserdata to do this. 

userdata and lightuserdata aren't usually used for the same thing,
despite the confusingly similar names:

  Some people use light userdata as a cheap alternative to full
  userdata. This is not a typical use, however. First, with light
  userdata you have to manage memory by yourself, because they are not
  subject to garbage collection. Second, despite the name, full userdata
  are inexpensive, too. They add little overhead compared to a malloc
  for the given memory size.


> I've tried to change the sample code 
> Image *pi = (Image *)lua_newuserdata(L, sizeof(Image)); 
> *pi = im; 
> to this 
> Image *pi = new Image; 
> lua_pushlightuserdata(L, pi); 
> but it doesn't work. 

That looks right, so what do you mean by "work"? Could you say what