private void OnNodeDoubleClick(object S, TreeNodeMouseClickEventArgs E) { LuaStateViewer.BeginUpdate(); E.Node.Nodes.Clear(); List <string> FullPath = new List <string>(); GetFullPath(FullPath, E.Node); L.GetTable(GLua.LUA_GLOBALSINDEX); for (int i = 0; i < FullPath.Count; i++) { L.GetField(-1, FullPath[i]); L.Remove(-2); } if (L.GetLuaType() == LuaType.Table) { L.PushNil(); while (L.Next(-2) != 0) { E.Node.Nodes.Add(L.LuaBase.GetString(-2)); L.Pop(); } } LuaStateViewer.EndUpdate(); }
public Color(GLua gLua, Int32 IStackPos) { Boolean B = gLua.Lock(); gLua.GetField(IStackPos, "r"); this.R = (Byte)gLua.LuaBase.GetNumber(-1); gLua.GetField(IStackPos, "g"); this.G = (Byte)gLua.LuaBase.GetNumber(-1); gLua.GetField(IStackPos, "b"); this.B = (Byte)gLua.LuaBase.GetNumber(-1); gLua.GetField(IStackPos, "a"); this.A = (Byte)gLua.LuaBase.GetNumber(-1); gLua.Pop(4); if (B) { gLua.UnLock(); } }
public static int Open(ref lua_State state) { GLua = GLua.Get(state); GLua.CreateTable(); GLua.Push(new Func <string, object>((string str) => { GLua.Push <string>("hello there"); GLua.Call(1, 2); Console.WriteLine(GLua.Get <string>(5)); GLua.Pop(); GLua.Push <string>("hello there"); GLua.Call(1, 2); Console.WriteLine(GLua.Get <string>(5)); return(0); })); GLua.SetField(-2, "test"); GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => { int res = instances.Count; try { instances.Add(NodeInstance.InstantiateSync(path, name, boundObjectAmout)); return(res); } catch (Exception e) { return(e.ToString()); } })); GLua.SetField(-2, "instantiateSync"); GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => { int res = instances.Count; NodeInstance.InstantiateAsync(path, name, boundObjectAmout).ContinueWith(taskResult => { if (taskResult.IsFaulted) { newInstancesExceptionsAsync.Add(res, string.Join(",", taskResult.Exception.InnerExceptions.Select(x => x.ToString()).ToArray())); } else { newInstancesAsync.Add(res, taskResult.Result); } }); return(res); })); GLua.SetField(-2, "instantiateAsync"); GLua.Push(new Func <int, bool>((int ptr) => { if (newInstancesAsync.ContainsKey(ptr)) { newInstancesAsync.Remove(ptr); return(true); } return(false); })); GLua.SetField(-2, "checkForNewAsyncInstances"); GLua.Push(new Func <int, object>((int ptr) => { if (newInstancesExceptionsAsync.ContainsKey(ptr)) { string str = newInstancesExceptionsAsync[ptr]; newInstancesExceptionsAsync.Remove(ptr); return(str); } return(false); })); GLua.SetField(-2, "checkForNewAsyncInstancesExceptions"); GLua.Push(new Func <int, string>((int instance) => { return(JsonConvert.SerializeObject(instances[instance].Methods)); })); GLua.SetField(-2, "getInstanceMethods"); GLua.Push(new Func <int, string, string, string>((int instance, string funcName, string args) => { Func <object> getHandler = new Func <object>(() => { GLua.Push <string>("hello there"); GLua.Call(1, 2); Console.WriteLine(GLua.Get <string>(5)); GLua.Pop(); return(0); }); try { object result = instances[instance].Call(funcName, JsonConvert.DeserializeObject <object[]>(args)); if (result == null) { return(null); } return(JsonConvert.SerializeObject(result)); } catch (Exception e) { Console.WriteLine(e); return("Error: " + e.Message); } })); GLua.SetField(-2, "callInstanceMethod"); GLua.Push(new Func <int, object>((int instance) => { instances[instance] = null; return(null); })); GLua.SetField(-2, "removeInstance"); GLua.Push(new Func <int, object>((int instance) => { instances[instance] = null; return(null); })); GLua.SetField(-2, "getInstanceObject"); GLua.Push(new Func <int, object>((int instance) => { instances[instance] = null; return(null); })); GLua.SetField(-2, "removeInstance"); GLua.Push(new Func <double>(() => { return(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds); })); GLua.SetField(-2, "getUnixTime"); GLua.SetField(GLua.LUA_GLOBALSINDEX, WRAPPER_OBJECT_NAME); return(0); }