public CozyLuaTable GetTable(string fullPath) { NLua.LuaTable table = mLua.GetTable(fullPath); if (table != null) { return(new CozyLuaTable(table)); } return(null); }
protected override void Initialized(object state) { base.Initialized(state); if (_ctx != null) { _ctx.Dispose(); } _ctx = new NLua.Lua(); _ctx.LoadCLRPackage(); _ctx.RegisterFunction("AddCommand", this, this.GetType().GetMethod("AddCommand")); _ctx.RegisterFunction("ArraySort", this, this.GetType().GetMethod("ArraySort")); //_ctx.RegisterFunction("HookBase", this, this.GetType().GetMethods() // .Where(x => x.Name == "HookBase" && x.GetParameters().Last().ParameterType == typeof(NLua.LuaFunction)) // .First()); //Access level enum _ctx.NewTable("AccessLevel"); var ac = _ctx.GetTable("AccessLevel"); foreach (var val in Enum.GetValues(typeof(TDSM.API.Command.AccessLevel))) { var al = (TDSM.API.Command.AccessLevel)val; ac[al.ToString()] = (int)val; } _ctx.DoFile(Path); CallSelf("Initialized"); var plg = _ctx["export"] as NLua.LuaTable; if (plg != null) { this.TDSMBuild = (int)(double)plg["TDSMBuild"]; this.Author = plg["Author"] as String; this.Description = plg["Description"] as String; this.Name = plg["Name"] as String; this.Version = plg["Version"] as String; IsValid = true; var hooks = plg["Hooks"] as NLua.LuaTable; if (hooks != null) { foreach (KeyValuePair <Object, Object> hookTarget in hooks) { var hook = hookTarget.Key as String; var hookPoint = PluginManager.GetHookPoint(hook); if (hookPoint != null) { var details = hookTarget.Value as NLua.LuaTable; var priority = (HookOrder)(details["Priority"] ?? HookOrder.NORMAL); //var priority = FindOrder(details["Priority"] as String); var del = _ctx.GetFunction(hookPoint.DelegateType, "export.Hooks." + hook + ".Call"); HookBase(hookPoint, priority, del); //TODO maybe fake an actual delegate as this is only used for registering or make a TDSM event info class } } } } }
//private Dictionary<object, object> private void itmMainFileOpenManual_Click(object sender, EventArgs e) { if (dlgOpenSavedVars.ShowDialog() == DialogResult.OK) { NLua.Lua loadedVars = new NLua.Lua(); try { loadedVars.DoFile(dlgOpenSavedVars.FileName); Dictionary <object, object> _elephantDB = loadedVars.GetTableDict(loadedVars.GetTable("ElephantDBPerChar")); Dictionary <object, object> profileKeys = loadedVars.GetTableDict((NLua.LuaTable)_elephantDB["profileKeys"]); //profileKeys[0] is null WHY?!?! how to get this value? //Hey dummy, use profileKeys.ElementAt(0) instead! MessageBox.Show(dlgOpenSavedVars.FileName + " loaded for " + profileKeys.First().Value + "!"); } catch (NLua.Exceptions.LuaException ex) { MessageBox.Show(ex.Message, "Error Parsing SavedVariables File", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }