lua-users home
lua-l archive

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

On Tue, 25 Aug 2020 at 08:42, Francisco Olarte <> wrote:
> Must it be kept in the stack or is it enoguh if I keep the original
> value referenced. I.e., I'm inside a method of one of my classes ( so
> I have a this pointer ) and I've arrived there from a C function which
> has the relevant userdata as first argument, index 1, and I have a
> string at the TOS, if I do:

The GC doesn't follow C pointers, only Lua value references.  The Lua
stack is a good temporary place.  for more "durable" references some
options are:

- in the registry
- as an upvalue to your C function
- in the userdata's metatable.

of course, any of these could be a direct reference to your string, or
a Lua table to hold it among other things.