aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-10 16:56:11 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-10 16:56:11 -0200
commitdabb19fc17acee55f9052c5d17ec07360cec809d (patch)
tree76983221f936eee7e681559093b3b23f8968e711 /lvm.c
parent08496eea8b277d37c4de9cf75a011715ad6a4100 (diff)
downloadlua-dabb19fc17acee55f9052c5d17ec07360cec809d.tar.gz
lua-dabb19fc17acee55f9052c5d17ec07360cec809d.tar.bz2
lua-dabb19fc17acee55f9052c5d17ec07360cec809d.zip
specialized versions for luaH_set (numbers and strings)
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/lvm.c b/lvm.c
index 0642db6b..a324ea69 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.149 2000/12/28 12:55:41 roberto Exp roberto $ 2** $Id: lvm.c,v 1.150 2001/01/10 17:41:50 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -122,7 +122,7 @@ const TObject *luaV_gettable (lua_State *L, StkId t) {
122 ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */ 122 ((tg = hvalue(t)->htag) == LUA_TTABLE || /* with default tag? */
123 luaT_gettm(L, tg, TM_GETTABLE) == NULL)) { /* or no TM? */ 123 luaT_gettm(L, tg, TM_GETTABLE) == NULL)) { /* or no TM? */
124 /* do a primitive get */ 124 /* do a primitive get */
125 const TObject *h = luaH_get(L, hvalue(t), L->top-1); 125 const TObject *h = luaH_get(hvalue(t), L->top-1);
126 /* result is no nil or there is no `index' tag method? */ 126 /* result is no nil or there is no `index' tag method? */
127 if (ttype(h) != LUA_TNIL || ((tm=luaT_gettm(L, tg, TM_INDEX)) == NULL)) 127 if (ttype(h) != LUA_TNIL || ((tm=luaT_gettm(L, tg, TM_INDEX)) == NULL))
128 return h; /* return result */ 128 return h; /* return result */
@@ -195,21 +195,11 @@ const TObject *luaV_getglobal (lua_State *L, TString *s) {
195 195
196 196
197void luaV_setglobal (lua_State *L, TString *s) { 197void luaV_setglobal (lua_State *L, TString *s) {
198 const TObject *oldvalue = luaH_getstr(L->gt, s); 198 TObject *oldvalue = luaH_setstr(L, L->gt, s);
199 Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL); 199 Closure *tm = luaT_gettmbyObj(L, oldvalue, TM_SETGLOBAL);
200 if (tm == NULL) { /* is there a tag method? */ 200 if (tm == NULL) /* no tag methods? */
201 if (oldvalue != &luaO_nilobject) { 201 *oldvalue = *(L->top - 1); /* raw set */
202 /* cast to remove `const' is OK, because `oldvalue' != luaO_nilobject */ 202 else { /* call tag method */
203 *(TObject *)oldvalue = *(L->top - 1);
204 }
205 else {
206 TObject key;
207 ttype(&key) = LUA_TSTRING;
208 tsvalue(&key) = s;
209 *luaH_set(L, L->gt, &key) = *(L->top - 1);
210 }
211 }
212 else {
213 luaD_checkstack(L, 3); 203 luaD_checkstack(L, 3);
214 *(L->top+2) = *(L->top-1); /* new value */ 204 *(L->top+2) = *(L->top-1); /* new value */
215 *(L->top+1) = *oldvalue; 205 *(L->top+1) = *oldvalue;
@@ -320,12 +310,15 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
320 310
321 311
322static void luaV_pack (lua_State *L, StkId firstelem) { 312static void luaV_pack (lua_State *L, StkId firstelem) {
313 TObject *nf;
323 int i; 314 int i;
324 Hash *htab = luaH_new(L, 0); 315 Hash *htab = luaH_new(L, 0);
325 for (i=0; firstelem+i<L->top; i++) 316 for (i=0; firstelem+i<L->top; i++)
326 *luaH_setint(L, htab, i+1) = *(firstelem+i); 317 *luaH_setnum(L, htab, i+1) = *(firstelem+i);
327 /* store counter in field `n' */ 318 /* store counter in field `n' */
328 luaH_setstrnum(L, htab, luaS_newliteral(L, "n"), i); 319 nf = luaH_setstr(L, htab, luaS_newliteral(L, "n"));
320 ttype(nf) = LUA_TNUMBER;
321 nvalue(nf) = i;
329 L->top = firstelem; /* remove elements from the stack */ 322 L->top = firstelem; /* remove elements from the stack */
330 ttype(L->top) = LUA_TTABLE; 323 ttype(L->top) = LUA_TTABLE;
331 hvalue(L->top) = htab; 324 hvalue(L->top) = htab;
@@ -498,7 +491,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
498 Hash *arr = hvalue(top-n-1); 491 Hash *arr = hvalue(top-n-1);
499 L->top = top-n; /* final value of `top' (in case of errors) */ 492 L->top = top-n; /* final value of `top' (in case of errors) */
500 for (; n; n--) 493 for (; n; n--)
501 *luaH_setint(L, arr, n+aux) = *(--top); 494 *luaH_setnum(L, arr, n+aux) = *(--top);
502 break; 495 break;
503 } 496 }
504 case OP_SETMAP: { 497 case OP_SETMAP: {