[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How is string passed from Lua to C
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Wed, 7 Dec 2011 11:32:56 +0100
2011/12/7 rahul sharma <email@example.com>:
> Can anyone explain me how the string fetching is done by Lua. I want to pass
> string from Lua to C. I am able to access it using gettable and then
> converting it to string using lua_tostring(). But I don't know whether a new
> copy of that string is made on stack or its a reference to the string's
> location. If anyone knows about it, do let me know. My basic motto is to
> avoid the copy of data.
lua_tostring will return a reference to it, but that reference is only
valid if the string stays on the Lua stack. So before removing it from
the stack, you have to make a copy of it.