aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c4
-rw-r--r--ldo.c10
-rw-r--r--ldo.h1
-rw-r--r--lvm.c32
4 files changed, 18 insertions, 29 deletions
diff --git a/lapi.c b/lapi.c
index 07f2cfb2..30e4d268 100644
--- a/lapi.c
+++ b/lapi.c
@@ -104,7 +104,9 @@ LUA_API void lua_settop (lua_State *L, int index) {
104 lua_lock(L); 104 lua_lock(L);
105 if (index >= 0) { 105 if (index >= 0) {
106 api_check(L, index <= L->stack_last - L->ci->base); 106 api_check(L, index <= L->stack_last - L->ci->base);
107 luaD_adjusttop(L, L->ci->base+index); 107 while (L->top < L->ci->base + index)
108 setnilvalue(L->top++);
109 L->top = L->ci->base + index;
108 } 110 }
109 else { 111 else {
110 api_check(L, -(index+1) <= (L->top - L->ci->base)); 112 api_check(L, -(index+1) <= (L->top - L->ci->base));
diff --git a/ldo.c b/ldo.c
index ae70d268..18bd3d32 100644
--- a/ldo.c
+++ b/ldo.c
@@ -69,16 +69,6 @@ void luaD_stackerror (lua_State *L) {
69 69
70 70
71/* 71/*
72** adjust top to new value; assume that new top is valid
73*/
74void luaD_adjusttop (lua_State *L, StkId newtop) {
75 while (L->top < newtop)
76 setnilvalue(L->top++);
77 L->top = newtop; /* `newtop' could be lower than `top' */
78}
79
80
81/*
82** Open a hole inside the stack at `pos' 72** Open a hole inside the stack at `pos'
83*/ 73*/
84static void luaD_openstack (lua_State *L, StkId pos) { 74static void luaD_openstack (lua_State *L, StkId pos) {
diff --git a/ldo.h b/ldo.h
index 100bc3d1..769fccb9 100644
--- a/ldo.h
+++ b/ldo.h
@@ -23,7 +23,6 @@
23 23
24 24
25void luaD_init (lua_State *L, int stacksize); 25void luaD_init (lua_State *L, int stacksize);
26void luaD_adjusttop (lua_State *L, StkId newtop);
27void luaD_lineHook (lua_State *L, int line, lua_Hook linehook); 26void luaD_lineHook (lua_State *L, int line, lua_Hook linehook);
28void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event); 27void luaD_callHook (lua_State *L, lua_Hook callhook, const char *event);
29StkId luaD_precall (lua_State *L, StkId func); 28StkId luaD_precall (lua_State *L, StkId func);
diff --git a/lvm.c b/lvm.c
index 435229a0..b56622e7 100644
--- a/lvm.c
+++ b/lvm.c
@@ -256,33 +256,29 @@ void luaV_strconc (lua_State *L, int total, StkId top) {
256} 256}
257 257
258 258
259static void luaV_pack (lua_State *L, StkId firstelem) { 259static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
260 int i; 260 int i;
261 Table *htab = luaH_new(L, 0, 0); 261 Table *htab;
262 TObject n, nname; 262 TObject n, nname;
263 for (i=0; firstelem+i<L->top; i++) 263 StkId firstvar = base + nfixargs; /* position of first vararg */
264 luaH_setnum(L, htab, i+1, firstelem+i); 264 if (L->top < firstvar) {
265 luaD_checkstack(L, firstvar - L->top);
266 while (L->top < firstvar)
267 setnilvalue(L->top++);
268 }
269 htab = luaH_new(L, 0, 0);
270 for (i=0; firstvar+i<L->top; i++)
271 luaH_setnum(L, htab, i+1, firstvar+i);
265 /* store counter in field `n' */ 272 /* store counter in field `n' */
266 setnvalue(&n, i); 273 setnvalue(&n, i);
267 setsvalue(&nname, luaS_newliteral(L, "n")); 274 setsvalue(&nname, luaS_newliteral(L, "n"));
268 luaH_set(L, htab, &nname, &n); 275 luaH_set(L, htab, &nname, &n);
269 L->top = firstelem; /* remove elements from the stack */ 276 L->top = firstvar; /* remove elements from the stack */
270 sethvalue(L->top, htab); 277 sethvalue(L->top, htab);
271 incr_top; 278 incr_top;
272} 279}
273 280
274 281
275static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
276 int nvararg = (L->top-base) - nfixargs;
277 StkId firstvar = base + nfixargs; /* position of first vararg */
278 if (nvararg < 0) {
279 luaD_checkstack(L, -nvararg);
280 luaD_adjusttop(L, firstvar);
281 }
282 luaV_pack(L, firstvar);
283}
284
285
286static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) { 282static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
287 const TObject *b = rb; 283 const TObject *b = rb;
288 const TObject *c = rc; 284 const TObject *c = rc;
@@ -352,7 +348,9 @@ StkId luaV_execute (lua_State *L, const LClosure *cl, StkId base) {
352 adjust_varargs(L, base, cl->p->numparams); 348 adjust_varargs(L, base, cl->p->numparams);
353 if (base > L->stack_last - cl->p->maxstacksize) 349 if (base > L->stack_last - cl->p->maxstacksize)
354 luaD_stackerror(L); 350 luaD_stackerror(L);
355 luaD_adjusttop(L, base + cl->p->maxstacksize); 351 while (L->top < base + cl->p->maxstacksize)
352 setnilvalue(L->top++);
353 L->top = base + cl->p->maxstacksize;
356 L->ci->pc = &pc; 354 L->ci->pc = &pc;
357 linehook = L->ci->linehook = L->linehook; 355 linehook = L->ci->linehook = L->linehook;
358 pc = cl->p->code; 356 pc = cl->p->code;