[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Using Lua's memory allocator
- From: Gavin Wraith <gavin@...>
- Date: Tue, 11 Oct 2011 11:32:26 +0100
A plea for advice from the experts. Can anybody point me to
anywhere in the Lua literature (or lists) on how to interface
a library to Lua so that it can take advantage of Lua's
garbage-collected memory allocation?
The library starts by initializing one large struct, and thereafter
uses calloc and free to grab from and give back to the heap.
My naive first thoughts are to extend the struct with a
(lua_State *) field, to make the library's free routine do
nothing, and to rewrite its calloc routine with something that
uses lua_newuserdata. Then there is the usual business of wrapping
its exported functions to make a Lua library.
Am I on the right track, or have I overlooked something important?
Sorry if this lacks detail. The library is in pure ANSI C, and has had
all its IO routines removed (I want these to come from Lua).
Gavin Wraith (email@example.com)
Home page: http://www.wra1th.plus.com/