lua-users home
lua-l archive

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


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 (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/