diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-07 17:13:41 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-07 17:13:41 -0300 |
| commit | f04fe526cd9de3e5460b614b2ff06268ad51872d (patch) | |
| tree | 9e9fd4fc0bae4858d74c04a22d8ce5748191d5a9 /lbaselib.c | |
| parent | 21947deddc5976536665cd2397d7d5c9e6bd7e48 (diff) | |
| download | lua-f04fe526cd9de3e5460b614b2ff06268ad51872d.tar.gz lua-f04fe526cd9de3e5460b614b2ff06268ad51872d.tar.bz2 lua-f04fe526cd9de3e5460b614b2ff06268ad51872d.zip | |
new functions `lua_tointeger' and lua_pushinteger'
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.132 2003/08/25 19:49:47 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.133 2003/08/27 21:02:08 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -187,8 +187,8 @@ static int luaB_rawset (lua_State *L) { | |||
| 187 | 187 | ||
| 188 | 188 | ||
| 189 | static int luaB_gcinfo (lua_State *L) { | 189 | static int luaB_gcinfo (lua_State *L) { |
| 190 | lua_pushnumber(L, (lua_Number)lua_getgccount(L)); | 190 | lua_pushinteger(L, lua_getgccount(L)); |
| 191 | lua_pushnumber(L, (lua_Number)lua_getgcthreshold(L)); | 191 | lua_pushinteger(L, lua_getgcthreshold(L)); |
| 192 | return 2; | 192 | return 2; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| @@ -229,19 +229,19 @@ static int luaB_pairs (lua_State *L) { | |||
| 229 | 229 | ||
| 230 | 230 | ||
| 231 | static int luaB_ipairs (lua_State *L) { | 231 | static int luaB_ipairs (lua_State *L) { |
| 232 | lua_Number i = lua_tonumber(L, 2); | 232 | int i = (int)lua_tointeger(L, 2); |
| 233 | luaL_checktype(L, 1, LUA_TTABLE); | 233 | luaL_checktype(L, 1, LUA_TTABLE); |
| 234 | if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ | 234 | if (i == 0 && lua_isnone(L, 2)) { /* `for' start? */ |
| 235 | lua_pushliteral(L, "ipairs"); | 235 | lua_pushliteral(L, "ipairs"); |
| 236 | lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */ | 236 | lua_rawget(L, LUA_GLOBALSINDEX); /* return generator, */ |
| 237 | lua_pushvalue(L, 1); /* state, */ | 237 | lua_pushvalue(L, 1); /* state, */ |
| 238 | lua_pushnumber(L, 0); /* and initial value */ | 238 | lua_pushinteger(L, 0); /* and initial value */ |
| 239 | return 3; | 239 | return 3; |
| 240 | } | 240 | } |
| 241 | else { /* `for' step */ | 241 | else { /* `for' step */ |
| 242 | i++; /* next value */ | 242 | i++; /* next value */ |
| 243 | lua_pushnumber(L, i); | 243 | lua_pushinteger(L, i); |
| 244 | lua_rawgeti(L, 1, (int)i); | 244 | lua_rawgeti(L, 1, i); |
| 245 | return (lua_isnil(L, -1)) ? 0 : 2; | 245 | return (lua_isnil(L, -1)) ? 0 : 2; |
| 246 | } | 246 | } |
| 247 | } | 247 | } |
