]>
git.r.bdr.sh - rbdr/pico-engine/blob - LuaDebugger.cpp
18f39092950c09875f4404510b7a8e49002d3260
1 // ---------------------------------------------------------------------------
2 // FILE NAME : LuaDebugger.cpp
3 // ---------------------------------------------------------------------------
6 // Simple debugging routines
8 // ---------------------------------------------------------------------------
11 // AUTHOR : Richard Shephard
12 // ---------------------------------------------------------------------------
13 // LIBRARY INCLUDE FILES
14 #include "luadebugger.h"
15 // ---------------------------------------------------------------------------
17 // typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
18 static void LuaHookCall (lua_State
*lua
)
21 printf ("---- Call Stack ----\n");
22 // printf ("[Level] [Function] [# args] [@line] [src]\n");
27 for (int iLevel
= 0; lua_getstack (lua
, iLevel
, &ar
) != 0; ++iLevel
)
29 if (lua_getinfo (lua
, "Snlu", &ar
) != 0)
31 printf ("%d %s %s %d @%d %s\n", iLevel
, ar
.namewhat
, ar
.name
, ar
.nups
, ar
.linedefined
, ar
.short_src
);
36 static void LuaHookRet (lua_State
*lua
)
41 static void LuaHookLine (lua_State
*lua
)
44 lua_getstack (lua
, 0, &ar
);
47 if (lua_getinfo (lua
, "Sl", &ar
) != 0)
49 printf ("exe %s on line %d\n", ar
.short_src
, ar
.currentline
);
53 static void LuaHookCount (lua_State
*lua
)
58 static void LuaHook (lua_State
*lua
, lua_Debug
*ar
)
60 // Handover to the correct hook
79 CLuaDebugger::CLuaDebugger (CLuaVirtualMachine
& vm
) : m_iCountMask (10), m_vm (vm
)
81 // Clear all current hooks
84 vm
.AttachDebugger (this);
85 lua_sethook ((lua_State
*) vm
, LuaHook
, 0, m_iCountMask
);
89 CLuaDebugger::~CLuaDebugger (void)
91 // Clear all current hooks
94 lua_sethook ((lua_State
*) m_vm
, LuaHook
, 0, m_iCountMask
);
98 void CLuaDebugger::SetHooksFlag (int iMask
)
101 lua_sethook ((lua_State
*) m_vm
, LuaHook
, iMask
, m_iCountMask
);
104 void CLuaDebugger::ErrorRun (int iErrorCode
)
109 printf ("LUA_ERRRUN\n");
112 printf ("LUA_ERRMEM\n");
115 printf ("LUA_ERRERR\n");
119 // Get the error string that appears on top of stack when a function
121 printf ("Error: %s\n", lua_tostring ((lua_State
*) m_vm
, -1));