diff options
Diffstat (limited to 'lvm.c')
| -rw-r--r-- | lvm.c | 27 |
1 files changed, 11 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.128 2000/08/22 20:49:29 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.129 2000/08/22 20:53:30 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 | */ |
| @@ -313,30 +313,25 @@ static void strconc (lua_State *L, int total, StkId top) { | |||
| 313 | } | 313 | } |
| 314 | 314 | ||
| 315 | 315 | ||
| 316 | void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) { | 316 | void luaV_pack (lua_State *L, StkId firstelem) { |
| 317 | int i; | 317 | int i; |
| 318 | Hash *htab; | 318 | Hash *htab = luaH_new(L, 0); |
| 319 | htab = hvalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */ | 319 | for (i=0; firstelem+i<L->top; i++) |
| 320 | ttype(tab) = TAG_TABLE; | ||
| 321 | for (i=0; i<nvararg; i++) | ||
| 322 | *luaH_setint(L, htab, i+1) = *(firstelem+i); | 320 | *luaH_setint(L, htab, i+1) = *(firstelem+i); |
| 323 | /* store counter in field `n' */ | 321 | /* store counter in field `n' */ |
| 324 | luaH_setstrnum(L, htab, luaS_new(L, "n"), nvararg); | 322 | luaH_setstrnum(L, htab, luaS_new(L, "n"), i); |
| 323 | L->top = firstelem; /* remove elements from the stack */ | ||
| 324 | ttype(L->top) = TAG_TABLE; | ||
| 325 | hvalue(L->top) = htab; | ||
| 326 | incr_top; | ||
| 325 | } | 327 | } |
| 326 | 328 | ||
| 327 | 329 | ||
| 328 | static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { | 330 | static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { |
| 329 | TObject arg; | ||
| 330 | int nvararg = (L->top-base) - nfixargs; | 331 | int nvararg = (L->top-base) - nfixargs; |
| 331 | if (nvararg < 0) { | 332 | if (nvararg < 0) |
| 332 | luaV_pack(L, base, 0, &arg); | ||
| 333 | luaD_adjusttop(L, base, nfixargs); | 333 | luaD_adjusttop(L, base, nfixargs); |
| 334 | } | 334 | luaV_pack(L, base+nfixargs); |
| 335 | else { | ||
| 336 | luaV_pack(L, base+nfixargs, nvararg, &arg); | ||
| 337 | L->top = base+nfixargs; | ||
| 338 | } | ||
| 339 | *L->top++ = arg; | ||
| 340 | } | 335 | } |
| 341 | 336 | ||
| 342 | 337 | ||
