[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Hooks for I/O, memory, etc?
- From: Terence Martin <tmartin@...>
- Date: Tue, 11 Jun 2002 15:02:41 -0700
> Roberto Ierusalimschy wrote:
> >
> > The drawback is that everyone using Lua would have to start it
> > with something like
> >
> > lua_open(&realloc);
> >
> > which is not exactly friendly...
>
> Not really. Lua _open can do that behind our backs.
> You keep the "callback functions"/"hooks" stored as
> funcion pointers somewhere in the Lua state. By default,
> the state is set up by lua_open to use the default ANCI C
> functions. The callback can then be changed by a new LUA api
> call such has lua_set_callbacks(lua_state *,
> lua_callback_struct *);
That won't work so good, because lua_open needs to allocate memory. It
would probably be quite catastrophic if some things were allocated
with malloc and some were allocated using your custom routines/
For this to work, there either has to be a call you make before
lua_open (which means having some global variables, which is perhaps
undesirable), or you have to tell lua_open yourself what functions to
use (which means extra paramters of some type, which is perhaps
undesirable).
I think maybe the first one might be a little cleaner looking, but I
don't really have a preference.