lua-users home
lua-l archive

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

On Thu, Dec 15, 2011 at 06:20:23PM +0530, rahul sharma wrote:
> Hi, I want to print the starting address of string in Lua. So is there any
> way using which I can do that? for ex:-
>     x="abc"
> Now I want to print the address where abc is stored. So is there any way to
> do it?? I will then pass this x to a c program and then try to print the
> address of x received to see that lua doesnot copy string but uses
> reference to the base address.
> So is there any method to do that???

The C function lua_tostring will return a const char * of a string.  You
should note that Lua strings can contain NUL, unlike C strings.  Also,
you should probably be very careful with the returned pointer, as it may
vanish if the string gets collected.

Also, Lua always copies strings for its own use; it interns them so only
one copy of each string is ever kept by Lua, also allowing for string
equality comparisons to be O(1).

Can I ask why you want to know / do this?

Documentation for function call: