mirror of
https://github.com/lua/lua
synced 2024-12-24 03:16:50 +03:00
new macro to convert double->int
This commit is contained in:
parent
b7ed502dea
commit
0b00e7f1a2
6
lapi.c
6
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 1.175 2002/03/04 21:29:41 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 1.176 2002/03/07 18:15:10 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -597,7 +597,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
|
||||
api_check(L, ttype(t) == LUA_TTABLE);
|
||||
value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */
|
||||
if (ttype(value) == LUA_TNUMBER)
|
||||
n = cast(int, nvalue(value));
|
||||
lua_number2int(n, nvalue(value));
|
||||
else {
|
||||
Node *nd;
|
||||
Table *a = hvalue(t);
|
||||
@ -618,7 +618,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
|
||||
max = nvalue(key(nd));
|
||||
nd++;
|
||||
}
|
||||
n = cast(int, max);
|
||||
lua_number2int(n, max);
|
||||
}
|
||||
lua_unlock(L);
|
||||
return n;
|
||||
|
8
ltable.c
8
ltable.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltable.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $
|
||||
** $Id: ltable.c,v 1.101 2002/02/14 21:41:08 roberto Exp roberto $
|
||||
** Lua tables (hash)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -85,7 +85,8 @@ Node *luaH_mainposition (const Table *t, const TObject *key) {
|
||||
*/
|
||||
static int arrayindex (const TObject *key) {
|
||||
if (ttype(key) == LUA_TNUMBER) {
|
||||
int k = cast(int, nvalue(key));
|
||||
int k;
|
||||
lua_number2int(k, (nvalue(key)));
|
||||
if (cast(lua_Number, k) == nvalue(key) && k >= 1 && !toobig(k))
|
||||
return k;
|
||||
}
|
||||
@ -421,7 +422,8 @@ const TObject *luaH_get (Table *t, const TObject *key) {
|
||||
switch (ttype(key)) {
|
||||
case LUA_TSTRING: return luaH_getstr(t, tsvalue(key));
|
||||
case LUA_TNUMBER: {
|
||||
int k = cast(int, nvalue(key));
|
||||
int k;
|
||||
lua_number2int(k, (nvalue(key)));
|
||||
if (cast(lua_Number, k) == nvalue(key)) /* is an integer index? */
|
||||
return luaH_getnum(t, k); /* use specialized version */
|
||||
/* else go through */
|
||||
|
7
lua.h
7
lua.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lua.h,v 1.121 2002/02/14 21:40:13 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.122 2002/03/07 18:15:10 roberto Exp roberto $
|
||||
** Lua - An Extensible Extension Language
|
||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||
** e-mail: info@lua.org
|
||||
@ -294,6 +294,11 @@ LUA_API int lua_pushupvalues (lua_State *L);
|
||||
#define lua_str2number(s,p) strtod((s), (p))
|
||||
#endif
|
||||
|
||||
/* function to convert a lua_Number to int (with any rounding method) */
|
||||
#ifndef lua_number2int
|
||||
#define lua_number2int(i,n) ((i)=(int)(n))
|
||||
#endif
|
||||
|
||||
/* }====================================================================== */
|
||||
|
||||
|
||||
|
11
makefile
11
makefile
@ -1,5 +1,5 @@
|
||||
#
|
||||
## $Id: makefile,v 1.32 2001/07/24 22:40:08 roberto Exp $
|
||||
## $Id: makefile,v 1.34 2002/02/14 21:49:33 roberto Exp roberto $
|
||||
## Makefile
|
||||
## See Copyright Notice in lua.h
|
||||
#
|
||||
@ -18,11 +18,12 @@
|
||||
|
||||
#EXTRA_H=-DLUA_USER_H='"ltests.h"'
|
||||
|
||||
CONFIG = -D_POSIX_SOURCE $(EXTRA_H)
|
||||
CONFIG = -D_POSIX_SOURCE $(EXTRA_H) \
|
||||
-D'lua_number2int(i,d)=__asm__("fldl %1\nfistpl %0":"=m"(i):"m"(d))'
|
||||
|
||||
|
||||
# Compilation parameters
|
||||
CC = g++
|
||||
CC = gcc
|
||||
CWARNS = -Wall -pedantic \
|
||||
-Waggregate-return \
|
||||
-Wcast-align \
|
||||
@ -146,9 +147,9 @@ ltests.o: ltests.c lua.h lapi.h lobject.h llimits.h lauxlib.h lcode.h \
|
||||
luadebug.h ldo.h lfunc.h lmem.h lstring.h lualib.h
|
||||
ltm.o: ltm.c lua.h lobject.h llimits.h lstate.h ltm.h luadebug.h \
|
||||
lstring.h ltable.h
|
||||
lua.o: lua.c lua.h luadebug.h lualib.h
|
||||
lua.o: lua.c lua.h lauxlib.h luadebug.h lualib.h
|
||||
lundump.o: lundump.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
luadebug.h lfunc.h lmem.h lopcodes.h lstring.h lundump.h lzio.h
|
||||
lvm.o: lvm.c lua.h lapi.h lobject.h llimits.h ldebug.h lstate.h ltm.h \
|
||||
lvm.o: lvm.c lua.h ldebug.h lstate.h lobject.h llimits.h ltm.h \
|
||||
luadebug.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h ltable.h lvm.h
|
||||
lzio.o: lzio.c lua.h lzio.h
|
||||
|
Loading…
Reference in New Issue
Block a user