summaryrefslogtreecommitdiff
path: root/src/ldo.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/ldo.js')
-rw-r--r--src/ldo.js247
1 files changed, 136 insertions, 111 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 3adedd4..5f849ca 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -1,30 +1,56 @@
"use strict";
-const assert = require('assert');
-
-const defs = require('./defs.js');
+const {
+ LUA_HOOKCALL,
+ LUA_HOOKRET,
+ LUA_HOOKTAILCALL,
+ LUA_MASKCALL,
+ LUA_MASKLINE,
+ LUA_MASKRET,
+ LUA_MINSTACK,
+ LUA_MULTRET,
+ LUA_SIGNATURE,
+ constant_types: {
+ LUA_TCCL,
+ LUA_TLCF,
+ LUA_TLCL,
+ LUA_TNIL
+ },
+ thread_status: {
+ LUA_ERRMEM,
+ LUA_ERRERR,
+ LUA_ERRRUN,
+ LUA_ERRSYNTAX,
+ LUA_OK,
+ LUA_YIELD
+ },
+ lua_Debug,
+ luastring_indexOf,
+ to_luastring
+} = require('./defs.js');
const lapi = require('./lapi.js');
const ldebug = require('./ldebug.js');
const lfunc = require('./lfunc.js');
-const llimits = require('./llimits.js');
+const {
+ api_check,
+ lua_assert,
+ LUAI_MAXCCALLS
+} = require('./llimits.js');
const lobject = require('./lobject.js');
const lopcodes = require('./lopcodes.js');
const lparser = require('./lparser.js');
const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
+const { luaS_newliteral } = require('./lstring.js');
const ltm = require('./ltm.js');
-const luaconf = require('./luaconf.js');
+const { LUAI_MAXSTACK } = require('./luaconf.js');
const lundump = require('./lundump.js');
const lvm = require('./lvm.js');
-const lzio = require('./lzio.js');
-
-const CT = defs.constant_types;
-const TS = defs.thread_status;
+const { MBuffer } = require('./lzio.js');
const adjust_top = function(L, newtop) {
if (L.top < newtop) {
while (L.top < newtop)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+ L.stack[L.top++] = new lobject.TValue(LUA_TNIL, null);
} else {
while (L.top > newtop)
delete L.stack[--L.top];
@@ -36,15 +62,15 @@ const seterrorobj = function(L, errcode, oldtop) {
/* extend stack so that L.stack[oldtop] is sure to exist */
while (L.top < oldtop + 1)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+ L.stack[L.top++] = new lobject.TValue(LUA_TNIL, null);
switch (errcode) {
- case TS.LUA_ERRMEM: {
- lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "not enough memory"));
+ case LUA_ERRMEM: {
+ lobject.setsvalue2s(L, oldtop, luaS_newliteral(L, "not enough memory"));
break;
}
- case TS.LUA_ERRERR: {
- lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "error in error handling"));
+ case LUA_ERRERR: {
+ lobject.setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling"));
break;
}
default: {
@@ -56,27 +82,27 @@ const seterrorobj = function(L, errcode, oldtop) {
delete L.stack[--L.top];
};
-const ERRORSTACKSIZE = luaconf.LUAI_MAXSTACK + 200;
+const ERRORSTACKSIZE = LUAI_MAXSTACK + 200;
const luaD_reallocstack = function(L, newsize) {
- assert(newsize <= luaconf.LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
- assert(L.stack_last == L.stack.length - lstate.EXTRA_STACK);
+ lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
+ lua_assert(L.stack_last == L.stack.length - lstate.EXTRA_STACK);
L.stack.length = newsize;
L.stack_last = newsize - lstate.EXTRA_STACK;
};
const luaD_growstack = function(L, n) {
let size = L.stack.length;
- if (size > luaconf.LUAI_MAXSTACK)
- luaD_throw(L, TS.LUA_ERRERR);
+ if (size > LUAI_MAXSTACK)
+ luaD_throw(L, LUA_ERRERR);
else {
let needed = L.top + n + lstate.EXTRA_STACK;
let newsize = 2 * size;
- if (newsize > luaconf.LUAI_MAXSTACK) newsize = luaconf.LUAI_MAXSTACK;
+ if (newsize > LUAI_MAXSTACK) newsize = LUAI_MAXSTACK;
if (newsize < needed) newsize = needed;
- if (newsize > luaconf.LUAI_MAXSTACK) { /* stack overflow? */
+ if (newsize > LUAI_MAXSTACK) { /* stack overflow? */
luaD_reallocstack(L, ERRORSTACKSIZE);
- ldebug.luaG_runerror(L, defs.to_luastring("stack overflow", true));
+ ldebug.luaG_runerror(L, to_luastring("stack overflow", true));
}
else
luaD_reallocstack(L, newsize);
@@ -93,26 +119,26 @@ const stackinuse = function(L) {
for (let ci = L.ci; ci !== null; ci = ci.previous) {
if (lim < ci.top) lim = ci.top;
}
- assert(lim <= L.stack_last);
+ lua_assert(lim <= L.stack_last);
return lim + 1; /* part of stack in use */
};
const luaD_shrinkstack = function(L) {
let inuse = stackinuse(L);
let goodsize = inuse + Math.floor(inuse / 8) + 2*lstate.EXTRA_STACK;
- if (goodsize > luaconf.LUAI_MAXSTACK)
- goodsize = luaconf.LUAI_MAXSTACK; /* respect stack limit */
- if (L.stack.length > luaconf.LUAI_MAXSTACK) /* had been handling stack overflow? */
+ if (goodsize > LUAI_MAXSTACK)
+ goodsize = LUAI_MAXSTACK; /* respect stack limit */
+ if (L.stack.length > LUAI_MAXSTACK) /* had been handling stack overflow? */
lstate.luaE_freeCI(L); /* free all CIs (list grew because of an error) */
/* if thread is currently not handling a stack overflow and its
good size is smaller than current size, shrink its stack */
- if (inuse <= (luaconf.LUAI_MAXSTACK - lstate.EXTRA_STACK) && goodsize < L.stack.length)
+ if (inuse <= (LUAI_MAXSTACK - lstate.EXTRA_STACK) && goodsize < L.stack.length)
luaD_reallocstack(L, goodsize);
};
const luaD_inctop = function(L) {
luaD_checkstack(L, 1);
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+ L.stack[L.top++] = new lobject.TValue(LUA_TNIL, null);
};
/*
@@ -126,30 +152,30 @@ const luaD_precall = function(L, off, nresults) {
let func = L.stack[off];
switch(func.type) {
- case CT.LUA_TCCL:
- case CT.LUA_TLCF: {
- let f = func.type === CT.LUA_TCCL ? func.value.f : func.value;
+ case LUA_TCCL:
+ case LUA_TLCF: {
+ let f = func.type === LUA_TCCL ? func.value.f : func.value;
- luaD_checkstack(L, defs.LUA_MINSTACK);
+ luaD_checkstack(L, LUA_MINSTACK);
let ci = lstate.luaE_extendCI(L);
ci.funcOff = off;
ci.nresults = nresults;
ci.func = func;
- ci.top = L.top + defs.LUA_MINSTACK;
- assert(ci.top <= L.stack_last);
+ ci.top = L.top + LUA_MINSTACK;
+ lua_assert(ci.top <= L.stack_last);
ci.callstatus = 0;
- if (L.hookmask & defs.LUA_MASKCALL)
- luaD_hook(L, defs.LUA_HOOKCALL, -1);
+ if (L.hookmask & LUA_MASKCALL)
+ luaD_hook(L, LUA_HOOKCALL, -1);
let n = f(L); /* do the actual call */
-
- assert(typeof n == "number" && n >= 0 && (n|0) === n, "invalid return value from JS function (expected integer)");
- assert(n < L.top - L.ci.funcOff, "not enough elements in the stack");
+ if (typeof n !== "number" || n < 0 || (n|0) !== n)
+ throw Error("invalid return value from JS function (expected integer)");
+ lapi.api_checknelems(L, n);
luaD_poscall(L, ci, L.top - n, n);
return true;
}
- case CT.LUA_TLCL: {
+ case LUA_TLCL: {
let base;
let p = func.value.p;
let n = L.top - off - 1;
@@ -159,7 +185,7 @@ const luaD_precall = function(L, off, nresults) {
base = adjust_varargs(L, p, n);
} else {
for (; n < p.numparams; n++)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null); // complete missing arguments
+ L.stack[L.top++] = new lobject.TValue(LUA_TNIL, null); // complete missing arguments
base = off + 1;
}
@@ -173,7 +199,7 @@ const luaD_precall = function(L, off, nresults) {
ci.l_code = p.code;
ci.l_savedpc = 0;
ci.callstatus = lstate.CIST_LUA;
- if (L.hookmask & defs.LUA_MASKCALL)
+ if (L.hookmask & LUA_MASKCALL)
callhook(L, ci);
return false;
}
@@ -187,9 +213,9 @@ const luaD_precall = function(L, off, nresults) {
const luaD_poscall = function(L, ci, firstResult, nres) {
let wanted = ci.nresults;
- if (L.hookmask & (defs.LUA_MASKRET | defs.LUA_MASKLINE)) {
- if (L.hookmask & defs.LUA_MASKRET)
- luaD_hook(L, defs.LUA_HOOKRET, -1);
+ if (L.hookmask & (LUA_MASKRET | LUA_MASKLINE)) {
+ if (L.hookmask & LUA_MASKRET)
+ luaD_hook(L, LUA_HOOKRET, -1);
L.oldpc = ci.previous.l_savedpc; /* 'oldpc' for caller function */
}
@@ -211,7 +237,7 @@ const moveresults = function(L, firstResult, res, nres, wanted) {
}
break;
}
- case defs.LUA_MULTRET: {
+ case LUA_MULTRET: {
for (let i = 0; i < nres; i++)
lobject.setobjs2s(L, res + i, firstResult + i);
for (let i=L.top; i>=(res + nres); i--)
@@ -229,7 +255,7 @@ const moveresults = function(L, firstResult, res, nres, wanted) {
lobject.setobjs2s(L, res + i, firstResult + i);
for (; i < wanted; i++) {
if (res+i >= L.top)
- L.stack[res + i] = new lobject.TValue(CT.LUAT_NIL, null);
+ L.stack[res + i] = new lobject.TValue(LUA_TNIL, null);
else
L.stack[res + i].setnilvalue();
}
@@ -255,17 +281,17 @@ const luaD_hook = function(L, event, line) {
let ci = L.ci;
let top = L.top;
let ci_top = ci.top;
- let ar = new defs.lua_Debug();
+ let ar = new lua_Debug();
ar.event = event;
ar.currentline = line;
ar.i_ci = ci;
- luaD_checkstack(L, defs.LUA_MINSTACK); /* ensure minimum stack size */
- ci.top = L.top + defs.LUA_MINSTACK;
- assert(ci.top <= L.stack_last);
+ luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
+ ci.top = L.top + LUA_MINSTACK;
+ lua_assert(ci.top <= L.stack_last);
L.allowhook = 0; /* cannot call hooks inside a hook */
ci.callstatus |= lstate.CIST_HOOKED;
hook(L, ar);
- assert(!L.allowhook);
+ lua_assert(!L.allowhook);
L.allowhook = 1;
ci.top = ci_top;
adjust_top(L, top);
@@ -274,12 +300,12 @@ const luaD_hook = function(L, event, line) {
};
const callhook = function(L, ci) {
- let hook = defs.LUA_HOOKCALL;
+ let hook = LUA_HOOKCALL;
ci.l_savedpc++; /* hooks assume 'pc' is already incremented */
if ((ci.previous.callstatus & lstate.CIST_LUA) &&
ci.previous.l_code[ci.previous.l_savedpc - 1].opcode == lopcodes.OpCodesI.OP_TAILCALL) {
ci.callstatus |= lstate.CIST_TAIL;
- hook = defs.LUA_HOOKTAILCALL;
+ hook = LUA_HOOKTAILCALL;
}
luaD_hook(L, hook, -1);
ci.l_savedpc--; /* correct 'pc' */
@@ -298,7 +324,7 @@ const adjust_varargs = function(L, p, actual) {
}
for (; i < nfixargs; i++)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+ L.stack[L.top++] = new lobject.TValue(LUA_TNIL, null);
return base;
};
@@ -306,7 +332,7 @@ const adjust_varargs = function(L, p, actual) {
const tryfuncTM = function(L, off, func) {
let tm = ltm.luaT_gettmbyobj(L, func, ltm.TMS.TM_CALL);
if (!tm.ttisfunction(tm))
- ldebug.luaG_typeerror(L, func, defs.to_luastring("call", true));
+ ldebug.luaG_typeerror(L, func, to_luastring("call", true));
/* Open a hole inside the stack at 'func' */
lobject.pushobj2s(L, L.stack[L.top-1]); /* push top of stack again */
for (let p = L.top-2; p > off; p--)
@@ -322,10 +348,10 @@ const tryfuncTM = function(L, off, func) {
** allow overflow handling to work)
*/
const stackerror = function(L) {
- if (L.nCcalls === llimits.LUAI_MAXCCALLS)
- ldebug.luaG_runerror(L, defs.to_luastring("JS stack overflow", true));
- else if (L.nCcalls >= llimits.LUAI_MAXCCALLS + (llimits.LUAI_MAXCCALLS >> 3))
- luaD_throw(L, TS.LUA_ERRERR); /* error while handing stack error */
+ if (L.nCcalls === LUAI_MAXCCALLS)
+ ldebug.luaG_runerror(L, to_luastring("JS stack overflow", true));
+ else if (L.nCcalls >= LUAI_MAXCCALLS + (LUAI_MAXCCALLS >> 3))
+ luaD_throw(L, LUA_ERRERR); /* error while handing stack error */
};
/*
@@ -335,7 +361,7 @@ const stackerror = function(L) {
** function position.
*/
const luaD_call = function(L, off, nResults) {
- if (++L.nCcalls >= llimits.LUAI_MAXCCALLS)
+ if (++L.nCcalls >= LUAI_MAXCCALLS)
stackerror(L);
if (!luaD_precall(L, off, nResults))
lvm.luaV_execute(L);
@@ -367,8 +393,8 @@ const luaD_throw = function(L, errcode) {
const luaD_rawrunprotected = function(L, f, ud) {
let oldnCcalls = L.nCcalls;
- let lj = { // TODO: necessary when using try/catch ? (ldo.c:47-52)
- status: TS.LUA_OK,
+ let lj = {
+ status: LUA_OK,
previous: L.errorJmp /* chain new error handler */
};
L.errorJmp = lj;
@@ -376,13 +402,13 @@ const luaD_rawrunprotected = function(L, f, ud) {
try {
f(L, ud);
} catch (e) {
- if (lj.status === TS.LUA_OK) {
+ if (lj.status === LUA_OK) {
/* error was not thrown via luaD_throw, i.e. it is a JS error */
/* run user error handler (if it exists) */
let atnativeerror = L.l_G.atnativeerror;
if (atnativeerror) {
try {
- lj.status = TS.LUA_OK;
+ lj.status = LUA_OK;
lapi.lua_pushcfunction(L, atnativeerror);
lapi.lua_pushlightuserdata(L, e);
@@ -397,9 +423,9 @@ const luaD_rawrunprotected = function(L, f, ud) {
luaD_callnoyield(L, L.top - 2, 1);
}
- lj.status = TS.LUA_ERRRUN;
+ lj.status = LUA_ERRRUN;
} catch(e2) {
- if (lj.status === TS.LUA_OK) {
+ if (lj.status === LUA_OK) {
/* also failed */
lj.status = -1;
}
@@ -425,21 +451,21 @@ const finishCcall = function(L, status) {
let ci = L.ci;
/* must have a continuation and must be able to call it */
- assert(ci.c_k !== null && L.nny === 0);
+ lua_assert(ci.c_k !== null && L.nny === 0);
/* error status can only happen in a protected call */
- assert(ci.callstatus & lstate.CIST_YPCALL || status === TS.LUA_YIELD);
+ lua_assert(ci.callstatus & lstate.CIST_YPCALL || status === LUA_YIELD);
- if (ci.callstatus & TS.CIST_YPCALL) { /* was inside a pcall? */
- ci.callstatus &= ~TS.CIST_YPCALL; /* continuation is also inside it */
+ if (ci.callstatus & lstate.CIST_YPCALL) { /* was inside a pcall? */
+ ci.callstatus &= ~lstate.CIST_YPCALL; /* continuation is also inside it */
L.errfunc = ci.c_old_errfunc; /* with the same error function */
}
/* finish 'lua_callk'/'lua_pcall'; CIST_YPCALL and 'errfunc' already
handled */
- if (ci.nresults === defs.LUA_MULTRET && L.ci.top < L.top) L.ci.top = L.top;
+ if (ci.nresults === LUA_MULTRET && L.ci.top < L.top) L.ci.top = L.top;
let c_k = ci.c_k; /* don't want to call as method */
let n = c_k(L, status, ci.c_ctx); /* call continuation function */
- assert(n < (L.top - L.ci.funcOff), "not enough elements in the stack");
+ lapi.api_checknelems(L, n);
luaD_poscall(L, ci, L.top - n, n); /* finish 'luaD_precall' */
};
@@ -457,7 +483,7 @@ const unroll = function(L, ud) {
while (L.ci !== L.base_ci) { /* something in the stack */
if (!(L.ci.callstatus & lstate.CIST_LUA)) /* C function? */
- finishCcall(L, TS.LUA_YIELD); /* complete its execution */
+ finishCcall(L, LUA_YIELD); /* complete its execution */
else { /* Lua function */
lvm.luaV_finishOp(L); /* finish interrupted instruction */
lvm.luaV_execute(L); /* execute down to higher C 'boundary' */
@@ -504,17 +530,17 @@ const recover = function(L, status) {
** coroutine error handler and should not kill the coroutine.)
*/
const resume_error = function(L, msg, narg) {
- let ts = lstring.luaS_newliteral(L, msg);
+ let ts = luaS_newliteral(L, msg);
if (narg === 0) {
lobject.pushsvalue2s(L, ts);
- assert(L.top <= L.ci.top, "stack overflow");
+ api_check(L, L.top <= L.ci.top, "stack overflow");
} else {
/* remove args from the stack */
for (let i=1; i<narg; i++)
delete L.stack[--L.top];
lobject.setsvalue2s(L, L.top-1, ts); /* push error message */
}
- return TS.LUA_ERRRUN;
+ return LUA_ERRRUN;
};
/*
@@ -527,12 +553,12 @@ const resume_error = function(L, msg, narg) {
const resume = function(L, n) {
let firstArg = L.top - n; /* first argument */
let ci = L.ci;
- if (L.status === TS.LUA_OK) { /* starting a coroutine? */
- if (!luaD_precall(L, firstArg - 1, defs.LUA_MULTRET)) /* Lua function? */
+ if (L.status === LUA_OK) { /* starting a coroutine? */
+ if (!luaD_precall(L, firstArg - 1, LUA_MULTRET)) /* Lua function? */
lvm.luaV_execute(L); /* call it */
} else { /* resuming from previous yield */
- assert(L.status === TS.LUA_YIELD);
- L.status = TS.LUA_OK; /* mark that it is running (again) */
+ lua_assert(L.status === LUA_YIELD);
+ L.status = LUA_OK; /* mark that it is running (again) */
ci.funcOff = ci.extra;
ci.func = L.stack[ci.funcOff];
@@ -540,8 +566,8 @@ const resume = function(L, n) {
lvm.luaV_execute(L); /* just continue running Lua code */
else { /* 'common' yield */
if (ci.c_k !== null) { /* does it have a continuation function? */
- n = ci.c_k(L, TS.LUA_YIELD, ci.c_ctx); /* call continuation */
- assert(n < (L.top - L.ci.funcOff), "not enough elements in the stack");
+ n = ci.c_k(L, LUA_YIELD, ci.c_ctx); /* call continuation */
+ lapi.api_checknelems(L, n);
firstArg = L.top - n; /* yield results come from continuation */
}
@@ -555,41 +581,40 @@ const resume = function(L, n) {
const lua_resume = function(L, from, nargs) {
let oldnny = L.nny; /* save "number of non-yieldable" calls */
- if (L.status === TS.LUA_OK) { /* may be starting a coroutine */
+ if (L.status === LUA_OK) { /* may be starting a coroutine */
if (L.ci !== L.base_ci) /* not in base level? */
return resume_error(L, "cannot resume non-suspended coroutine", nargs);
- } else if (L.status !== TS.LUA_YIELD)
+ } else if (L.status !== LUA_YIELD)
return resume_error(L, "cannot resume dead coroutine", nargs);
L.nCcalls = from ? from.nCcalls + 1 : 1;
- if (L.nCcalls >= llimits.LUAI_MAXCCALLS)
+ if (L.nCcalls >= LUAI_MAXCCALLS)
return resume_error(L, "JS stack overflow", nargs);
L.nny = 0; /* allow yields */
- assert((L.status === TS.LUA_OK ? nargs + 1: nargs) < (L.top - L.ci.funcOff),
- "not enough elements in the stack");
+ lapi.api_checknelems(L, L.status === LUA_OK ? nargs + 1: nargs);
let status = luaD_rawrunprotected(L, resume, nargs);
if (status === -1) /* error calling 'lua_resume'? */
- status = TS.LUA_ERRRUN;
+ status = LUA_ERRRUN;
else { /* continue running after recoverable errors */
- while (status > TS.LUA_YIELD && recover(L, status)) {
+ while (status > LUA_YIELD && recover(L, status)) {
/* unroll continuation */
status = luaD_rawrunprotected(L, unroll, status);
}
- if (status > TS.LUA_YIELD) { /* unrecoverable error? */
+ if (status > LUA_YIELD) { /* unrecoverable error? */
L.status = status; /* mark thread as 'dead' */
seterrorobj(L, status, L.top); /* push error message */
L.ci.top = L.top;
} else
- assert(status === L.status); /* normal end or yield */
+ lua_assert(status === L.status); /* normal end or yield */
}
L.nny = oldnny; /* restore 'nny' */
L.nCcalls--;
- assert(L.nCcalls === (from ? from.nCcalls : 0));
+ lua_assert(L.nCcalls === (from ? from.nCcalls : 0));
return status;
};
@@ -599,29 +624,29 @@ const lua_isyieldable = function(L) {
const lua_yieldk = function(L, nresults, ctx, k) {
let ci = L.ci;
- assert(nresults < (L.top - L.ci.funcOff), "not enough elements in the stack");
+ lapi.api_checknelems(L, nresults);
if (L.nny > 0) {
if (L !== L.l_G.mainthread)
- ldebug.luaG_runerror(L, defs.to_luastring("attempt to yield across a JS-call boundary", true));
+ ldebug.luaG_runerror(L, to_luastring("attempt to yield across a JS-call boundary", true));
else
- ldebug.luaG_runerror(L, defs.to_luastring("attempt to yield from outside a coroutine", true));
+ ldebug.luaG_runerror(L, to_luastring("attempt to yield from outside a coroutine", true));
}
- L.status = TS.LUA_YIELD;
+ L.status = LUA_YIELD;
ci.extra = ci.funcOff; /* save current 'func' */
if (ci.callstatus & lstate.CIST_LUA) /* inside a hook? */
- assert(k === null, "hooks cannot continue after yielding");
+ api_check(L, k === null, "hooks cannot continue after yielding");
else {
ci.c_k = k;
if (k !== null) /* is there a continuation? */
ci.c_ctx = ctx; /* save context */
ci.funcOff = L.top - nresults - 1; /* protect stack below results */
ci.func = L.stack[ci.funcOff];
- luaD_throw(L, TS.LUA_YIELD);
+ luaD_throw(L, LUA_YIELD);
}
- assert(ci.callstatus & lstate.CIST_HOOKED); /* must be inside a hook */
+ lua_assert(ci.callstatus & lstate.CIST_HOOKED); /* must be inside a hook */
return 0; /* return to 'luaD_hook' */
};
@@ -638,7 +663,7 @@ const luaD_pcall = function(L, func, u, old_top, ef) {
let status = luaD_rawrunprotected(L, func, u);
- if (status !== TS.LUA_OK) {
+ if (status !== LUA_OK) {
lfunc.luaF_close(L, old_top);
seterrorobj(L, status, old_top);
L.ci = old_ci;
@@ -667,7 +692,7 @@ const luaD_callnoyield = function(L, off, nResults) {
class SParser {
constructor(z, name, mode) { /* data to 'f_parser' */
this.z = z;
- this.buff = new lzio.MBuffer(); /* dynamic structure used by the scanner */
+ this.buff = new MBuffer(); /* dynamic structure used by the scanner */
this.dyd = new lparser.Dyndata(); /* dynamic structures used by the parser */
this.mode = mode;
this.name = name;
@@ -675,25 +700,25 @@ class SParser {
}
const checkmode = function(L, mode, x) {
- if (mode && mode.indexOf(x[0]) === -1) {
+ if (mode && luastring_indexOf(mode, x[0]) === -1) {
lobject.luaO_pushfstring(L,
- defs.to_luastring("attempt to load a %s chunk (mode is '%s')"), x, mode);
- luaD_throw(L, TS.LUA_ERRSYNTAX);
+ to_luastring("attempt to load a %s chunk (mode is '%s')"), x, mode);
+ luaD_throw(L, LUA_ERRSYNTAX);
}
};
const f_parser = function(L, p) {
let cl;
let c = p.z.zgetc(); /* read first character */
- if (c === defs.LUA_SIGNATURE.charCodeAt(0)) {
- checkmode(L, p.mode, defs.to_luastring("binary", true));
+ if (c === LUA_SIGNATURE[0]) {
+ checkmode(L, p.mode, to_luastring("binary", true));
cl = lundump.luaU_undump(L, p.z, p.name);
} else {
- checkmode(L, p.mode, defs.to_luastring("text", true));
+ checkmode(L, p.mode, to_luastring("text", true));
cl = lparser.luaY_parser(L, p.z, p.buff, p.dyd, p.name, c);
}
- assert(cl.nupvalues === cl.p.upvalues.length);
+ lua_assert(cl.nupvalues === cl.p.upvalues.length);
lfunc.luaF_initupvals(L, cl);
};