aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-10-01 16:17:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-10-01 16:17:51 -0300
commit7f9a32ad854d0c91a0ec231199933d536ecce3db (patch)
tree59ee9aec708e25eeb00f7c47c6ccd59508e09e7c
parentbc1b0733b808f02639ed79fff02f69f731636539 (diff)
downloadlua-7f9a32ad854d0c91a0ec231199933d536ecce3db.tar.gz
lua-7f9a32ad854d0c91a0ec231199933d536ecce3db.tar.bz2
lua-7f9a32ad854d0c91a0ec231199933d536ecce3db.zip
new function 'printcode'
-rw-r--r--ltests.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/ltests.c b/ltests.c
index 4388e1c9..b4518604 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.222 2017/06/27 18:32:49 roberto Exp roberto $ 2** $Id: ltests.c,v 2.223 2017/06/29 15:06:44 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -595,6 +595,22 @@ static int listcode (lua_State *L) {
595} 595}
596 596
597 597
598static int printcode (lua_State *L) {
599 int pc;
600 Proto *p;
601 luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
602 1, "Lua function expected");
603 p = getproto(obj_at(L, 1));
604 printf("maxstack: %d\n", p->maxstacksize);
605 printf("numparams: %d\n", p->numparams);
606 for (pc=0; pc<p->sizecode; pc++) {
607 char buff[100];
608 printf("%d\t%s\n", pc + 1, buildop(p, pc, buff));
609 }
610 return 0;
611}
612
613
598static int listk (lua_State *L) { 614static int listk (lua_State *L) {
599 Proto *p; 615 Proto *p;
600 int i; 616 int i;
@@ -1634,6 +1650,7 @@ static const struct luaL_Reg tests_funcs[] = {
1634 {"log2", log2_aux}, 1650 {"log2", log2_aux},
1635 {"limits", get_limits}, 1651 {"limits", get_limits},
1636 {"listcode", listcode}, 1652 {"listcode", listcode},
1653 {"printcode", printcode},
1637 {"listk", listk}, 1654 {"listk", listk},
1638 {"listlocals", listlocals}, 1655 {"listlocals", listlocals},
1639 {"loadlib", loadlib}, 1656 {"loadlib", loadlib},