aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-10 09:57:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-10-10 09:57:55 -0300
commit533737f26e3f8036d7978e09427ea5ff75aec9df (patch)
tree003004a423cf20bc4e1493918760494b0d694f93 /lapi.c
parenta41d60e1d1f3a954648884d4ab7fb7e9ccdd52d6 (diff)
downloadlua-533737f26e3f8036d7978e09427ea5ff75aec9df.tar.gz
lua-533737f26e3f8036d7978e09427ea5ff75aec9df.tar.bz2
lua-533737f26e3f8036d7978e09427ea5ff75aec9df.zip
new functions `lua_getfield' and `lua_setfield'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/lapi.c b/lapi.c
index b40f984a..16686e7e 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.244 2003/08/27 21:01:44 roberto Exp roberto $ 2** $Id: lapi.c,v 1.245 2003/10/07 20:13:41 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*/
@@ -498,6 +498,19 @@ LUA_API void lua_gettable (lua_State *L, int idx) {
498} 498}
499 499
500 500
501LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
502 StkId t;
503 TObject key;
504 lua_lock(L);
505 t = luaA_index(L, idx);
506 api_checkvalidindex(L, t);
507 setsvalue(&key, luaS_new(L, k));
508 luaV_gettable(L, t, &key, L->top);
509 api_incr_top(L);
510 lua_unlock(L);
511}
512
513
501LUA_API void lua_rawget (lua_State *L, int idx) { 514LUA_API void lua_rawget (lua_State *L, int idx) {
502 StkId t; 515 StkId t;
503 lua_lock(L); 516 lua_lock(L);
@@ -582,6 +595,20 @@ LUA_API void lua_settable (lua_State *L, int idx) {
582} 595}
583 596
584 597
598LUA_API void lua_setfield (lua_State *L, int idx, const char *k) {
599 StkId t;
600 TObject key;
601 lua_lock(L);
602 api_checknelems(L, 1);
603 t = luaA_index(L, idx);
604 api_checkvalidindex(L, t);
605 setsvalue(&key, luaS_new(L, k));
606 luaV_settable(L, t, &key, L->top - 1);
607 L->top--; /* pop value */
608 lua_unlock(L);
609}
610
611
585LUA_API void lua_rawset (lua_State *L, int idx) { 612LUA_API void lua_rawset (lua_State *L, int idx) {
586 StkId t; 613 StkId t;
587 lua_lock(L); 614 lua_lock(L);