void DoCommand(string str) { LuaState luaState = LuaState.main; if (luaState == null) { return; } if (string.IsNullOrEmpty(str)) { return; } int index = str.IndexOf(" "); string cmd = str; string tail = ""; if (index > 0) { cmd = str.Substring(0, index).Trim().ToLower(); tail = str.Substring(index + 1); } if (cmd == "p") { if (tail == "") { return; } LuaFunction f = luaState.doString(COMMON_DEFINE + "return printExpr", "LuaConsole") as LuaFunction; f.call(tail); f.Dispose(); } else if (cmd == "dir") { if (tail == "") { return; } LuaFunction f = luaState.doString(COMMON_DEFINE + "return dirExpr", "LuaConsole") as LuaFunction; f.call(tail); f.Dispose(); } else { LuaFunction f = luaState.doString(COMMON_DEFINE + "return compile", "LuaConsole") as LuaFunction; f.call(str); f.Dispose(); } }
public static void BuildLua() { SLua.LuaState l = new SLua.LuaState(); foreach (string file in Directory.GetFiles(Path.GetFullPath(Application.dataPath), "*.lua", SearchOption.AllDirectories)) { if (file.StartsWith(Path.GetFullPath(Application.streamingAssetsPath))) { continue; } string output = file.Replace(Path.GetFullPath(Application.dataPath), ""); output = Application.streamingAssetsPath + output; output = Path.GetFullPath(output); //Debug.LogError(Path.GetDirectoryName(output)); Directory.CreateDirectory(Path.GetDirectoryName(output)); l.doString(string.Format(@" local f = io.open('{0}', 'wb') local s = io.open('{1}') f:write(string.dump(loadstring(s:read('*a'), '{1}'))) f:close() s:close() ", output.Replace(@"\", @"/"), file.Replace(@"\", @"/"))); } l.Dispose(); AssetDatabase.Refresh(); }
void onClientDisconnect() { state.doString("Slua.ldb.clearBreakPoint()"); client.Close(); client = null; Logger.Log("Debug session disconnected"); }
public static void reg(IntPtr l) { #if !LUA_5_3 && !SLUA_STANDALONE // lua implemented valuetype isn't faster than raw under non-jit. LuaState ls = LuaState.get(l); ls.doString(script, "ValueTypeScript"); #endif }
void Do(string tail, string type) { LuaState.printTrace = false; LuaFunction f = current.doString(COMMON_DEFINE + type, "LuaConsole") as LuaFunction; f.call(tail); f.Dispose(); LuaState.printTrace = true; }
void onClientDisconnect() { state.doString("Slua.ldb.clearBreakPoint()"); debugMode = false; client.Close(); client = null; LuaState.logDelegate -= addLog; LuaState.errorDelegate -= addError; Logger.Log("Debug session disconnected"); }
public static void reg(IntPtr l) { #if !LUA_5_3 && !SLUA_STANDALONE // lua implemented valuetype isn't faster than raw under non-jit. LuaState ls = LuaState.get(l); ls.regPushVar(typeof(UnityEngine.Vector2), (IntPtr L, object o) => { LuaObject.pushValue(L, (UnityEngine.Vector2)o); }); ls.regPushVar(typeof(UnityEngine.Vector3), (IntPtr L, object o) => { LuaObject.pushValue(L, (UnityEngine.Vector3)o); }); ls.regPushVar(typeof(UnityEngine.Vector4), (IntPtr L, object o) => { LuaObject.pushValue(L, (UnityEngine.Vector4)o); }); ls.regPushVar(typeof(UnityEngine.Quaternion), (IntPtr L, object o) => { LuaObject.pushValue(L, (UnityEngine.Quaternion)o); }); ls.regPushVar(typeof(UnityEngine.Color), (IntPtr L, object o) => { LuaObject.pushValue(L, (UnityEngine.Color)o); }); ls.doString(script, "ValueTypeScript"); #endif }
public object startDoString(string script) { if (script != null) { luaState.doString(script); LuaFunction func = (LuaFunction)luaState["main"]; if (func != null) { return(func.call()); } } return(null); }
void doCommand(string str) { LuaSvrGameObject lua = FindObjectOfType <LuaSvrGameObject>(); if (lua == null) { return; } LuaState luaState = lua.state; int index = str.IndexOf(" "); string cmd = str; if (index > 0) { cmd = str.Substring(0, index).Trim().ToLower(); } if (cmd == "reload") { // TODO } else if (cmd == "cls") { outputText = ""; } else { if (!string.IsNullOrEmpty(str)) { #if !CONSOLE_DEBUG var luaFunc = luaState.getFunction("Slua.ldb.printExpr"); if (luaFunc != null) { luaFunc.call(str); } else { consolePrint("do script failed"); } #else luaState.doString(str); #endif } } }
public static void init(IntPtr l) { string newindexfun = @" local getmetatable=getmetatable local rawget=rawget local error=error local type=type local function newindex(ud,k,v) local t=getmetatable(ud) repeat local h=rawget(t,k) if h then if h[2] then h[2](ud,v) return else error('property '..k..' is read only') end end t=rawget(t,'__parent') until t==nil error('can not find '..k) end return newindex "; string indexfun = @" local type=type local error=error local rawget=rawget local getmetatable=getmetatable local function index(ud,k) local t=getmetatable(ud) repeat local fun=rawget(t,k) local tp=type(fun) if tp=='function' then return fun elseif tp=='table' then local f=fun[1] if f then return f(ud) else error('property '..k..' is write only') end end t = rawget(t,'__parent') until t==nil error('Can not find '..k) end return index "; LuaState L = LuaState.get(l); newindex_func = (LuaFunction)L.doString(newindexfun); index_func = (LuaFunction)L.doString(indexfun); // object method LuaDLL.lua_createtable(l, 0, 4); addMember(l, ToString); addMember(l, GetHashCode); addMember(l, Equals); addMember(l, GetType); LuaDLL.lua_setfield(l, LuaIndexes.LUA_REGISTRYINDEX, "__luabaseobject"); LuaArray.init(l); LuaVarObject.init(l); LuaDLL.lua_newtable(l); LuaDLL.lua_setglobal(l, DelgateTable); setupPushVar(); }
public static void reg(IntPtr l) { LuaState L = LuaState.get(l); L.doString(script); }
public static void reg(IntPtr l) { LuaState ls = LuaState.get(l); ls.doString(script, "LuaSocketMini"); }