lua-users home
lua-l archive

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


On 13/04/2014 7:46 AM, Tim Hill wrote:
lua_tolstring() and lua_tostring() both return a direct pointer to
the string within the Lua state; you should treat it as read-only
(hence the const) and valid only while the stack index referenced is
unchanged. So yes, you could find the refcount from the pointer, but
I still think this is a risky approach, as it depends on assumptions
about undocumented behaviors of the Lua VM.

I wonder what it would take to provide an API for zero-copy "injectable" immutable strings.

lua_injectstring()

An API where the client C code can do the work of allocating the string buffer (presumably with some particular sized header for VM use). The client would then add the string to the VM state with "inject". This has the effect of handing off responsibility for deallocating the memory to the VM/GC.

The same type of injection would be useful for userdata.

It would be even more useful if calls to the deallocate function indicated that such memory was of this "injected" type (using a flag), or called a separate deallocate function for injected memory.

Ross.