lua-users home
lua-l archive

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


You can also ensure that it doesn't get garbage collected by getting a
reference to the string, using lua_ref.

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Curt Carpenter
> Sent: Wednesday, September 04, 2002 4:38 PM
> To: Multiple recipients of list
> Subject: RE: simple question
>
>
> As doc'd (4.0):
> This function returns a pointer to a string inside the Lua environment.
> Those strings always have a zero ('\0') after their last character (as
> in C), but may contain other zeros in their body. If you do not know
> whether a string may contain zeros, you should use lua_strlen to get its
> actual length. Because Lua has garbage collection, there is no guarantee
> that the pointer returned by lua_tostring will be valid after the
> respective value is removed from the stack.
>
> Curt
>
> -----Original Message-----
> From: Bram Vaessen [mailto:bram.vaessen@wxs.nl]
> Sent: Wednesday, September 04, 2002 2:04 PM
> To: Multiple recipients of list
> Subject: simple question
>
>
> simple question:
>
> If I have a normal lua function that returns a string, and I call this
> function from C, and use lua_tostring to get the string. Do I need to
> copy the string into another string if I want to keep it. And if not,
> then I guess I have to take care of deleting the string if it's not
> needed anymore?
>
> Thanks,
>
> Bram Vaessen
>
>