[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How is string passed from Lua to C
- From: Mark Hamburg <mark@...>
- Date: Wed, 7 Dec 2011 18:16:29 -0800
On Dec 7, 2011, at 7:57 AM, Rebel Neurofog wrote:
> On Wed, Dec 7, 2011 at 7:35 PM, Mark Hamburg <firstname.lastname@example.org> wrote:
>> On Dec 7, 2011, at 3:09 AM, Rebel Neurofog wrote:
>>> 1. Putting string into registry will guarantee it's validness during
>>> lua_State lifetime.
>> This is true of current implementations of Lua but is not guaranteed by the API. It could break, for example, if Lua shifted to a moving collector.
> What do you mean?
> String value will be lost? But then what will I get by accessing registry?
> String value will change? But that's not about collector but string
> hashing. So when should it happen not to ruin C code?
> Please explain it in details. Until now I thought I have clear vision
> about that...
The string will still be in the registry but the character buffer for the string might move which would invalidate the results of lua_tostring. The API only promises that lua_tostring's results will stay valid if the string remains on the stack.