diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-01-16 10:42:21 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-01-16 10:42:21 -0200 |
| commit | 73ebc5d8f677a46de2e95c6f63fbb1f9e5b9cd46 (patch) | |
| tree | 9e53aab2fe308761e26df548c9b7b85f322c0ba7 | |
| parent | a666752b1d0a216902601a3dc4e670789d885bb3 (diff) | |
| download | lua-73ebc5d8f677a46de2e95c6f63fbb1f9e5b9cd46.tar.gz lua-73ebc5d8f677a46de2e95c6f63fbb1f9e5b9cd46.tar.bz2 lua-73ebc5d8f677a46de2e95c6f63fbb1f9e5b9cd46.zip | |
compat code should keep compatibility
| -rw-r--r-- | lauxlib.c | 28 |
1 files changed, 19 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.156 2005/10/21 13:47:42 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -295,23 +295,33 @@ static void getsizes (lua_State *L) { | |||
| 295 | 295 | ||
| 296 | LUALIB_API void luaL_setn (lua_State *L, int t, int n) { | 296 | LUALIB_API void luaL_setn (lua_State *L, int t, int n) { |
| 297 | t = abs_index(L, t); | 297 | t = abs_index(L, t); |
| 298 | getsizes(L); | 298 | lua_pushliteral(L, "n"); |
| 299 | lua_pushvalue(L, t); | 299 | lua_rawget(L, t); |
| 300 | lua_pushinteger(L, n); | 300 | if (checkint(L, 1) >= 0) { /* is there a numeric field `n'? */ |
| 301 | lua_rawset(L, -3); /* sizes[t] = n */ | 301 | lua_pushliteral(L, "n"); /* use it */ |
| 302 | lua_pop(L, 1); /* remove `sizes' */ | 302 | lua_pushinteger(L, n); |
| 303 | lua_rawset(L, t); | ||
| 304 | } | ||
| 305 | else { /* use `sizes' */ | ||
| 306 | getsizes(L); | ||
| 307 | lua_pushvalue(L, t); | ||
| 308 | lua_pushinteger(L, n); | ||
| 309 | lua_rawset(L, -3); /* sizes[t] = n */ | ||
| 310 | lua_pop(L, 1); /* remove `sizes' */ | ||
| 311 | } | ||
| 303 | } | 312 | } |
| 304 | 313 | ||
| 305 | 314 | ||
| 306 | LUALIB_API int luaL_getn (lua_State *L, int t) { | 315 | LUALIB_API int luaL_getn (lua_State *L, int t) { |
| 307 | int n; | 316 | int n; |
| 308 | t = abs_index(L, t); | 317 | t = abs_index(L, t); |
| 309 | getsizes(L); /* try sizes[t] */ | 318 | lua_pushliteral(L, "n"); /* try t.n */ |
| 319 | lua_rawget(L, t); | ||
| 320 | if ((n = checkint(L, 1)) >= 0) return n; | ||
| 321 | getsizes(L); /* else try sizes[t] */ | ||
| 310 | lua_pushvalue(L, t); | 322 | lua_pushvalue(L, t); |
| 311 | lua_rawget(L, -2); | 323 | lua_rawget(L, -2); |
| 312 | if ((n = checkint(L, 2)) >= 0) return n; | 324 | if ((n = checkint(L, 2)) >= 0) return n; |
| 313 | lua_getfield(L, t, "n"); /* else try t.n */ | ||
| 314 | if ((n = checkint(L, 1)) >= 0) return n; | ||
| 315 | return (int)lua_objlen(L, t); | 325 | return (int)lua_objlen(L, t); |
| 316 | } | 326 | } |
| 317 | 327 | ||
