[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: how to make a string outlive the invocation of a C function?
- From: roberto@... (Roberto Ierusalimschy)
- Date: Tue, 17 Apr 2007 11:30:50 -0300
> 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 document that defines the contract between the Lua interpreter and
extensions written in C is the Lua manual. The manual tells (or should
tell, or tries to tell) what is valid. (It would be a really long list
to write down all kinds of invalid things that cannot be done). If you
are "religious", you should not make assumptions that are not written
For strings, the manual says this:
Because Lua has garbage collection, there is no guarantee that the
pointer returned by lua_tolstring will be valid after the corresponding
value is removed from the stack.
(But it does not specify the behavior of userdata...)