diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-08-26 09:04:13 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-08-26 09:04:13 -0300 |
commit | b1141427991dea7a96597f2aacdedf243b60decd (patch) | |
tree | 28a56414da88099502ae7d182b44e5201856c787 | |
parent | 4b2e71ddb674c3bb22f549743721155ddaeb9b5d (diff) | |
download | lua-b1141427991dea7a96597f2aacdedf243b60decd.tar.gz lua-b1141427991dea7a96597f2aacdedf243b60decd.tar.bz2 lua-b1141427991dea7a96597f2aacdedf243b60decd.zip |
new auxiliary function `luaH_setstr'
-rw-r--r-- | ldo.c | 7 | ||||
-rw-r--r-- | ltable.c | 14 | ||||
-rw-r--r-- | ltable.h | 3 |
3 files changed, 18 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.221 2003/07/16 20:51:47 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.222 2003/08/25 19:51:54 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -198,7 +198,6 @@ void luaD_callhook (lua_State *L, int event, int line) { | |||
198 | static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { | 198 | static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { |
199 | int i; | 199 | int i; |
200 | Table *htab; | 200 | Table *htab; |
201 | TObject nname; | ||
202 | int actual = L->top - base; /* actual number of arguments */ | 201 | int actual = L->top - base; /* actual number of arguments */ |
203 | if (actual < nfixargs) { | 202 | if (actual < nfixargs) { |
204 | luaD_checkstack(L, nfixargs - actual); | 203 | luaD_checkstack(L, nfixargs - actual); |
@@ -210,8 +209,8 @@ static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { | |||
210 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ | 209 | for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ |
211 | setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i); | 210 | setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i); |
212 | /* store counter in field `n' */ | 211 | /* store counter in field `n' */ |
213 | setsvalue(&nname, luaS_newliteral(L, "n")); | 212 | setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), |
214 | setnvalue(luaH_set(L, htab, &nname), cast(lua_Number, actual)); | 213 | cast(lua_Number, actual)); |
215 | L->top -= actual; /* remove extra elements from the stack */ | 214 | L->top -= actual; /* remove extra elements from the stack */ |
216 | sethvalue(L->top, htab); | 215 | sethvalue(L->top, htab); |
217 | incr_top(L); | 216 | incr_top(L); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.133 2003/04/28 13:31:46 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.134 2003/04/28 19:26:16 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -511,3 +511,15 @@ TObject *luaH_setnum (lua_State *L, Table *t, int key) { | |||
511 | } | 511 | } |
512 | } | 512 | } |
513 | 513 | ||
514 | |||
515 | TObject *luaH_setstr (lua_State *L, Table *t, TString *key) { | ||
516 | const TObject *p = luaH_getstr(t, key); | ||
517 | if (p != &luaO_nilobject) | ||
518 | return cast(TObject *, p); | ||
519 | else { | ||
520 | TObject k; | ||
521 | setsvalue(&k, key); | ||
522 | return newkey(L, t, &k); | ||
523 | } | ||
524 | } | ||
525 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.h,v 1.43 2002/11/07 16:03:33 roberto Exp roberto $ | 2 | ** $Id: ltable.h,v 1.44 2003/03/18 12:50:04 roberto Exp roberto $ |
3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,6 +18,7 @@ | |||
18 | const TObject *luaH_getnum (Table *t, int key); | 18 | const TObject *luaH_getnum (Table *t, int key); |
19 | TObject *luaH_setnum (lua_State *L, Table *t, int key); | 19 | TObject *luaH_setnum (lua_State *L, Table *t, int key); |
20 | const TObject *luaH_getstr (Table *t, TString *key); | 20 | const TObject *luaH_getstr (Table *t, TString *key); |
21 | TObject *luaH_setstr (lua_State *L, Table *t, TString *key); | ||
21 | const TObject *luaH_get (Table *t, const TObject *key); | 22 | const TObject *luaH_get (Table *t, const TObject *key); |
22 | TObject *luaH_set (lua_State *L, Table *t, const TObject *key); | 23 | TObject *luaH_set (lua_State *L, Table *t, const TObject *key); |
23 | Table *luaH_new (lua_State *L, int narray, int lnhash); | 24 | Table *luaH_new (lua_State *L, int narray, int lnhash); |