diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-08-21 17:07:56 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-08-21 17:07:56 -0300 |
| commit | 7f1a2ad69976cc6891c104d2b669771820b8959a (patch) | |
| tree | e9c21db809a04e80a8db95eea379981f32d74131 /lapi.c | |
| parent | a1ab5ab396df521eff70f304e571c16b809037d1 (diff) | |
| download | lua-7f1a2ad69976cc6891c104d2b669771820b8959a.tar.gz lua-7f1a2ad69976cc6891c104d2b669771820b8959a.tar.bz2 lua-7f1a2ad69976cc6891c104d2b669771820b8959a.zip | |
new functions 'lua_geti/lua_seti' (non raw)
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 26 |
1 files changed, 25 insertions, 1 deletions
| @@ -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 | ||
| 614 | LUA_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 | |||
| 614 | LUA_API int lua_rawget (lua_State *L, int idx) { | 626 | LUA_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 | ||
| 758 | LUA_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 | |||
| 746 | LUA_API void lua_rawset (lua_State *L, int idx) { | 770 | LUA_API void lua_rawset (lua_State *L, int idx) { |
| 747 | StkId o; | 771 | StkId o; |
| 748 | Table *t; | 772 | Table *t; |
