lua-users home
lua-l archive

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


On 27/05/2014 18:31, Roberto Ierusalimschy wrote:
If it cannot, is it guaranteed somewhere in the docs or is it
implementation dependent?

It is implementation dependent. (Note that even the notion of "garbage
collection cycle" is implementation dependent. Lua uses an incremental
collector, which means that a cycle occurs distributed among several
points in time.)

Why do you need to know that?


A non-Lua application calls into a Lua plugin and expects to get from it a pointer to some C-struct filled with data (I cannot change this interface, it is predefined). It would be very handy to do something like:

  struct Info* info = lua_newuserdata(L, sizeof(struct Info));
  ..... // fill the fields of struct with data
  lua_pop(L,1);
  return info;

As it is known that the application uses the returned pointer immediately, it should be safe, unless 'info' is not collected.

--
Shmuel