diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-18 15:18:35 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-18 15:18:35 -0300 |
| commit | 0b00e7f1a20b5c4c3f21aaf163818335d0d61928 (patch) | |
| tree | c0950f44c82d0fe3a70c6f5c3671490d36740464 | |
| parent | b7ed502deaaab48c8794314e8594b0511dfa34d8 (diff) | |
| download | lua-0b00e7f1a20b5c4c3f21aaf163818335d0d61928.tar.gz lua-0b00e7f1a20b5c4c3f21aaf163818335d0d61928.tar.bz2 lua-0b00e7f1a20b5c4c3f21aaf163818335d0d61928.zip | |
new macro to convert double->int
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | ltable.c | 8 | ||||
| -rw-r--r-- | lua.h | 7 | ||||
| -rw-r--r-- | makefile | 11 |
4 files changed, 20 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.175 2002/03/04 21:29:41 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.176 2002/03/07 18:15:10 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -597,7 +597,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 597 | api_check(L, ttype(t) == LUA_TTABLE); | 597 | api_check(L, ttype(t) == LUA_TTABLE); |
| 598 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */ | 598 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */ |
| 599 | if (ttype(value) == LUA_TNUMBER) | 599 | if (ttype(value) == LUA_TNUMBER) |
| 600 | n = cast(int, nvalue(value)); | 600 | lua_number2int(n, nvalue(value)); |
| 601 | else { | 601 | else { |
| 602 | Node *nd; | 602 | Node *nd; |
| 603 | Table *a = hvalue(t); | 603 | Table *a = hvalue(t); |
| @@ -618,7 +618,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
| 618 | max = nvalue(key(nd)); | 618 | max = nvalue(key(nd)); |
| 619 | nd++; | 619 | nd++; |
| 620 | } | 620 | } |
| 621 | n = cast(int, max); | 621 | lua_number2int(n, max); |
| 622 | } | 622 | } |
| 623 | lua_unlock(L); | 623 | lua_unlock(L); |
| 624 | return n; | 624 | return n; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: ltable.c,v 1.101 2002/02/14 21:41:08 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -85,7 +85,8 @@ Node *luaH_mainposition (const Table *t, const TObject *key) { | |||
| 85 | */ | 85 | */ |
| 86 | static int arrayindex (const TObject *key) { | 86 | static int arrayindex (const TObject *key) { |
| 87 | if (ttype(key) == LUA_TNUMBER) { | 87 | if (ttype(key) == LUA_TNUMBER) { |
| 88 | int k = cast(int, nvalue(key)); | 88 | int k; |
| 89 | lua_number2int(k, (nvalue(key))); | ||
| 89 | if (cast(lua_Number, k) == nvalue(key) && k >= 1 && !toobig(k)) | 90 | if (cast(lua_Number, k) == nvalue(key) && k >= 1 && !toobig(k)) |
| 90 | return k; | 91 | return k; |
| 91 | } | 92 | } |
| @@ -421,7 +422,8 @@ const TObject *luaH_get (Table *t, const TObject *key) { | |||
| 421 | switch (ttype(key)) { | 422 | switch (ttype(key)) { |
| 422 | case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); | 423 | case LUA_TSTRING: return luaH_getstr(t, tsvalue(key)); |
| 423 | case LUA_TNUMBER: { | 424 | case LUA_TNUMBER: { |
| 424 | int k = cast(int, nvalue(key)); | 425 | int k; |
| 426 | lua_number2int(k, (nvalue(key))); | ||
| 425 | if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */ | 427 | if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */ |
| 426 | return luaH_getnum(t, k); /* use specialized version */ | 428 | return luaH_getnum(t, k); /* use specialized version */ |
| 427 | /* else go through */ | 429 | /* else go through */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.121 2002/02/14 21:40:13 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.122 2002/03/07 18:15:10 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -294,6 +294,11 @@ LUA_API int lua_pushupvalues (lua_State *L); | |||
| 294 | #define lua_str2number(s,p) strtod((s), (p)) | 294 | #define lua_str2number(s,p) strtod((s), (p)) |
| 295 | #endif | 295 | #endif |
| 296 | 296 | ||
| 297 | /* function to convert a lua_Number to int (with any rounding method) */ | ||
| 298 | #ifndef lua_number2int | ||
| 299 | #define lua_number2int(i,n) ((i)=(int)(n)) | ||
| 300 | #endif | ||
| 301 | |||
| 297 | /* }====================================================================== */ | 302 | /* }====================================================================== */ |
| 298 | 303 | ||
| 299 | 304 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | # | 1 | # |
| 2 | ## $Id: makefile,v 1.32 2001/07/24 22:40:08 roberto Exp $ | 2 | ## $Id: makefile,v 1.34 2002/02/14 21:49:33 roberto Exp roberto $ |
| 3 | ## Makefile | 3 | ## Makefile |
| 4 | ## See Copyright Notice in lua.h | 4 | ## See Copyright Notice in lua.h |
| 5 | # | 5 | # |
| @@ -18,11 +18,12 @@ | |||
| 18 | 18 | ||
| 19 | #EXTRA_H=-DLUA_USER_H='"ltests.h"' | 19 | #EXTRA_H=-DLUA_USER_H='"ltests.h"' |
| 20 | 20 | ||
| 21 | CONFIG = -D_POSIX_SOURCE $(EXTRA_H) | 21 | CONFIG = -D_POSIX_SOURCE $(EXTRA_H) \ |
| 22 | -D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))' | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | # Compilation parameters | 25 | # Compilation parameters |
| 25 | CC = g++ | 26 | CC = gcc |
| 26 | CWARNS = -Wall -pedantic \ | 27 | CWARNS = -Wall -pedantic \ |
| 27 | -Waggregate-return \ | 28 | -Waggregate-return \ |
| 28 | -Wcast-align \ | 29 | -Wcast-align \ |
| @@ -146,9 +147,9 @@ ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \ | |||
| 146 | luadebug.h ldo.h lfunc.h lmem.h lstring.h lualib.h | 147 | luadebug.h ldo.h lfunc.h lmem.h lstring.h lualib.h |
| 147 | ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h luadebug.h \ | 148 | ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h luadebug.h \ |
| 148 | lstring.h ltable.h | 149 | lstring.h ltable.h |
| 149 | lua.o: lua.c lua.h luadebug.h lualib.h | 150 | lua.o: lua.c lua.h lauxlib.h luadebug.h lualib.h |
| 150 | lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ | 151 | lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ |
| 151 | luadebug.h lfunc.h lmem.h lopcodes.h lstring.h lundump.h lzio.h | 152 | luadebug.h lfunc.h lmem.h lopcodes.h lstring.h lundump.h lzio.h |
| 152 | lvm.o: lvm.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \ | 153 | lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ |
| 153 | luadebug.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h | 154 | luadebug.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h |
| 154 | lzio.o: lzio.c lua.h lzio.h | 155 | lzio.o: lzio.c lua.h lzio.h |
