lua-users home
lua-l archive

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


On Apr 12, 2014, at 10:32 AM, Thijs Schreijer <thijs@thijsschreijer.nl> wrote:

> 
> Question;
> When Lua returns a string, it returns a 'const', is that already a copy of the original Lua string, or is it the actual Lua string? If so, could that returned pointer then be used to link it to the refcount?
> 
> Thijs
> 
> 
> 

lua_tolstring() and lua_tostring() both return a direct pointer to the string within the Lua state; you should treat it as read-only (hence the const) and valid only while the stack index referenced is unchanged. So yes, you could find the refcount from the pointer, but I still think this is a risky approach, as it depends on assumptions about undocumented behaviors of the Lua VM.

—Tim