From 292c9530183a8e9939cff9a7d30fc50e85031698 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 5 Jun 2000 17:15:33 -0300 Subject: new auxiliar function `luaH_setstr' --- lbuiltin.c | 9 ++------- ltable.c | 10 +++++++++- ltable.h | 3 ++- lvm.c | 7 +++---- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lbuiltin.c b/lbuiltin.c index 2e5833ed..19cdb6d6 100644 --- a/lbuiltin.c +++ b/lbuiltin.c @@ -1,5 +1,5 @@ /* -** $Id: lbuiltin.c,v 1.111 2000/05/26 19:17:57 roberto Exp roberto $ +** $Id: lbuiltin.c,v 1.112 2000/06/02 19:08:56 roberto Exp roberto $ ** Built-in functions ** See Copyright Notice in lua.h */ @@ -68,12 +68,7 @@ static Number getsize (const Hash *h) { static Number getnarg (lua_State *L, const Hash *a) { - TObject index; - const TObject *value; - /* value = table.n */ - ttype(&index) = TAG_STRING; - tsvalue(&index) = luaS_new(L, "n"); - value = luaH_get(L, a, &index); + const TObject *value = luaH_getstr(a, luaS_new(L, "n")); /* value = a.n */ return (ttype(value) == TAG_NUMBER) ? nvalue(value) : getsize(a); } diff --git a/ltable.c b/ltable.c index 9929146d..4ffd2f9d 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.43 2000/05/24 13:54:49 roberto Exp roberto $ +** $Id: ltable.c,v 1.44 2000/06/05 20:07:53 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -278,6 +278,14 @@ void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val) { } +void luaH_setstr (lua_State *L, Hash *t, TString *key, const TObject *val) { + TObject index; + ttype(&index) = TAG_STRING; + tsvalue(&index) = key; + luaH_set(L, t, &index, val); +} + + const TObject *luaH_getglobal (lua_State *L, const char *name) { return luaH_getstr(L->gt, luaS_new(L, name)); } diff --git a/ltable.h b/ltable.h index df36e8a6..52053f8f 100644 --- a/ltable.h +++ b/ltable.h @@ -1,5 +1,5 @@ /* -** $Id: ltable.h,v 1.20 2000/05/08 19:32:53 roberto Exp roberto $ +** $Id: ltable.h,v 1.21 2000/06/05 20:07:53 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -25,6 +25,7 @@ void luaH_remove (Hash *t, TObject *key); void luaH_set (lua_State *L, Hash *t, const TObject *key, const TObject *val); int luaH_pos (lua_State *L, const Hash *t, const TObject *r); void luaH_setint (lua_State *L, Hash *t, int key, const TObject *val); +void luaH_setstr (lua_State *L, Hash *t, TString *key, const TObject *val); unsigned long luaH_hash (lua_State *L, const TObject *key); const TObject *luaH_getglobal (lua_State *L, const char *name); diff --git a/lvm.c b/lvm.c index d53017a8..c264fd96 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.110 2000/05/30 19:00:31 roberto Exp roberto $ +** $Id: lvm.c,v 1.111 2000/06/05 14:56:18 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -66,10 +66,9 @@ int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */ void luaV_setn (lua_State *L, Hash *t, int val) { - TObject index, value; - ttype(&index) = TAG_STRING; tsvalue(&index) = luaS_new(L, "n"); + TObject value; ttype(&value) = TAG_NUMBER; nvalue(&value) = val; - luaH_set(L, t, &index, &value); + luaH_setstr(L, t, luaS_new(L, "n"), &value); } -- cgit v1.2.3-55-g6feb