static void StartDebuggingWithOption(bool debugDebuggee = false) { if (Application.isPlaying) { var type = Type.GetType("lua.LuaBehaviour"); if (type == null) { type = Type.GetType("lua.LuaBehaviour, Assembly-CSharp-firstpass"); } Debug.Assert(type != null); var field = type.GetField("L", BindingFlags.Static | BindingFlags.NonPublic); var L = (Lua)field.GetValue(null); Debug.Assert(L != null); var top = Api.lua_gettop(L); try { Api.luaL_dostring(L, "return function()" + " local Debug = csharp.import('UnityEngine.Debug, UnityEngine')\n" + " local json = require 'json'\n"+ " local debuggee = require 'vscode-debuggee'\n"+ " local startResult, startType = debuggee.start(json, { dumpCommunication = " + (debugDebuggee ? "true" : "false") + "})\n" + " Debug.Log('start debuggee ' .. startType .. ' ' .. tostring(startResult))\n" + " return debuggee.poll\n" + "end"); L.Call(0, 2); if (debuggeePoll != null) { LuaBehaviour.debuggeePoll = null; debuggeePoll.Dispose(); debuggeePoll = null; } debuggeePoll = LuaFunction.MakeRefTo(L, -2); LuaBehaviour.debuggeePoll = delegate() { try { debuggeePoll.Invoke(); } catch (Exception e) { Debug.LogError("debug session is ended unexpected: " + e.Message); LuaBehaviour.debuggeePoll = null; debuggeePoll.Dispose(); debuggeePoll = null; } }; } catch (Exception e) { Debug.LogErrorFormat("Cannot start debuggee {0}", e.Message); } Api.lua_settop(L, top); } }
LuaFunction Cache(string name, bool renew = false, LuaFunction withFunc = null) { LuaFunction f = null; if (cached.TryGetValue(name, out f)) { if (!renew) { return(f); } // renew, dispose current if (f != null) { f.Dispose(); } if (withFunc != null) { cached[name] = withFunc; } } var L = CheckValid(); var top = Api.lua_gettop(L); Push(); if (Api.lua_getfield(L, -1, name) == Api.LUA_TFUNCTION) { f = LuaFunction.MakeRefTo(L, -1); } else { Config.LogError(string.Format("attempt to call a non-function '{0}' ", name)); } cached[name] = f; Api.lua_settop(L, top); return(f); }