fix coded debugger support

This commit is contained in:
dualface 2014-10-14 18:26:56 +08:00
parent 94757e7adb
commit 23781f7b92
3 changed files with 28 additions and 28 deletions

View File

@ -93,7 +93,6 @@ void startScript(string strDebugArg)
if (!strDebugArg.empty()) if (!strDebugArg.empty())
{ {
// open debugger.lua module // open debugger.lua module
luaopen_debugger(engine->getLuaStack()->getLuaState());
engine->executeString(strDebugArg.c_str()); engine->executeString(strDebugArg.c_str());
} }
cocos2d::log("debug args = %s", strDebugArg.c_str()); cocos2d::log("debug args = %s", strDebugArg.c_str());
@ -1221,6 +1220,7 @@ void initRuntime()
auto engine = LuaEngine::getInstance(); auto engine = LuaEngine::getInstance();
ScriptEngineManager::getInstance()->setScriptEngine(engine); ScriptEngineManager::getInstance()->setScriptEngine(engine);
register_runtime_override_function(engine->getLuaStack()->getLuaState()); register_runtime_override_function(engine->getLuaStack()->getLuaState());
luaopen_lua_debugger(engine->getLuaStack()->getLuaState());
static ConsoleCustomCommand *g_customCommand; static ConsoleCustomCommand *g_customCommand;
g_customCommand = new ConsoleCustomCommand(); g_customCommand = new ConsoleCustomCommand();

View File

@ -74,7 +74,7 @@ static const char *lua_m_debugger =
"-- * Break-on-error feature (break if an error is thrown and there is no pcall in stack to handle it).\n" "-- * Break-on-error feature (break if an error is thrown and there is no pcall in stack to handle it).\n"
"-- * Use new 5.2 facilities to provide informations about function (arguments names, vararg, ...)\n" "-- * Use new 5.2 facilities to provide informations about function (arguments names, vararg, ...)\n"
"-- * Allow to see ... content for vararg functions (5.2 only)\n" "-- * Allow to see ... content for vararg functions (5.2 only)\n"
"-- * Inspect LuaJIT C data (http://lua-users.org/lists/lua-l/2011-02/msg01012.html)-- /!\ This file is auto-generated. Do not alter manually /!\\n" "-- * Inspect LuaJIT C data (http://lua-users.org/lists/lua-l/2011-02/msg01012.html)-- /!\\ This file is auto-generated. Do not alter manually /!\\\n"
"\n" "\n"
"--------------------------------------------------------------------------------\n" "--------------------------------------------------------------------------------\n"
"-- Submodules body\n" "-- Submodules body\n"
@ -101,7 +101,7 @@ static const char *lua_m_debugger =
"function b64_wrap(src)\n" "function b64_wrap(src)\n"
" local t = {}\n" " local t = {}\n"
" local b64_src = mime.b64(src)\n" " local b64_src = mime.b64(src)\n"
" for i=1, #b64_src, 76 do t[#t+1] = b64_src:sub(i, i+75)..\"\r\n\" end\n" " for i=1, #b64_src, 76 do t[#t+1] = b64_src:sub(i, i+75)..\"\\r\\n\" end\n"
" return table.concat(t)\n" " return table.concat(t)\n"
"end\n" "end\n"
"\n" "\n"
@ -134,7 +134,7 @@ static const char *lua_m_debugger =
" b64 = function(data)\n" " b64 = function(data)\n"
" t = {}\n" " t = {}\n"
" local b64_data = apr.base64_encode(data)\n" " local b64_data = apr.base64_encode(data)\n"
" for i=1, #b64_data, 76 do t[#t+1] = b64_data:sub(i, i+75)..\"\r\n\" end\n" " for i=1, #b64_data, 76 do t[#t+1] = b64_data:sub(i, i+75)..\"\\r\\n\" end\n"
" return table.concat(t)\n" " return table.concat(t)\n"
" end,\n" " end,\n"
"\n" "\n"
@ -752,7 +752,7 @@ static const char *lua_m_debugger =
" local file, err = io.open(path)\n" " local file, err = io.open(path)\n"
" if not file then dbgp.error(100, err, { success = 0 }) end\n" " if not file then dbgp.error(100, err, { success = 0 }) end\n"
" -- Try to identify compiled files\n" " -- Try to identify compiled files\n"
" if file:read(1) == \"\033\" then dbgp.error(100, args.f..\" is bytecode\", { success = 0 }) end\n" " if file:read(1) == \"\\033\" then dbgp.error(100, args.f..\" is bytecode\", { success = 0 }) end\n"
" file:seek(\"set\", 0)\n" " file:seek(\"set\", 0)\n"
"\n" "\n"
"\n" "\n"
@ -765,11 +765,11 @@ static const char *lua_m_debugger =
" elseif currentline >= endline then break end\n" " elseif currentline >= endline then break end\n"
" end\n" " end\n"
" file:close()\n" " file:close()\n"
" srclines[#srclines + 1] = \"\" -- to add a trailing \n\n" " srclines[#srclines + 1] = \"\" -- to add a trailing \\n\n"
"\n" "\n"
" dbgp.send_xml(self.skt, { tag = \"response\",\n" " dbgp.send_xml(self.skt, { tag = \"response\",\n"
" attr = { command = \"source\", transaction_id = args.i, success = 1},\n" " attr = { command = \"source\", transaction_id = args.i, success = 1},\n"
" util.b64(table.concat(srclines, \"\n\")) })\n" " util.b64(table.concat(srclines, \"\\n\")) })\n"
"end\n" "end\n"
"\n" "\n"
"-- Factory for both stdout and stderr commands, change file descriptor in io\n" "-- Factory for both stdout and stderr commands, change file descriptor in io\n"
@ -864,13 +864,13 @@ static const char *lua_m_debugger =
"\n" "\n"
" -- debug only !!\n" " -- debug only !!\n"
" __tostring = function(self)\n" " __tostring = function(self)\n"
" local buf = { \"Locals: \n\" }\n" " local buf = { \"Locals: \\n\" }\n"
" for k,v in pairs(self[LOCAL][STORE]) do\n" " for k,v in pairs(self[LOCAL][STORE]) do\n"
" buf[#buf+1] = \"\t\"..tostring(k)..\"(\"..tostring(v)..\")=\"..tostring(self[LOCAL][k])..\"\n\"\n" " buf[#buf+1] = \"\\t\"..tostring(k)..\"(\"..tostring(v)..\")=\"..tostring(self[LOCAL][k])..\"\\n\"\n"
" end\n" " end\n"
" buf[#buf+1] = \"Upvalues: \n\"\n" " buf[#buf+1] = \"Upvalues: \\n\"\n"
" for k,v in pairs(self[UPVAL][STORE]) do\n" " for k,v in pairs(self[UPVAL][STORE]) do\n"
" buf[#buf+1] = \"\t\"..tostring(k)..\"(\"..tostring(v)..\")=\"..tostring(self[UPVAL][k])..\"\n\"\n" " buf[#buf+1] = \"\\t\"..tostring(k)..\"(\"..tostring(v)..\")=\"..tostring(self[UPVAL][k])..\"\\n\"\n"
" end\n" " end\n"
" return table.concat(buf)\n" " return table.concat(buf)\n"
" end,\n" " end,\n"
@ -1040,7 +1040,7 @@ static const char *lua_m_debugger =
" while true do\n" " while true do\n"
" local byte, err = skt:receive(1)\n" " local byte, err = skt:receive(1)\n"
" if not byte then return nil, err end\n" " if not byte then return nil, err end\n"
" if byte == \"\000\" then break end\n" " if byte == \"\\000\" then break end\n"
" size[#size+1] = byte\n" " size[#size+1] = byte\n"
" end\n" " end\n"
" return tconcat(size)\n" " return tconcat(size)\n"
@ -1109,9 +1109,9 @@ static const char *lua_m_debugger =
" if not resp.attr then resp.attr = {} end\n" " if not resp.attr then resp.attr = {} end\n"
" resp.attr.xmlns = \"urn:debugger_protocol_v1\"\n" " resp.attr.xmlns = \"urn:debugger_protocol_v1\"\n"
"\n" "\n"
" local data = '<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n'..M.lom2str(resp)\n" " local data = '<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\\n'..M.lom2str(resp)\n"
" util.log(\"DEBUG\", \"Send \" .. data)\n" " util.log(\"DEBUG\", \"Send \" .. data)\n"
" skt:send(tostring(#data)..\"\000\"..data..\"\000\")\n" " skt:send(tostring(#data)..\"\\000\"..data..\"\\000\")\n"
"end\n" "end\n"
"\n" "\n"
"--- Return an XML tag describing a debugger error, with an optional message\n" "--- Return an XML tag describing a debugger error, with an optional message\n"
@ -1326,8 +1326,8 @@ static const char *lua_m_debugger =
"end\n" "end\n"
"\n" "\n"
"M.inspectors.string = function(name, value, parent, fullname)\n" "M.inspectors.string = function(name, value, parent, fullname)\n"
" -- escape linebreaks as \n and not as \<0x0A> like %q does\n" " -- escape linebreaks as \\n and not as \\<0x0A> like %q does\n"
" return M.property(name, \"string\", sformat(\"%q\", value):gsub(\"\\\n\", \"\\n\"), parent, fullname)\n" " return M.property(name, \"string\", sformat(\"%q\", value):gsub(\"\\\\\\n\", \"\\\\n\"), parent, fullname)\n"
"end\n" "end\n"
"\n" "\n"
"M.inspectors[\"function\"] = function(name, value, parent, fullname)\n" "M.inspectors[\"function\"] = function(name, value, parent, fullname)\n"
@ -1337,7 +1337,7 @@ static const char *lua_m_debugger =
" -- try to create a fancy representation if possible\n" " -- try to create a fancy representation if possible\n"
" local repr = info.nparams and fancy_func_repr(value, info) or tostring(value)\n" " local repr = info.nparams and fancy_func_repr(value, info) or tostring(value)\n"
" if info.source:sub(1,1) == \"@\" then\n" " if info.source:sub(1,1) == \"@\" then\n"
" repr = repr .. \"\n\" .. platform.get_uri(\"@\" .. info.source) .. \"\n\" .. tostring(info.linedefined)\n" " repr = repr .. \"\\n\" .. platform.get_uri(\"@\" .. info.source) .. \"\\n\" .. tostring(info.linedefined)\n"
" end\n" " end\n"
" prop = M.property(name, \"function (Lua)\", repr, parent, fullname)\n" " prop = M.property(name, \"function (Lua)\", repr, parent, fullname)\n"
" else\n" " else\n"
@ -2296,13 +2296,13 @@ static const char *lua_m_debugger =
" M.to_path = function (parsed_url) return url.unescape(parsed_url.path) end\n" " M.to_path = function (parsed_url) return url.unescape(parsed_url.path) end\n"
" else\n" " else\n"
" -- Implementations for Windows, see UNIX versions for documentation.\n" " -- Implementations for Windows, see UNIX versions for documentation.\n"
" M.path_sep = \"\\\"\n" " M.path_sep = \"\\\\\"\n"
" M.is_path_absolute = function (path) return path:match(\"^%a:/\") end\n" " M.is_path_absolute = function (path) return path:match(\"^%a:/\") end\n"
" M.to_file_uri = function (path) return url.build{scheme=\"file\",authority=\"\", path=\"/\"..path} end\n" " M.to_file_uri = function (path) return url.build{scheme=\"file\",authority=\"\", path=\"/\"..path} end\n"
" M.to_path = function (parsed_url) return url.unescape(parsed_url.path):gsub(\"^/\", \"\") end\n" " M.to_path = function (parsed_url) return url.unescape(parsed_url.path):gsub(\"^/\", \"\") end\n"
"\n" "\n"
" local unixnormalize = M.normalize\n" " local unixnormalize = M.normalize\n"
" M.normalize = function(path) return unixnormalize(path:gsub(\"\\\",\"/\"):lower()) end\n" " M.normalize = function(path) return unixnormalize(path:gsub(\"\\\\\",\"/\"):lower()) end\n"
"\n" "\n"
" -- determine base dir\n" " -- determine base dir\n"
" local function getworkingdirectory()\n" " local function getworkingdirectory()\n"
@ -2507,7 +2507,7 @@ static const char *lua_m_debugger =
"function M.log(level, msg, ...)\n" "function M.log(level, msg, ...)\n"
" if (LEVELS[level] or -1) > LOG_LEVEL then return end\n" " if (LEVELS[level] or -1) > LOG_LEVEL then return end\n"
" if select(\"#\", ...) > 0 then msg = msg:format(...) end\n" " if select(\"#\", ...) > 0 then msg = msg:format(...) end\n"
" io.base.stderr:write(string.format(\"DEBUGGER\t%s\t%s\n\", level, msg))\n" " io.base.stderr:write(string.format(\"DEBUGGER\\t%s\\t%s\\n\", level, msg))\n"
"end\n" "end\n"
"\n" "\n"
"return M\n" "return M\n"
@ -2906,7 +2906,7 @@ static const char *lua_m_debugger =
"-- for i=1, select(\"#\", ...) do\n" "-- for i=1, select(\"#\", ...) do\n"
"-- buf[i] = tostring(buf[i])\n" "-- buf[i] = tostring(buf[i])\n"
"-- end\n" "-- end\n"
"-- io.stdout:write(table.concat(buf, \"\t\") .. \"\n\")\n" "-- io.stdout:write(table.concat(buf, \"\\t\") .. \"\\n\")\n"
"-- end\n" "-- end\n"
"\n" "\n"
"-- Actually change standard output file but still return the \"fake\" stdout\n" "-- Actually change standard output file but still return the \"fake\" stdout\n"
@ -2922,7 +2922,7 @@ static const char *lua_m_debugger =
" write = function(self, ...)\n" " write = function(self, ...)\n"
" local buf = {...}\n" " local buf = {...}\n"
" for i=1, select(\"#\", ...) do buf[i] = tostring(buf[i]) end\n" " for i=1, select(\"#\", ...) do buf[i] = tostring(buf[i]) end\n"
" buf = table.concat(buf):gsub(\"\n\", \"\r\n\")\n" " buf = table.concat(buf):gsub(\"\\n\", \"\\r\\n\")\n"
" dbgp.send_xml(self.skt, { tag = \"stream\", attr = { type=self.mode }, util.b64(buf) } )\n" " dbgp.send_xml(self.skt, { tag = \"stream\", attr = { type=self.mode }, util.b64(buf) } )\n"
" end,\n" " end,\n"
" flush = dummy,\n" " flush = dummy,\n"
@ -3489,7 +3489,7 @@ static luaL_Reg lua_debugger_modules[] = {
{NULL, NULL} {NULL, NULL}
}; };
void luaopen_debugger(lua_State* L) void luaopen_lua_debugger(lua_State* L)
{ {
luaL_Reg* lib = lua_debugger_modules; luaL_Reg* lib = lua_debugger_modules;
lua_getglobal(L, "package"); lua_getglobal(L, "package");

View File

@ -1,8 +1,8 @@
/* lua_debugger.h.h */ /* lua_debugger.h.h */
#ifndef __LUA_MODULES_6138519995EA0D10EABE8E26B195D5DB_H_ #ifndef __LUA_MODULES_865AA78CBE5B66EE51A8CB6690FEE443_H_
#define __LUA_MODULES_6138519995EA0D10EABE8E26B195D5DB_H_ #define __LUA_MODULES_865AA78CBE5B66EE51A8CB6690FEE443_H_
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -10,7 +10,7 @@ extern "C" {
#include "lua.h" #include "lua.h"
void luaopen_debugger(lua_State* L); void luaopen_lua_debugger(lua_State* L);
/* /*
int luaopen_lua_m_debugger(lua_State* L); int luaopen_lua_m_debugger(lua_State* L);
@ -20,4 +20,4 @@ int luaopen_lua_m_debugger(lua_State* L);
} }
#endif #endif
#endif /* __LUA_MODULES_6138519995EA0D10EABE8E26B195D5DB_H_ */ #endif /* __LUA_MODULES_865AA78CBE5B66EE51A8CB6690FEE443_H_ */