lua-users home
lua-l archive

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


Yes, you right about the realloc(). I think it good in luaconf.h to
let everyone one know about the only two allocation routines that lua
uses. And it reminds me that I have to probably change it.

The primary issue for me here is the macroizing of the fgets/fputs usage
that exists in lauxlib.c ldblib.c and lbaselib.c.

To give real examples:

atpanic() - the puts gets an event log write and the refernce to
stderr is removed
because it does not exist. Or we add a syslog call. Or stderr is not
even defined.
The macro does not obviate the need for lua_atpanic().

print() in lbaselib() - my most common replacement is write(1,...).
Again the reference to stdout is problematic. It may work ok it may not.


debug.debug() in ldblib.c - the console input / output. The usual change is
to #ifdef the debug() function out of existence when we dont have a
stdin/stderr.

luaL_loadfile() in lauxlib.c for which I did not provide a luaconf
solution. This
is often a hassle. I usually just provide a total replacement function for
loading from; virtual file systems, os pipes, multi language file systems,
file IO with charset translation capabilities. Loading lua script exclusively
from resource files. And finally I suspect the embedders will always
change the lua_Reader. I concede that this is a tough one to generalize,
but it would be nice if the IO functions here could be easily macroed.
ungetc() does not help.

Let me reiterate that the main issue here is getting ANSI IO out of
all of the library code except liolib.c. This is a requirement when
fopen() et al are either unavailable or disfunctional.

thanks
David B


On 4/5/06, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> > Further to trying to avoid changes to Lua source modules, I have created
> > the following macros for Lua 5.1.
>
> > #ifndef LUAI_REALLOC
> > #define LUAI_REALLOC(p,n) realloc((p),(n))
> > #endif
>
> The point being made by me and Roberto is that you could simply do this in
> luaconf.h:
>
> #define realloc myrealloc
>
> Lua header files are included after system files precisely to allow this.
> Or are we missing someting?
> --lhf
>