aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c26
-rw-r--r--lbaselib.c5
-rw-r--r--ltablib.c29
-rw-r--r--lua.h4
4 files changed, 35 insertions, 29 deletions
diff --git a/lapi.c b/lapi.c
index 9ba82982..d3e95007 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.232 2014/07/30 14:00:14 roberto Exp roberto $ 2** $Id: lapi.c,v 2.233 2014/08/01 17:33:08 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -611,6 +611,18 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {
611} 611}
612 612
613 613
614LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
615 StkId t;
616 lua_lock(L);
617 t = index2addr(L, idx);
618 setivalue(L->top, n);
619 api_incr_top(L);
620 luaV_gettable(L, t, L->top - 1, L->top - 1);
621 lua_unlock(L);
622 return ttnov(L->top - 1);
623}
624
625
614LUA_API int lua_rawget (lua_State *L, int idx) { 626LUA_API int lua_rawget (lua_State *L, int idx) {
615 StkId t; 627 StkId t;
616 lua_lock(L); 628 lua_lock(L);
@@ -743,6 +755,18 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
743} 755}
744 756
745 757
758LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
759 StkId t;
760 lua_lock(L);
761 api_checknelems(L, 1);
762 t = index2addr(L, idx);
763 setivalue(L->top++, n);
764 luaV_settable(L, t, L->top - 1, L->top - 2);
765 L->top -= 2; /* pop value and key */
766 lua_unlock(L);
767}
768
769
746LUA_API void lua_rawset (lua_State *L, int idx) { 770LUA_API void lua_rawset (lua_State *L, int idx) {
747 StkId o; 771 StkId o;
748 Table *t; 772 Table *t;
diff --git a/lbaselib.c b/lbaselib.c
index 595f240f..ba92fc90 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.294 2014/08/01 17:22:57 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.295 2014/08/01 17:33: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*/
@@ -266,8 +266,7 @@ static int ipairsaux (lua_State *L) {
266 } 266 }
267 else { 267 else {
268 lua_pushinteger(L, i); 268 lua_pushinteger(L, i);
269 lua_pushinteger(L, i); /* key for indexing table */ 269 lua_geti(L, 1, i);
270 lua_gettable(L, 1);
271 return 2; 270 return 2;
272 } 271 }
273} 272}
diff --git a/ltablib.c b/ltablib.c
index 56b3c2bd..fd868915 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -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*/
33static 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*/
42static 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--) {
diff --git a/lua.h b/lua.h
index 8ac6991e..a092f829 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.312 2014/07/31 13:44:30 roberto Exp roberto $ 2** $Id: lua.h,v 1.313 2014/08/01 17:33:08 roberto Exp roberto $
3** Lua - A Scripting Language 3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file 5** See Copyright Notice at the end of this file
@@ -239,6 +239,7 @@ LUA_API int (lua_pushthread) (lua_State *L);
239LUA_API int (lua_getglobal) (lua_State *L, const char *var); 239LUA_API int (lua_getglobal) (lua_State *L, const char *var);
240LUA_API int (lua_gettable) (lua_State *L, int idx); 240LUA_API int (lua_gettable) (lua_State *L, int idx);
241LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k); 241LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
242LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
242LUA_API int (lua_rawget) (lua_State *L, int idx); 243LUA_API int (lua_rawget) (lua_State *L, int idx);
243LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); 244LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
244LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p); 245LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
@@ -255,6 +256,7 @@ LUA_API int (lua_getuservalue) (lua_State *L, int idx);
255LUA_API void (lua_setglobal) (lua_State *L, const char *var); 256LUA_API void (lua_setglobal) (lua_State *L, const char *var);
256LUA_API void (lua_settable) (lua_State *L, int idx); 257LUA_API void (lua_settable) (lua_State *L, int idx);
257LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 258LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
259LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
258LUA_API void (lua_rawset) (lua_State *L, int idx); 260LUA_API void (lua_rawset) (lua_State *L, int idx);
259LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n); 261LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
260LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); 262LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);