static void DebugHook(object sender, NLua.Event.DebugHookEventArgs args) { }
/// <summary> /// Initializes a new instance of the LuaPluginLoader class /// </summary> /// <param name="lua"></param> /// <param name="luaExtension"></param> public LuaPluginLoader(NLua.Lua lua, LuaExtension luaExtension) { LuaEnvironment = lua; LuaExtension = luaExtension; }
public LuaScriptManager( NLua.Lua luaState ) { _lua = luaState; }
/// <summary> /// Register API functions with the Lua instance specified. /// </summary> /// <param name="lua">Lua instance</param> public void RegisterFunctions(NLua.Lua lua) { lua["Settings"] = _userSettings; lua["Application"] = _mainForm; }
/// <summary> /// Translates a single object from its C# form to its Lua form /// </summary> /// <param name="lua"></param> /// <param name="item"></param> /// <returns></returns> private static object TranslateConfigItemToLuaItem(NLua.Lua lua, object item) { // Switch on the object type if (item is int || item is float || item is double) return Convert.ToDouble(item); else if (item is bool) return Convert.ToBoolean(item); else if (item is string) return item; else if (item is List<object>) { lua.NewTable("tmplist"); LuaTable tbl = lua["tmplist"] as LuaTable; lua["tmplist"] = null; List<object> list = item as List<object>; for (int i = 0; i < list.Count; i++) { tbl[i + 1] = TranslateConfigItemToLuaItem(lua, list[i]); } return tbl; } else if (item is Dictionary<string, object>) { lua.NewTable("tmpdict"); LuaTable tbl = lua["tmpdict"] as LuaTable; lua["tmpdict"] = null; Dictionary<string, object> dict = item as Dictionary<string, object>; foreach (var pair in dict) { CreateFullPath(pair.Key, tbl, lua); tbl[pair.Key] = TranslateConfigItemToLuaItem(lua, pair.Value); } return tbl; } else return null; }
/// <summary> /// Copies and translates the contents of the specified config file into the specified table /// </summary> /// <param name="config"></param> /// <param name="lua"></param> /// <returns></returns> public static LuaTable TableFromConfig(DynamicConfigFile config, NLua.Lua lua) { // Make a table lua.NewTable("tmp"); LuaTable tbl = lua["tmp"] as LuaTable; lua["tmp"] = null; // Loop each item in config foreach (var pair in config) { CreateFullPath(pair.Key, tbl, lua); // Translate and set on table tbl[pair.Key] = TranslateConfigItemToLuaItem(lua, pair.Value); } // Return return tbl; }
private static void CreateFullPath(string fullPath, LuaTable tbl, NLua.Lua lua) { var path = fullPath.Split('.'); for (var i = 0; i < path.Length - 1; i++) { if (tbl[path[i]] == null) { lua.NewTable("tmp"); var table = (LuaTable) lua["tmp"]; tbl[path[i]] = table; lua["tmp"] = null; tbl = table; } } }
/// <summary> /// Initializes a new instance of the LuaUtil class /// </summary> /// <param name="logger"></param> public LuaUtil(NLua.Lua lua) { LuaEnvironment = lua; }
public string[] convertTableToSArray(NLua.LuaTable table) { tempStringArray = new string[table.Values.Count]; table.Values.CopyTo(tempStringArray, 0); return tempStringArray; }
public LHTable(NLua.LuaTable Parent, string Key){ Data = Parent[Key] as LuaTable; Count = Data.Keys.Count; Keys = new string[Count]; Data.Keys.CopyTo(Keys, 0); }
public int[] convertTableToIArray(NLua.LuaTable table) { tempIntArray = new string[table.Values.Count]; table.Values.CopyTo(tempIntArray, 0); return Array.ConvertAll(tempIntArray, int.Parse); }
public void createTable(string name, NLua.LuaTable values, NLua.LuaTable lengths) { Database.CreateTables(name, convertTableToSArray(values), convertTableToIArray(lengths)); }
/// <summary> /// Registers this package to the given Lua state. /// </summary> /// <param name="state"></param> public void RegisterPackage(NLua.Lua state) { NLua.LuaLib.LuaNewTable(state.GetState()); this.m_FunctionDelegates.ForEach(f => state.RegisterTableFunction(f.Key, f.Value)); NLua.LuaLib.LuaSetGlobal(state.GetState(), "file"); }
public CommandInfo LuaCall(NLua.LuaFunction callback) { LuaCallback = callback; return this; }
public static string FormatException(NLua.Exceptions.LuaException e) { string source = (string.IsNullOrEmpty(e.Source)) ? "<no source>" : e.Source.Substring(0, e.Source.Length - 2); return string.Format("{0}\nLua (at {2})", e.Message, string.Empty, source); }
public LuaTableWrapper(LuaInterface.LuaTable luaTable) { this.luaTable = luaTable; }
/// <summary> /// Initializes a new instance of the LuaDatafile class /// </summary> /// <param name="lua"></param> public LuaDatafile(NLua.Lua lua) { datafilemap = new Dictionary<DynamicConfigFile, LuaTable>(); LuaEnvironment = lua; }