lua-users home
lua-l archive

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


JAST wrote:
Hello everyone!
Warning! New Lua User
I need a dynamically allocated buffer for a unicode string in win32
is there a lua API function to alloc a memory buffer inside a cfunction
and let the garbage collector free it later
(function that does not push something to the statck)

If I understand you, then what you're asking for is a
way to allocate a string that doesn't get 'given' to Lua,
that you want to use from the C-side, but which will still
be garbage-collected?

If so, that's not really possible (since until a string
is internalised by Lua, by creating it on the stack, it's
still C memory which Lua doesn't stand a fighting chance
of knowing the lifetime of -- and if it ONLY lives on the
stack it'll likely soon be thrown away).

You can put your string into the registry and get the mild
benefits of Lua's string uniquification but then the
liveness-management (as far as the C-side is concerned) has
to be explicit and you don't get magical GC (which I assume
is what you're wanting).

--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3