aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-20 12:27:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-20 12:27:53 -0200
commit81245b1ad51c5f4a4dd71da272b65b2450929b80 (patch)
tree25b69ceb42d06e1c3a32aabda7212b805f605349 /lvm.c
parent397ce11996bb1b5a6ef81fdf44252cf58b230937 (diff)
downloadlua-81245b1ad51c5f4a4dd71da272b65b2450929b80.tar.gz
lua-81245b1ad51c5f4a4dd71da272b65b2450929b80.tar.bz2
lua-81245b1ad51c5f4a4dd71da272b65b2450929b80.zip
'numisinteger' (for table keys) replaced by 'luaV_tointeger' (old
'tointeger_aux'), which can do the same job.
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/lvm.c b/lvm.c
index 64bf883b..f40c1e95 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.233 2015/01/16 16:54:37 roberto Exp roberto $ 2** $Id: lvm.c,v 2.234 2015/02/05 17:15:33 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -31,16 +31,6 @@
31#include "lvm.h" 31#include "lvm.h"
32 32
33 33
34/*
35** You can define LUA_FLOORN2I if you want to convert floats to integers
36** by flooring them (instead of raising an error if they are not
37** integral values)
38*/
39#if !defined(LUA_FLOORN2I)
40#define LUA_FLOORN2I 0
41#endif
42
43
44/* limit for table tag-method chains (to avoid loops) */ 34/* limit for table tag-method chains (to avoid loops) */
45#define MAXTAGLOOP 2000 35#define MAXTAGLOOP 2000
46 36
@@ -89,7 +79,7 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
89** mode == 1: takes the floor of the number 79** mode == 1: takes the floor of the number
90** mode == 2: takes the ceil of the number 80** mode == 2: takes the ceil of the number
91*/ 81*/
92static int tointeger_aux (const TValue *obj, lua_Integer *p, int mode) { 82int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode) {
93 TValue v; 83 TValue v;
94 again: 84 again:
95 if (ttisfloat(obj)) { 85 if (ttisfloat(obj)) {
@@ -116,14 +106,6 @@ static int tointeger_aux (const TValue *obj, lua_Integer *p, int mode) {
116 106
117 107
118/* 108/*
119** try to convert a value to an integer
120*/
121int luaV_tointeger_ (const TValue *obj, lua_Integer *p) {
122 return tointeger_aux(obj, p, LUA_FLOORN2I);
123}
124
125
126/*
127** Try to convert a 'for' limit to an integer, preserving the 109** Try to convert a 'for' limit to an integer, preserving the
128** semantics of the loop. 110** semantics of the loop.
129** (The following explanation assumes a non-negative step; it is valid 111** (The following explanation assumes a non-negative step; it is valid
@@ -141,7 +123,7 @@ int luaV_tointeger_ (const TValue *obj, lua_Integer *p) {
141static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step, 123static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,
142 int *stopnow) { 124 int *stopnow) {
143 *stopnow = 0; /* usually, let loops run */ 125 *stopnow = 0; /* usually, let loops run */
144 if (!tointeger_aux(obj, p, (step < 0 ? 2 : 1))) { /* not fit in integer? */ 126 if (!luaV_tointeger(obj, p, (step < 0 ? 2 : 1))) { /* not fit in integer? */
145 lua_Number n; /* try to convert to float */ 127 lua_Number n; /* try to convert to float */
146 if (!tonumber(obj, &n)) /* cannot convert to float? */ 128 if (!tonumber(obj, &n)) /* cannot convert to float? */
147 return 0; /* not a number */ 129 return 0; /* not a number */