diff options
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 29 |
1 files changed, 5 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.73 2014/07/29 16:01:00 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.74 2014/08/21 19:13:55 roberto Exp roberto $ |
3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -28,25 +28,6 @@ typedef struct { | |||
28 | 28 | ||
29 | 29 | ||
30 | /* | 30 | /* |
31 | ** equivalent to 'lua_rawgeti', but not raw | ||
32 | */ | ||
33 | static int geti (lua_State *L, int idx, lua_Integer n) { | ||
34 | lua_pushinteger(L, n); | ||
35 | return lua_gettable(L, idx); /* assume 'idx' is not negative */ | ||
36 | } | ||
37 | |||
38 | |||
39 | /* | ||
40 | ** equivalent to 'lua_rawseti', but not raw | ||
41 | */ | ||
42 | static void seti (lua_State *L, int idx, lua_Integer n) { | ||
43 | lua_pushinteger(L, n); | ||
44 | lua_rotate(L, -2, 1); /* exchange key and value */ | ||
45 | lua_settable(L, idx); /* assume 'idx' is not negative */ | ||
46 | } | ||
47 | |||
48 | |||
49 | /* | ||
50 | ** Check that 'arg' has a table and set access functions in 'ta' to raw | 31 | ** Check that 'arg' has a table and set access functions in 'ta' to raw |
51 | ** or non-raw according to the presence of corresponding metamethods. | 32 | ** or non-raw according to the presence of corresponding metamethods. |
52 | */ | 33 | */ |
@@ -55,10 +36,10 @@ static void checktab (lua_State *L, int arg, TabA *ta) { | |||
55 | if (lua_getmetatable(L, arg)) { | 36 | if (lua_getmetatable(L, arg)) { |
56 | lua_pushliteral(L, "__index"); /* 'index' metamethod */ | 37 | lua_pushliteral(L, "__index"); /* 'index' metamethod */ |
57 | if (lua_rawget(L, -2) != LUA_TNIL) | 38 | if (lua_rawget(L, -2) != LUA_TNIL) |
58 | ta->geti = geti; | 39 | ta->geti = lua_geti; |
59 | lua_pushliteral(L, "__newindex"); /* 'newindex' metamethod */ | 40 | lua_pushliteral(L, "__newindex"); /* 'newindex' metamethod */ |
60 | if (lua_rawget(L, -3) != LUA_TNIL) | 41 | if (lua_rawget(L, -3) != LUA_TNIL) |
61 | ta->seti = seti; | 42 | ta->seti = lua_seti; |
62 | lua_pop(L, 3); /* pop metatable plus both metamethods */ | 43 | lua_pop(L, 3); /* pop metatable plus both metamethods */ |
63 | } | 44 | } |
64 | if (ta->geti == NULL || ta->seti == NULL) { | 45 | if (ta->geti == NULL || ta->seti == NULL) { |
@@ -147,10 +128,10 @@ static int tmove (lua_State *L) { | |||
147 | lua_Integer n, i; | 128 | lua_Integer n, i; |
148 | ta.geti = (!luaL_getmetafield(L, 1, "__index")) | 129 | ta.geti = (!luaL_getmetafield(L, 1, "__index")) |
149 | ? (luaL_checktype(L, 1, LUA_TTABLE), lua_rawgeti) | 130 | ? (luaL_checktype(L, 1, LUA_TTABLE), lua_rawgeti) |
150 | : geti; | 131 | : lua_geti; |
151 | ta.seti = (!luaL_getmetafield(L, tt, "__newindex")) | 132 | ta.seti = (!luaL_getmetafield(L, tt, "__newindex")) |
152 | ? (luaL_checktype(L, tt, LUA_TTABLE), lua_rawseti) | 133 | ? (luaL_checktype(L, tt, LUA_TTABLE), lua_rawseti) |
153 | : seti; | 134 | : lua_seti; |
154 | n = e - f + 1; /* number of elements to move */ | 135 | n = e - f + 1; /* number of elements to move */ |
155 | if (t > f) { | 136 | if (t > f) { |
156 | for (i = n - 1; i >= 0; i--) { | 137 | for (i = n - 1; i >= 0; i--) { |