lua-users home
lua-l archive

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


Hi,

Daniel Collins wrote:
> The strings are immutable but need to persist in C longer than the
> duration of the API function called from Lua. So the string parameter
> passed in my method one would need to be copied into another buffer.

Ok, a returned string pointer is guaranteed to be valid as long
as the corresponding Lua string exists in the Lua stack (see the
description of lua_tolstring() in the Lua 5.1 manual).

But the current GC algorithm (as of Lua 5.0/5.1) does not move
objects. So right now you can also rely on the fact that the
string pointer is valid as long as there is _any_ reference to it
(i.e. from the table you use to store them). 

Yes, the latter means relying on implementation internals. But
nobody forces you to upgrade to a newer Lua version. The C API
usually changes over major versions, anyway.

Bye,
     Mike