lua-users home
lua-l archive

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


I am modifying my Lua 5.1 sources for an environment without a
floating point unit.  I tried to retrieve the relevant patch described
at lua-users.org, but this is what happens:

$ svn co svn://slugak.dyndns.org/public/lua-patches
svn: Can't connect to host 'slugak.dyndns.org': Connection refused

So I simply hacked the sources, which seems to mean one must modify
only lmathlib.c and luaconf.h.  It all seems straightforward with the
exception of changing the macro luai_numpow.  What definition is
appropriate?  Also, why is pow called directly in lmathlib.c, rather
than called via luai_numpow?

John

diff -ur olua-5.1/src/lmathlib.c lua-5.1/src/lmathlib.c
--- olua-5.1/src/lmathlib.c	2005-08-26 13:36:32.000000000 -0400
+++ lua-5.1/src/lmathlib.c	2006-04-04 15:28:38.000000000 -0400
@@ -252,8 +252,10 @@
   luaL_register(L, LUA_MATHLIBNAME, mathlib);
   lua_pushnumber(L, PI);
   lua_setfield(L, -2, "pi");
+#if defined(LUA_NUMBER_DOUBLE)
   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 -ur olua-5.1/src/luaconf.h lua-5.1/src/luaconf.h
--- olua-5.1/src/luaconf.h	2006-02-10 12:44:06.000000000 -0500
+++ lua-5.1/src/luaconf.h	2006-04-04 16:02:39.000000000 -0400
@@ -128,8 +128,8 @@
 ** 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
 
+#define LUA_INTEGER	long
 
 /*
 @@ LUA_API is a mark for all core API functions.
@@ -488,14 +488,14 @@
 ** ===================================================================
 */
 
-#define LUA_NUMBER_DOUBLE
-#define LUA_NUMBER	double
+#define LUA_NUMBER_LONG
+#define LUA_NUMBER	LUA_INTEGER
 
 /*
 @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
 @* over a number.
 */
-#define LUAI_UACNUMBER	double
+#define LUAI_UACNUMBER	LUA_NUMBER
 
 
 /*
@@ -505,11 +505,11 @@
 @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
 @@ lua_str2number converts a string to a number.
 */
-#define LUA_NUMBER_SCAN		"%lf"
-#define LUA_NUMBER_FMT		"%.14g"
+#define LUA_NUMBER_SCAN		"%ld"
+#define LUA_NUMBER_FMT		"%ld"
 #define lua_number2str(s,n)	sprintf((s), LUA_NUMBER_FMT, (n))
-#define LUAI_MAXNUMBER2STR	32 /* 16 digits, sign, point, and \0 */
-#define lua_str2number(s,p)	strtod((s), (p))
+#define LUAI_MAXNUMBER2STR	32
+#define lua_str2number(s,p)	strtol((s), (p), 10)
 
 
 /*
@@ -521,7 +521,7 @@
 #define luai_numsub(a,b)	((a)-(b))
 #define luai_nummul(a,b)	((a)*(b))
 #define luai_numdiv(a,b)	((a)/(b))
-#define luai_nummod(a,b)	((a) - floor((a)/(b))*(b))
+#define luai_nummod(a,b)	((a)%(b))
 #define luai_numpow(a,b)	(pow(a,b))
 #define luai_numunm(a)		(-(a))
 #define luai_numeq(a,b)		((a)==(b))