Ejemplo n.º 1
0
 static void DebugHook(object sender, NLua.Event.DebugHookEventArgs args)
 {
 }
Ejemplo n.º 2
0
 /// <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;
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
        /// <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;
        }
Ejemplo n.º 7
0
 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;
         }
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the LuaUtil class
 /// </summary>
 /// <param name="logger"></param>
 public LuaUtil(NLua.Lua lua)
 {
     LuaEnvironment = lua;
 }
Ejemplo n.º 9
0
        public string[] convertTableToSArray(NLua.LuaTable table)
        {
            tempStringArray = new string[table.Values.Count];

            table.Values.CopyTo(tempStringArray, 0);

            return tempStringArray;
        }
Ejemplo n.º 10
0
		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);
		}
Ejemplo n.º 11
0
        public int[] convertTableToIArray(NLua.LuaTable table)
        {
            tempIntArray = new string[table.Values.Count];

                table.Values.CopyTo(tempIntArray, 0);

            return Array.ConvertAll(tempIntArray, int.Parse);
        }
Ejemplo n.º 12
0
 public void createTable(string name, NLua.LuaTable values, NLua.LuaTable lengths)
 {
     Database.CreateTables(name, convertTableToSArray(values), convertTableToIArray(lengths));
 }
Ejemplo n.º 13
0
 /// <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;
 }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
 public LuaTableWrapper(LuaInterface.LuaTable luaTable)
 {
     this.luaTable = luaTable;
 }
Ejemplo n.º 17
-1
 /// <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;
 }