lua-users home
lua-l archive

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


On 15 December 2011 13:52, rahul sharma <rahulatgslab@gmail.com> wrote:
> Hi All,
>
> Thanks for your kind reply. Why I want the address in Lua is because I want
> to know the address in Lua, then I will pass that string to C, and in C, I
> will get the address of that string using lua_tostring(). So if these two
> match, then I can be sure that no copying is done in lua on passing string
> from Lua to C.

Lua does not perform any copying when passing a string from Lua -> C.
It is up to you to copy the string if you need to (since Lua may move
or delete it when it no longer needs it).

If all you want to do is pass a pointer to a string *through* Lua so
that Lua doesn't copy it from C, you can push the pointer as a
userdata or lightuserdata. More information on these can be found at:

  - http://www.lua.org/manual/5.1/manual.html#lua_newuserdata
  - http://www.lua.org/manual/5.1/manual.html#lua_pushlightuserdata
  - http://www.lua.org/pil/28.1.html
  - http://www.lua.org/pil/28.5.html

In this case it's up to you to make sure the string remains accessible
in C while Lua still has a reference to it.

Regards,
Matthew