From 7f9a32ad854d0c91a0ec231199933d536ecce3db Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sun, 1 Oct 2017 16:17:51 -0300 Subject: [PATCH] new function 'printcode' --- ltests.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ltests.c b/ltests.c index 4388e1c9..b4518604 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.222 2017/06/27 18:32:49 roberto Exp roberto $ +** $Id: ltests.c,v 2.223 2017/06/29 15:06:44 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -595,6 +595,22 @@ static int listcode (lua_State *L) { } +static int printcode (lua_State *L) { + int pc; + Proto *p; + luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), + 1, "Lua function expected"); + p = getproto(obj_at(L, 1)); + printf("maxstack: %d\n", p->maxstacksize); + printf("numparams: %d\n", p->numparams); + for (pc=0; pcsizecode; pc++) { + char buff[100]; + printf("%d\t%s\n", pc + 1, buildop(p, pc, buff)); + } + return 0; +} + + static int listk (lua_State *L) { Proto *p; int i; @@ -1634,6 +1650,7 @@ static const struct luaL_Reg tests_funcs[] = { {"log2", log2_aux}, {"limits", get_limits}, {"listcode", listcode}, + {"printcode", printcode}, {"listk", listk}, {"listlocals", listlocals}, {"loadlib", loadlib},