new functions 'lua_geti/lua_seti' (non raw)

This commit is contained in:
Roberto Ierusalimschy
2014-08-21 17:07:56 -03:00
parent a1ab5ab396
commit 7f1a2ad699
4 changed files with 35 additions and 29 deletions

26
lapi.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.232 2014/07/30 14:00:14 roberto Exp roberto $
** $Id: lapi.c,v 2.233 2014/08/01 17:33:08 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -611,6 +611,18 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {
}
LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
StkId t;
lua_lock(L);
t = index2addr(L, idx);
setivalue(L->top, n);
api_incr_top(L);
luaV_gettable(L, t, L->top - 1, L->top - 1);
lua_unlock(L);
return ttnov(L->top - 1);
}
LUA_API int lua_rawget (lua_State *L, int idx) {
StkId t;
lua_lock(L);
@@ -743,6 +755,18 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
}
LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
StkId t;
lua_lock(L);
api_checknelems(L, 1);
t = index2addr(L, idx);
setivalue(L->top++, n);
luaV_settable(L, t, L->top - 1, L->top - 2);
L->top -= 2; /* pop value and key */
lua_unlock(L);
}
LUA_API void lua_rawset (lua_State *L, int idx) {
StkId o;
Table *t;