[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua5: questions & suggestions
- From: mjscod@... (Mark Junker)
- Date: 31 Jul 2003 01:02:00 +0100
Hi,
first I have to say that Lua is a great script language with a quite small
footprint, a clean interface and good documentation.
I recently compiled Lua 5 with the Hitachi EC++ compiler for SH4 and I had to
make some changes. They led to the following questions and suggestions.
My questions:
1. In liolib.c, you use CLOCKS_PER_SEC. Shouldn't it be CLK_TCK?
2. Is it possible to compile Lua in a way that disables all file i/o?
What I mean is:
- compile without the ability to load external libraries/files
- no execute/open/close/input/output/file name handling functions in liolib.c
- leaves stdin, stdout, ...
My suggestions:
1. For the next Lua version, can you save the compiled Lua script in a
machine-independent way?
It's a big advantage to store a compiled Lua script in a machine-independent
way when you want to compile the script on the PC side, then transfer it to
the embedded (big-endian) machine where it'll be executed (no parser to save
memory, no file i/o needed either).
Example for DumpNumber from ldump.c:
-------------------------- snip --------------------------------------
/* use 8 instead of sizeof(double)
* because there are compilers where sizeof(float)==sizeof(double) */
#define DOUBLE_SIZE (8)
static void DumpNumber(lua_Number x, DumpState* D)
{
#if LUA_NUM_IS_INTEGRAL==1
char chTmp[sizeof(x)];
unsigned i;
lua_Number mask = UCHAR_MAX;
for (i=0; i!=sizeof(x); ++i) {
chTmp[i] = (char) (x & mask);
x /= (1<<CHAR_BIT);
}
DumpBlock(chTmp,sizeof(x),D);
#else
int iExponent = 0;
double dblMantissa = frexp((double) x, &iExponent);
double ipart;
double dblFactorUL = ldexp(1, CHAR_BIT * sizeof(unsigned long) - 1);
dblMantissa = ldexp(dblMantissa, CHAR_BIT * sizeof(unsigned long) - 1);
dblMantissa = modf(dblMantissa, &ipart);
dblMantissa *= dblFactorUL;
DumpInt(iExponent, D);
DumpUL((long) dblMantissa, D);
DumpUL((long) ipart, D);
#endif
}
-------------------------- snip --------------------------------------
2. Can you define a set of macros (maybe in a different header file) for
arithmetics with lua_Number variables?
This might be useful when lua_Number is a 64 bit fixed point (48.16) integer
number for very fast integer arithmetics.
Best regards,
Mark Junker