lua-users home
lua-l archive

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


You wouldn't necessarily have to integrate the callback mechanism with
lua_open. Much better in my opinion would be something like:

lua_userealloc(&my_custom_realloc);

called just before lua_open so that it can still use the defaults if the
user doesn't want to write their own.

----- Original Message -----
From: "Roberto Ierusalimschy" <roberto@inf.puc-rio.br>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Monday, June 10, 2002 2:26 PM
Subject: Re: Hooks for I/O, memory, etc?


> > Callbacks for I/O and memory allocation seems, to me anyway, obvious
> > for an embedded API. Is there any drawback to it? Sure I have a
> > working implementation now, but I went through a
>
> The drawback is that everyone using Lua would have to start it with
> something like
>
>   lua_open(&realloc);
>
> which is not exactly friendly... Note that you already can change memory
> allocation without editing the source:
>
>   #ifndef l_realloc
>   #define l_realloc(b,os,s)       realloc(b,s)
>   #endif
>
> (5.0w0 still uses an extra l_free; we are removing it.) So all you need
> is to define your own "l_realloc" when compiling Lua.
>
> -- Roberto
>