summaryrefslogtreecommitdiff
path: root/com32
diff options
context:
space:
mode:
Diffstat (limited to 'com32')
-rw-r--r--com32/lua/src/linit.c2
-rw-r--r--com32/lua/src/lmathlib.c2
-rw-r--r--com32/lua/src/loslib.c4
-rw-r--r--com32/lua/src/lstrlib.c2
-rw-r--r--com32/lua/src/luaconf.h58
-rw-r--r--com32/lua/src/lvm.c27
6 files changed, 89 insertions, 6 deletions
diff --git a/com32/lua/src/linit.c b/com32/lua/src/linit.c
index c1f90dfa..a97de379 100644
--- a/com32/lua/src/linit.c
+++ b/com32/lua/src/linit.c
@@ -21,7 +21,9 @@ static const luaL_Reg lualibs[] = {
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
+#if !defined LUA_NUMBER_INTEGRAL
{LUA_MATHLIBNAME, luaopen_math},
+#endif
{LUA_DBLIBNAME, luaopen_debug},
{NULL, NULL}
};
diff --git a/com32/lua/src/lmathlib.c b/com32/lua/src/lmathlib.c
index 441fbf73..ccae8ed5 100644
--- a/com32/lua/src/lmathlib.c
+++ b/com32/lua/src/lmathlib.c
@@ -252,8 +252,10 @@ LUALIB_API int luaopen_math (lua_State *L) {
luaL_register(L, LUA_MATHLIBNAME, mathlib);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
+#if !defined LUA_NUMBER_INTEGRAL
lua_pushnumber(L, HUGE_VAL);
lua_setfield(L, -2, "huge");
+#endif
#if defined(LUA_COMPAT_MOD)
lua_getfield(L, -1, "fmod");
lua_setfield(L, -2, "mod");
diff --git a/com32/lua/src/loslib.c b/com32/lua/src/loslib.c
index da06a572..81b57eb8 100644
--- a/com32/lua/src/loslib.c
+++ b/com32/lua/src/loslib.c
@@ -192,11 +192,13 @@ static int os_time (lua_State *L) {
}
+#if !defined LUA_NUMBER_INTEGRAL
static int os_difftime (lua_State *L) {
lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
(time_t)(luaL_optnumber(L, 2, 0))));
return 1;
}
+#endif
/* }====================================================== */
@@ -220,7 +222,9 @@ static int os_exit (lua_State *L) {
static const luaL_Reg syslib[] = {
{"clock", os_clock},
{"date", os_date},
+#if !defined LUA_NUMBER_INTEGRAL
{"difftime", os_difftime},
+#endif
{"execute", os_execute},
{"exit", os_exit},
{"getenv", os_getenv},
diff --git a/com32/lua/src/lstrlib.c b/com32/lua/src/lstrlib.c
index ca333ba1..1613cc92 100644
--- a/com32/lua/src/lstrlib.c
+++ b/com32/lua/src/lstrlib.c
@@ -784,11 +784,13 @@ static int str_format (lua_State *L) {
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
+#if !defined LUA_NUMBER_INTEGRAL
case 'e': case 'E': case 'f':
case 'g': case 'G': {
sprintf(buff, form, (double)luaL_checknumber(L, arg));
break;
}
+#endif
case 'q': {
addquoted(L, &b, arg);
continue; /* skip the 'addsize' at the end */
diff --git a/com32/lua/src/luaconf.h b/com32/lua/src/luaconf.h
index eb2f5a1f..f39f50e2 100644
--- a/com32/lua/src/luaconf.h
+++ b/com32/lua/src/luaconf.h
@@ -140,8 +140,9 @@
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
*/
-#define LUA_INTEGER ptrdiff_t
+/* Changed to long for use with integral Lua numbers. */
+#define LUA_INTEGER long
/*
@@ LUA_API is a mark for all core API functions.
@@ -501,14 +502,31 @@
** ===================================================================
*/
+/* Define LUA_NUMBER_INTEGRAL to produce a system that uses no
+ floating point operations by changing the type of Lua numbers from
+ double to long. It implements division and modulus so that
+
+ x == (x / y) * y + x % y.
+
+ The exponentiation function returns zero for negative exponents.
+ Defining LUA_NUMBER_INTEGRAL also removes the difftime function,
+ and the math module should not be used. The string.format function
+ no longer handles the floating point directives %e, %E, %f, %g, and
+ %G. */
+
+#define LUA_NUMBER_INTEGRAL
+#if defined LUA_NUMBER_INTEGRAL
+#define LUA_NUMBER long
+#else
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
+#endif
/*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
*/
-#define LUAI_UACNUMBER double
+#define LUAI_UACNUMBER LUA_NUMBER
/*
@@ -518,11 +536,20 @@
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
@@ lua_str2number converts a string to a number.
*/
+#if defined LUA_NUMBER_INTEGRAL
+#define LUA_NUMBER_SCAN "%ld"
+#define LUA_NUMBER_FMT "%ld"
+#else
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
+#endif
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
+#if defined LUA_NUMBER_INTEGRAL
+#define lua_str2number(s,p) strtol((s), (p), 10)
+#else
#define lua_str2number(s,p) strtod((s), (p))
+#endif
/*
@@ -533,9 +560,36 @@
#define luai_numadd(a,b) ((a)+(b))
#define luai_numsub(a,b) ((a)-(b))
#define luai_nummul(a,b) ((a)*(b))
+#if defined LUA_NUMBER_INTEGRAL
+#define luai_numdiv(a,b) \
+ (-1/2? \
+ (a)/(b): \
+ ((a)<0==(b)<0||(a)%(b)==0? \
+ (a)/(b): \
+ (a)/(b)-1))
+#define luai_nummod(a,b) \
+ (-1/2? \
+ (a)%(b): \
+ ((a)<0==(b)<0||(a)%(b)==0? \
+ (a)%(b): \
+ (a)%(b)+(b)))
+#define luai_lnumdiv(a,b) \
+ ((b)==0? \
+ (luaG_runerror(L,"divide by zero"),0): \
+ luai_numdiv(a,b))
+#define luai_lnummod(a,b) \
+ ((b)==0? \
+ (luaG_runerror(L,"modulo by zero"),0): \
+ luai_nummod(a,b))
+LUA_NUMBER luai_ipow(LUA_NUMBER, LUA_NUMBER);
+#define luai_numpow(a,b) (luai_ipow(a,b))
+#else
#define luai_numdiv(a,b) ((a)/(b))
#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
+#define luai_lnumdiv(a,b) (luai_numdiv(a,b))
+#define luai_lnummod(a,b) (luai_nummod(a,b))
#define luai_numpow(a,b) (pow(a,b))
+#endif
#define luai_numunm(a) (-(a))
#define luai_numeq(a,b) ((a)==(b))
#define luai_numlt(a,b) ((a)<(b))
diff --git a/com32/lua/src/lvm.c b/com32/lua/src/lvm.c
index aef3da43..e65ccc80 100644
--- a/com32/lua/src/lvm.c
+++ b/com32/lua/src/lvm.c
@@ -27,6 +27,25 @@
#include "lvm.h"
+#if defined LUA_NUMBER_INTEGRAL
+LUA_NUMBER luai_ipow(LUA_NUMBER a, LUA_NUMBER b) {
+ if (b < 0)
+ return 0;
+ else if (b == 0)
+ return 1;
+ else {
+ LUA_NUMBER c = 1;
+ for (;;) {
+ if (b & 1)
+ c *= a;
+ b = b >> 1;
+ if (b == 0)
+ return c;
+ a *= a;
+ }
+ }
+}
+#endif
/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP 100
@@ -322,8 +341,8 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb,
case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
- case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
- case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
+ case TM_DIV: setnvalue(ra, luai_lnumdiv(nb, nc)); break;
+ case TM_MOD: setnvalue(ra, luai_lnummod(nb, nc)); break;
case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
default: lua_assert(0); break;
@@ -481,11 +500,11 @@ void luaV_execute (lua_State *L, int nexeccalls) {
continue;
}
case OP_DIV: {
- arith_op(luai_numdiv, TM_DIV);
+ arith_op(luai_lnumdiv, TM_DIV);
continue;
}
case OP_MOD: {
- arith_op(luai_nummod, TM_MOD);
+ arith_op(luai_lnummod, TM_MOD);
continue;
}
case OP_POW: {