lua

A copy of the Lua development repository
Log | Files | Refs | README

commit b1141427991dea7a96597f2aacdedf243b60decd
parent 4b2e71ddb674c3bb22f549743721155ddaeb9b5d
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Tue, 26 Aug 2003 09:03:51 -0300

new auxiliary function `luaH_setstr'

Diffstat:
Mldo.c | 7+++----
Mltable.c | 14+++++++++++++-
Mltable.h | 3++-
3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/ldo.c b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.221 2003/07/16 20:51:47 roberto Exp roberto $ +** $Id: ldo.c,v 1.222 2003/08/25 19:51:54 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -198,7 +198,6 @@ void luaD_callhook (lua_State *L, int event, int line) { static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { int i; Table *htab; - TObject nname; int actual = L->top - base; /* actual number of arguments */ if (actual < nfixargs) { luaD_checkstack(L, nfixargs - actual); @@ -210,8 +209,8 @@ static void adjust_varargs (lua_State *L, int nfixargs, StkId base) { for (i=0; i<actual; i++) /* put extra arguments into `arg' table */ setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i); /* store counter in field `n' */ - setsvalue(&nname, luaS_newliteral(L, "n")); - setnvalue(luaH_set(L, htab, &nname), cast(lua_Number, actual)); + setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), + cast(lua_Number, actual)); L->top -= actual; /* remove extra elements from the stack */ sethvalue(L->top, htab); incr_top(L); diff --git a/ltable.c b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.133 2003/04/28 13:31:46 roberto Exp roberto $ +** $Id: ltable.c,v 1.134 2003/04/28 19:26:16 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -511,3 +511,15 @@ TObject *luaH_setnum (lua_State *L, Table *t, int key) { } } + +TObject *luaH_setstr (lua_State *L, Table *t, TString *key) { + const TObject *p = luaH_getstr(t, key); + if (p != &luaO_nilobject) + return cast(TObject *, p); + else { + TObject k; + setsvalue(&k, key); + return newkey(L, t, &k); + } +} + diff --git a/ltable.h b/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 1.43 2002/11/07 16:03:33 roberto Exp roberto $ +** $Id: ltable.h,v 1.44 2003/03/18 12:50:04 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -18,6 +18,7 @@ const TObject *luaH_getnum (Table *t, int key); TObject *luaH_setnum (lua_State *L, Table *t, int key); const TObject *luaH_getstr (Table *t, TString *key); +TObject *luaH_setstr (lua_State *L, Table *t, TString *key); const TObject *luaH_get (Table *t, const TObject *key); TObject *luaH_set (lua_State *L, Table *t, const TObject *key); Table *luaH_new (lua_State *L, int narray, int lnhash);