lua-users home
lua-l archive

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


> My question: Is there something
> tricky to take  into  account when  using  pointers to  lua_objects as
> userdata in tables ?

I haven't understood your point. "lua_objects" are no pointers, they are
integers, and should be handled as abstract data types in C (that is, the only
thing you can do with a lua_object is to give it back to Lua). If you have
pointers to lua_objects, they point to your own variables, since Lua never
gives you a lua_object address.

  What is a little tricky is not about pointers to lua_objects, but about
lua_objects themselves:

  Because Lua has automatic memory management and garbage collection,
  a |lua_Object| has a limited scope,
  and is only valid inside the block where it has been created.
  A C function called from Lua is a block,
  and its parameters are valid only until its end.
  It is good programming practice to convert Lua objects to C values
  as soon as they are available,
  and never to store |lua_Object|s in C global variables.

If you need a "non-volatile" reference to a Lua object in C, you must use
references (see lua_ref).

-- Roberto