summaryrefslogtreecommitdiffstats
path: root/apps/plugins/lua/lparser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/lparser.c')
-rw-r--r--apps/plugins/lua/lparser.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/apps/plugins/lua/lparser.c b/apps/plugins/lua/lparser.c
index d002e96b86..bb08c51c0b 100644
--- a/apps/plugins/lua/lparser.c
+++ b/apps/plugins/lua/lparser.c
@@ -344,6 +344,11 @@ static void open_func (LexState *ls, FuncState *fs) {
fs->bl = NULL;
f->source = ls->source;
f->maxstacksize = 2; /* registers 0/1 are always valid */
+#ifdef LUA_OPTIMIZE_DEBUG
+ fs->lastline = 0;
+ fs->lastlineOffset = 0;
+ fs->lineinfoLastPC = -1;
+#endif
fs->h = luaH_new(L, 0, 0);
/* anchor table of constants and prototype (to avoid being collected) */
sethvalue2s(L, L->top, fs->h);
@@ -361,8 +366,14 @@ static void close_func (LexState *ls) {
luaK_ret(fs, 0, 0); /* final return */
luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
f->sizecode = fs->pc;
+#ifdef LUA_OPTIMIZE_DEBUG
+ f->packedlineinfo[fs->lastlineOffset+1]=0;
+ luaM_reallocvector(L, f->packedlineinfo, f->sizelineinfo,
+ fs->lastlineOffset+2, unsigned char);
+#else
luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
f->sizelineinfo = fs->pc;
+#endif
luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
f->sizek = fs->nk;
luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
@@ -379,6 +390,23 @@ static void close_func (LexState *ls) {
L->top -= 2; /* remove table and prototype from the stack */
}
+#ifdef LUA_OPTIMIZE_DEBUG
+static void compile_stripdebug(lua_State *L, Proto *f) {
+ int level;
+#ifdef LUA_OPTIMIZE_DEBUG_USER
+ lua_pushlightuserdata(L, &luaG_stripdebug);
+ lua_gettable(L, LUA_REGISTRYINDEX);
+ level = lua_isnil(L, -1) ? LUA_OPTIMIZE_DEBUG : lua_tointeger(L, -1);
+ lua_pop(L, 1);
+#else
+ level = LUA_OPTIMIZE_DEBUG;
+#endif
+
+ if (level > 1) {
+ luaG_stripdebug(L, f, level, 16);
+ }
+}
+#endif
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
struct LexState lexstate;
@@ -395,6 +423,9 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
check(&lexstate, TK_EOS);
close_func(&lexstate);
L->top--; /* remove 'name' from stack */
+#ifdef LUA_OPTIMIZE_DEBUG
+ compile_stripdebug(L, funcstate.f);
+#endif
lua_assert(funcstate.prev == NULL);
lua_assert(funcstate.f->nups == 0);
lua_assert(lexstate.fs == NULL);
@@ -402,7 +433,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
}
-
/*============================================================*/
/* GRAMMAR RULES */
/*============================================================*/