]>
git.r.bdr.sh - rbdr/pico-engine/blob - LuaDebugger.cpp
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
78 CLuaDebugger::CLuaDebugger (CLuaVirtualMachine
& vm
) : m_iCountMask (10), m_vm (vm
)
80 // Clear all current hooks
83 vm
.AttachDebugger (this);
84 lua_sethook ((lua_State
*) vm
, LuaHook
, 0, m_iCountMask
);
88 CLuaDebugger::~CLuaDebugger (void)
90 // Clear all current hooks
93 lua_sethook ((lua_State
*) m_vm
, LuaHook
, 0, m_iCountMask
);
97 void CLuaDebugger::SetHooksFlag (int iMask
)
100 lua_sethook ((lua_State
*) m_vm
, LuaHook
, iMask
, m_iCountMask
);
103 void CLuaDebugger::ErrorRun (int iErrorCode
)
108 printf ("LUA_ERRRUN\n");
111 printf ("LUA_ERRMEM\n");
114 printf ("LUA_ERRERR\n");
118 // Get the error string that appears on top of stack when a function
120 printf ("Error: %s\n", lua_tostring ((lua_State
*) m_vm
, -1));