lua-users home
lua-l archive

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

On Thursday 23 August 2007, David Given wrote:
> The value of ret isn't the problem --- it's the string data that it's
> pointing at. That data is owned by Lua, and the garbage collector is at

note that this isn't a Lua-specific issue.  when using any C library, if 
you're given a pointer, you ALWAYS have to ask "who owns this data?". in the 
Lua case, it's clearly stated in the manual:

"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."

not giving enough time for this kind of things is what gives pointers (and C) 
their bad reputation. 


Attachment: pgpw1J9IJAJVq.pgp
Description: PGP signature