[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to make a string outlive the invocation of a C function?
- From: Rici Lake <lua@...>
- Date: Tue, 17 Apr 2007 09:30:59 -0500
Gé Weijers wrote:
There's no document that I'm aware of that exactly defines the contract
between the Lua interpreter and extensions written in C. My assumption
has been that any reference to an object will keep the object allocated
and in the same location. If that's not true I'd really like to know.
The Reference Manual says: (description of lua_tolstring)
"lua_tolstring returns a fully aligned pointer to a string inside the
Lua state... there is no guarantee that the pointer returned by
lua_tolstring will be valid after the corresponding value is removed
from the stack."
In theory that would allow Lua to relocate strings which are not
referenced from the Lua stack. In practice, it doesn't do that, and
I suspect a lot of extension modules would break if it started to.
Still, that's the contract.