[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Missing feature in 5.3: LUA_FLOAT_NONE for crippled C libraries
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 21 Oct 2015 11:21:04 -0200
I may be missing something, but the following definitions in 'luaconf.h'
seem to do a good job of elliminating floats from Lua. A few caveats:
- Depending how you add these definitions to your luaconf.h, you will
have to undefine the original definition.
- I assume you removed the math lib (a one-line change in linit.c).
- There are some quirks; most of them I think were present also in
older versions of Lua converted to int:
* exponentiation results in zero (we should provide our own
implementation for integer exponentiation)
* string.format for floats (%a, %f, %g, etc.) give weird results
-- Roberto
/* -----------------------------------------------------------------*/
#define LUA_NUMBER LUA_INTEGER
#define LUAI_UACNUMBER LUAI_UACINT
#define LUA_NUMBER_FRMLEN LUA_INTEGER_FRMLEN
#define LUA_NUMBER_FMT LUA_INTEGER_FMT
#define luai_numpow(L,a,b) 0 /* we should provide an implementation... */
#define luai_nummod(L,a,b,m) ((m) = luaV_mod(L, (a), (b)))
#define luai_numdiv(L,a,b) luaV_div(L, a, b)
#define luai_numidiv(L,a,b) luaV_div(L, a, b)
#define l_floor(x) (x)
#define l_mathop(op) X X X /* ensure it is not being used */
#define LUA_COMPAT_FLOATSTRING
#define lua_str2number(s,p) (*(p) = (char*)(s), 0)
#define l_hashfloat(n) (n)
#define l_mathlim(x) (LUAI_##x)
#define LUAI_MANT_DIG 63
#define LUAI_MAX_10_EXP 10 /* arbitrary */
#define lua_numbertointeger(n,p) (*(p)=(n), 1)