lua-users home
lua-l archive

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


Further to trying to avoid changes to Lua source modules, I have created
the following macros for Lua 5.1. These macros were prompted by my
repeated changing the code on different platforms (e.g. no console,
no IO library) and the recent thread on Embedded Lua..

The changes which are minor and I think something like this would
be worthwile in a minor revision of 5.1.

The realloc/free macros exist because although one can override the
allocator with lua_newstate(), the libary code with the calls to
realloc and free means that they still get linked (whether called ot not).

For the lua library (not the standalone interpreter) and lua_loadfile() aside
this leaves liolib.c as the only module that contains any RTL file functions.

Let me know what you think,

David B.

** added to luaconf.h **

/*
** defines the only allocation functions used by lua
*/
#ifndef LUAI_REALLOC
#define LUAI_REALLOC(p,n) realloc((p),(n))
#endif
#ifndef LUAI_FREE
#define LUAI_FREE(x) free((x))
#endif

/*
** defines the output routine for atpanic() errors
*/
#ifndef LUAI_PRTERROR
#define LUAI_PRTERROR(x) fputs((x),stderr)
#endif
/*
** defines the output routine for print()
*/
#ifndef LUAI_PRTOUTPUT
#define LUAI_PRTOUTPUT(x) fputs((x),stdout)
#endif
/*
** defines the console input mechanism for debug.debug()
** undefine it if you have no console input or
** you do not require it
*/
#ifndef LUAI_CONINPUTLINE
#define LUAI_CONINPUTLINE(b,l) fgets((b), (l), stdin)
#endif