コード例 #1
1
ファイル: LuaExtension.cs プロジェクト: RuanPitout88/Oxide
        /// <summary>
        /// Initializes the Lua environment
        /// </summary>
        private void InitializeLua()
        {
            // Create the Lua environment
            LuaEnvironment = new NLua.Lua();

            // Filter useless or potentially malicious libraries/functions
            LuaEnvironment["os"] = null;
            LuaEnvironment["io"] = null;
            LuaEnvironment["require"] = null;
            LuaEnvironment["dofile"] = null;
            LuaEnvironment["package"] = null;
            LuaEnvironment["luanet"] = null;
            LuaEnvironment["load"] = null;

            // Read util methods
            setmetatable = LuaEnvironment["setmetatable"] as LuaFunction;

            // Create metatables
            //Type mytype = GetType();
            LuaEnvironment.NewTable("tmp");
            overloadselectormeta = LuaEnvironment["tmp"] as LuaTable;
            //LuaEnvironment.RegisterFunction("tmp.__index", mytype.GetMethod("FindOverload", BindingFlags.Public | BindingFlags.Static));
            LuaEnvironment.NewTable("tmp");
            // Ideally I'd like for this to be implemented C# side, but using C#-bound methods as metamethods seems dodgy
            LuaEnvironment.LoadString(
            @"function tmp:__index( key )
            local sftbl = rawget( self, '_sftbl' )
            local field = sftbl[ key ]
            if (field) then return field:GetValue( nil ) end
            end
            function tmp:__newindex( key, value )
            local sftbl = rawget( self, '_sftbl' )
            local field = sftbl[ key ]
            if (field) then field:SetValue( nil, value ) end
            end
            ", "LuaExtension").Call();
            //LuaEnvironment.RegisterFunction("tmp.__index", mytype.GetMethod("ReadStaticProperty", BindingFlags.NonPublic | BindingFlags.Static));
            //LuaEnvironment.RegisterFunction("tmp.__newindex", mytype.GetMethod("WriteStaticProperty", BindingFlags.NonPublic | BindingFlags.Static));
            typetablemeta = LuaEnvironment["tmp"] as LuaTable;
            LuaEnvironment["tmp"] = null;

            LuaEnvironment.NewTable("tmp");
            LuaEnvironment.LoadString(
            @"function tmp:__index( key )
            if (type( key ) == 'table') then
            local baseType = rawget( self, '_type' )
            return util.SpecializeType( baseType, key )
            end
            end
            ", "LuaExtension").Call();
            generictypetablemeta = LuaEnvironment["tmp"] as LuaTable;
            LuaEnvironment["tmp"] = null;

            LuaEnvironment.NewTable("libraryMetaTable");
            LuaEnvironment.LoadString(
            @"function libraryMetaTable:__index( key )
            local ptbl = rawget( self, '_properties' )
            local property = ptbl[ key ]
            if (property) then return property:GetValue( rawget( self, '_object' ), null ) end
            end
            function libraryMetaTable:__newindex( key, value )
            local ptbl = rawget( self, '_properties' )
            local property = ptbl[ key ]
            if (property) then property:SetValue( rawget( self, '_object' ), value ) end
            end
            ", "LuaExtension").Call();
            libraryMetaTable = LuaEnvironment["libraryMetaTable"] as LuaTable;
            LuaEnvironment["libraryMetaTable"] = null;

            LuaEnvironment.NewTable("tmp");
            PluginMetatable = LuaEnvironment["tmp"] as LuaTable;
            LuaEnvironment.LoadString(
            @"function tmp:__newindex( key, value )
            if (type( value ) ~= 'function') then return rawset( self, key, value ) end
            local activeAttrib = rawget( self, '_activeAttrib' )
            if (not activeAttrib) then return rawset( self, key, value ) end
            if (activeAttrib == self) then
            print( 'PluginMetatable.__newindex - self._activeAttrib was somehow self!' )
            rawset( self, key, value )
            return
            end
            local attribArr = rawget( self, '_attribArr' )
            if (not attribArr) then
            attribArr = {}
            rawset( self, '_attribArr', attribArr )
            end
            activeAttrib._func = value
            attribArr[#attribArr + 1] = activeAttrib
            rawset( self, '_activeAttrib', nil )
            end
            ", "LuaExtension").Call();
            LuaEnvironment["tmp"] = null;
        }
コード例 #2
0
ファイル: LuaGame.cs プロジェクト: CallumDev/BubbleEngine
 public LuaGame(string entryPath)
 {
     Window.Title = "Bubble Engine";
     //create lua state
     state = new BubbleLua (new Lua());
     state.Lua.LoadCLRPackage ();
     state.Bubble ["runtime"] = new LuaAPI.Runtime();
     state.Bubble ["fonts"] = new LuaAPI.Fonts (FontContext);
     luaGraphics = new LuaAPI.Graphics (null, this);
     state.Bubble ["graphics"] = luaGraphics;
     state.Bubble ["window"] = new LuaAPI.LWindow (Window);
     LuaAPI.Util.RegisterEnum (typeof(Keys), state);
     state.Lua ["embedres"] = new LuaAPI.EmbeddedLoader ();
     //run init scripts
     state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.procure.lua"));
     state.Lua.DoString(EmbeddedResources.GetString("BubbleEngine.LuaAPI.init.lua"));
     //config
     state.Lua.DoFile(entryPath);
     gameTable = (LuaTable)state.Lua ["game"];
     var cfg = (LuaFunction)gameTable ["config"];
     if (cfg == null) {
         throw new NLua.Exceptions.LuaScriptException ("Script must have a game.config() function", entryPath);
     }
     cfg.Call ();
     updateFunction = (LuaFunction)gameTable ["update"];
     drawFunction = (LuaFunction)gameTable ["draw"];
 }
コード例 #3
0
ファイル: LuaScript.cs プロジェクト: horato/IntWarsSharp
        public Dictionary<object, object> getTableDictionary(LuaTable table)
        {
            if (!loaded)
                return null;

            return lua.GetTableDict(table);
        }
コード例 #4
0
ファイル: Task.cs プロジェクト: nondev/kaizo
        public static object Call(string name, LuaTable args = null)
        {
            Logger.Default.Log(":", false, MainClass.COLOR).Log(name);
              var task = MainClass.GetLua().GetFunction (name);

              if (task == null) {
            throw new NotImplementedException ("Unknown task '" + name + "'");
              }

              object result = null;

              var project = name.Split ('.')[0];

              try {
            if (args != null) {
              result = task.Call (project, args);
            } else {
              result = task.Call (project);
            }
              } catch (Exception e) {
            MainClass.Fail (e);
              }

              return result;
        }
コード例 #5
0
        /// <summary>
        /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
        /// </summary>
        private static string GetStatusKey(LuaInterface.LuaTable asset1, LuaInterface.LuaTable asset2)
        {
            string asset1Name = StringToTableIndex(asset1["Name"].ToString());
            string asset2Name = StringToTableIndex(asset2["Name"].ToString());

            return(string.Format("{0}[\"{1}\"],{2}[\"{3}\"]", new System.Object[] { GetAssetType(asset1Name), asset1Name, GetAssetType(asset2Name), asset2Name }));
        }
コード例 #6
0
ファイル: LuaUtil.cs プロジェクト: 906507516/Oxide
        public object BitwiseOr(LuaTable table)
        {
            // First of all, check it's actually an array
            int size;
            if (!table.IsArray(out size) || size == 0)
            {
                throw new InvalidOperationException("Specified table is not an array");
            }

            // Get the length
            int result = -1;
            Type type = null;

            // Create the array
            foreach (object key in table.Keys)
            {
                if (result < 0)
                {
                    result = (int)table[key];
                    type = table[key].GetType();
                    continue;
                }
                result |= (int)table[key];
            }

            // Return it
            return Enum.ToObject(type, result);
        }
コード例 #7
0
        public static Vector2 LuaToVector2(LuaTable table)
        {
            Vector2 vector = new Vector2();
            vector.X = (float)(double)table[0];
            vector.Y = (float)(double)table[1];

            return vector;
        }
コード例 #8
0
ファイル: BubbleLua.cs プロジェクト: CallumDev/BubbleEngine
 public BubbleLua(Lua lua, bool init = true)
 {
     Lua = lua;
     if (!init)
         return;
     Lua.NewTable ("bubble");
     Bubble = (LuaTable)Lua ["bubble"];
     lua.DoString (EmbeddedResources.GetString ("BubbleEngine.LuaAPI.bubbleinternal.lua"));
 }
コード例 #9
0
ファイル: LuaUtil.cs プロジェクト: yas-online/Oxide
 public object TableToLangDict(LuaTable table)
 {
     var dict = new Dictionary<string, string>();
     foreach (var key in table.Keys)
     {
         if (key is string)
         dict.Add((string)key, (string)table[key]);
     }
     return dict;
 }
コード例 #10
0
ファイル: Utility.cs プロジェクト: yas-online/Oxide
 /// <summary>
 /// Copies and translates the contents of the specified table into the specified config file
 /// </summary>
 /// <param name="config"></param>
 /// <param name="table"></param>
 public static void SetConfigFromTable(DynamicConfigFile config, LuaTable table)
 {
     config.Clear();
     foreach (var key in table.Keys)
     {
         var keystr = key as string;
         if (keystr == null) continue;
         var value = TranslateLuaItemToConfigItem(table[key]);
         if (value != null) config[keystr] = value;
     }
 }
コード例 #11
0
ファイル: RequireExample.cs プロジェクト: SD-J/UnityLua
		void Start()
		{
			LuaState = new Lua();
			LuaState.LoadCLRPackage();
			LuaState.LoadUnityExpand();

			var ret = LuaState.DoString(@"return require 'requiretest'");
			TestLib = ret[0] as LuaTable;

			var startCallback = TestLib["Start"] as LuaFunction;
			startCallback.Call(this.gameObject);
		}
コード例 #12
0
        public static void RegisterComponent(string Name, LuaTable tab)
        {
            Util.Msg("Registring Component " + Name);

            if(ComponentDictionary.ContainsKey(Name))
            {
                Util.Msg("Warning: Lua Component " + Name + " Already registered! Skipping");
                return;
            }

            ComponentDictionary[Name] = tab;
        }
コード例 #13
0
ファイル: Graphics.cs プロジェクト: CallumDev/BubbleEngine
 public void fillRectangle(double x, double y, double w, double h, LuaTable color)
 {
     if (color == null) {
         Console.WriteLine ("Null color");
         throw new Exception ();
     }
     Batch.FillRectangle (
         new Rectangle (
             (int)x, (int)y, (int)w, (int)h
         ),
         Util.ColorFromTable (color)
     );
 }
コード例 #14
0
        /// <summary>
        /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
        /// </summary>
        public static void DecRelationship(LuaInterface.LuaTable actor1, LuaInterface.LuaTable actor2, string relationshipType, float value)
        {
            string key = GetRelationshipKey(actor1, actor2, relationshipType);

            if (relationshipTable.ContainsKey(key))
            {
                relationshipTable[key] -= value;
            }
            else
            {
                relationshipTable.Add(key, -value);
            }
        }
コード例 #15
0
 public void SendDecisionMessage( LuaTable decisionsToSend )
 {
     if ( decisionsToSend != null ) {
         if ( decisionsToSend.Values.Count > 1 ) {
             //seems to be pulling things in the order they are on the stack, not how they were put there
             var d = decisionsToSend.Values.Cast<Decision>().Reverse().ToArray();
             Messenger.Default.Send( new DecisionMessage( d ) );
         }else {
             var d = decisionsToSend.Values.Cast<Decision>().ToArray();
             Messenger.Default.Send( new DecisionMessage( d[0] ) );
         }
     }
 }
コード例 #16
0
ファイル: Util.cs プロジェクト: yangsookimm/Goose
        public static object ObjFromTable(LuaTable t)
        {
            Dictionary<string, object> args = new Dictionary<string, object>();

            foreach (object key in t.Keys)
            {
                object value = t[key];
                object obj;
                if (key is double) { return ObjArrayFromTable(t); }
                if (value is LuaTable) { obj = ObjFromTable((LuaTable)value); } else { obj = value; }
                args.Add(key.ToString(), obj);
            }
            return args;
        }
コード例 #17
0
        protected override bool _OnInit(string v_strCellVal)
        {
            _key = v_strCellVal;
            Lua.Lua lua_state = LuaState.Get_Instenct();
            object  lua_data  = null;
            var     tmprst    = lua_state.DoString("return " + v_strCellVal);

            if (tmprst == null)
            {
                Debug.ExcelError("return " + v_strCellVal + " is nil");
                return(false);
            }
            lua_data = tmprst[0];
            if (lua_data == null)
            {
                _luaval = new LuaNil();
                return(true);
            }
            else if (lua_data is Lua.LuaTable)
            {
                Lua.LuaTable table = lua_data as Lua.LuaTable;
                LuaMap       map   = new LuaMap();
                map.init(_isStretch, ExportSheetBin.ROW_MAX_ELEMENT);
                if (!fill_luatable(map, table))
                {
                    _luaval = new LuaNil();
                    return(false);
                }
                _luaval = map;
                return(true);
            }
            else if (lua_data is double)
            {
                _luaval = new LuaDouble(Convert.ToDouble(lua_data));
                return(true);
            }
            else if (lua_data is string)
            {
                _luaval = new LuaString(Convert.ToString(lua_data));
                return(true);
            }
            else if (lua_data is bool)
            {
                _luaval = new LuaBoolean(Convert.ToBoolean(lua_data));
                return(true);
            }

            return(false);
        }
コード例 #18
0
 private static bool IsAssetInTable(string assetTableName, string assetName)
 {
     LuaInterface.LuaTable table = Lua.Run(string.Format("return {0}", new System.Object[] { assetTableName })).AsLuaTable;
     if (table != null)
     {
         foreach (string key in table.Keys)
         {
             if (string.Equals(key, assetName))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #19
0
ファイル: Util.cs プロジェクト: yangsookimm/Goose
 public static object[] ObjArrayFromTable(LuaTable t)
 {
     object[] r = new object[t.Values.Count];
     int i = 0;
     foreach (object value in t.Values)
     {
         if (value is LuaTable) { r[i] = ObjFromTable((LuaTable)value); }
         else
         {
             r[i] = value;
         }
         i++;
     }
     return r;
 }
コード例 #20
0
 public void SendDecisionMessage( LuaTable decisionsToSend )
 {
     if (decisionsToSend == null) {
         return;
     }
     if ( decisionsToSend.Values.Count > 1 ) {
         var decs=new Decision[decisionsToSend.Keys.Count];
         for ( var i = 0; i < decisionsToSend.Keys.Count; i++ ) {
             decs[i] = (Decision)decisionsToSend[i];
         }
         Messenger.Default.Send( new DecisionMessage( decs ) );
     }else {
         var d = decisionsToSend.Values.Cast<Decision>().ToArray();
         Messenger.Default.Send( new DecisionMessage( d[0] ) );
     }
 }
コード例 #21
0
 /// <summary>
 /// Checks if a table element exists.
 /// </summary>
 /// <returns><c>true</c>, if the table entry exists, <c>false</c> otherwise.</returns>
 /// <param name="table">Table name (e.g., "Actor").</param>
 /// <param name="element">Element name (e.g., "Player").</param>
 public static bool DoesTableElementExist(string table, string element)
 {
     LuaInterface.LuaTable luaTable = SafeGetLuaResult(string.Format("return {0}", new System.Object[] { table })).AsLuaTable;
     if (luaTable != null)
     {
         string tableIndex = StringToTableIndex(element);
         foreach (var o in luaTable.Keys)
         {
             if ((o.GetType() == typeof(string)) && (string.Equals((string)o, tableIndex)))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #22
0
        protected bool fill_luatable(LuaMap v_map, Lua.LuaTable v_luatable)
        {
            foreach (KeyValuePair <object, object> i in v_luatable)
            {
                LuaValue val = null;
                if (i.Value is Lua.LuaTable)
                {
                    LuaMap newTable = new LuaMap();
                    newTable.init(_isStretch, ExportSheetBin.ROW_MAX_ELEMENT);
                    fill_luatable(newTable, (Lua.LuaTable)i.Value);
                    val = newTable;
                }
                else
                {
                    if (i.Value is double)
                    {
                        val = new LuaDouble(Convert.ToDouble(i.Value));
                    }
                    else if (i.Value is string)
                    {
                        val = new LuaString(Convert.ToString(i.Value));
                    }
                    else if (i.Value is bool)
                    {
                        val = new LuaBoolean(Convert.ToBoolean(i.Value));
                    }
                    else if (i.Value == null)
                    {
                        val = new LuaNil();
                    }
                    else
                    {
                        Debug.Exception("出现了无法识别的luavalue,键是{0}", i.Key);
                    }
                }

                if (i.Key is int || i.Key is double)
                {
                    v_map.addData(Convert.ToInt32(i.Key), val);
                }
                else if (i.Key is string)
                {
                    v_map.addData(Convert.ToString(i.Key), val);
                }
            }
            return(true);
        }
コード例 #23
0
        public static Color LuaToColor(LuaTable table)
        {
            if (table.Values.Count == 3)
            {
                Color color = new Color();
                color.R = (byte)(double)table[1];
                color.G = (byte)(double)table[2];
                color.B = (byte)(double)table[3];
                color.A = 255;

                return color;
            }
            else
            {
                throw new Exception("Invalid Lua Color!");
            }
        }
コード例 #24
0
        DataTable LuaTableToDataTable(NLua.LuaTable columns, NLua.LuaTable rows)
        {
            var d = new DataTable();

            if (columns == null)
            {
                return(d);
            }

            var ts = GetTypesFromRows(rows);

            var idx = 0;

            foreach (var column in columns.Values)
            {
                var name = column.ToString();
                if (ts == null)
                {
                    d.Columns.Add(name);
                }
                else
                {
                    d.Columns.Add(name, ts[idx++]);
                }
            }

            if (rows == null)
            {
                return(d);
            }
            var rowsKey = rows.Keys;

            foreach (var rowkey in rowsKey)
            {
                var row   = rows[rowkey] as NLua.LuaTable;
                var items = new List <object>();
                foreach (var item in row.Values)
                {
                    items.Add(item);
                }

                d.Rows.Add(items.ToArray());
            }
            return(d);
        }
コード例 #25
0
        /// <summary>
        /// Gets the value of field in a Lua table element.
        /// </summary>
        /// <returns>The field value as a Lua.Result. To get a basic data type, addend <c>.AsString</c>, <c>.AsBool</c>, etc., to it.</returns>
        /// <param name="table">Table name.</param>
        /// <param name="element">Name of an element in the table.</param>
        /// <param name="field">Name of a field in the element.</param>
        public static Lua.Result GetTableField(string table, string element, string field)
        {
            string tableIndex = StringToTableIndex(element);

            LuaInterface.LuaTable luaTable = SafeGetLuaResult(string.Format("return {0}", new System.Object[] { table })).AsLuaTable;
            if (luaTable == null)
            {
                return(Lua.NoResult);
            }
            foreach (var o in luaTable.Keys)
            {
                if ((o.GetType() == typeof(string)) && (string.Equals((string)o, tableIndex)))
                {
                    return(SafeGetLuaResult(string.Format("return {0}[\"{1}\"].{2}", new System.Object[] { table, tableIndex, StringToTableIndex(field) })));
                }
            }
            return(Lua.NoResult);
        }
コード例 #26
0
        List <Type> GetTypesFromRows(NLua.LuaTable rows)
        {
            if (rows == null)
            {
                return(null);
            }

            var ts = new List <Type>();

            foreach (var row in rows.Values)
            {
                foreach (var cell in (row as NLua.LuaTable).Values)
                {
                    ts.Add(cell.GetType());
                }
                return(ts);
            }
            return(null);
        }
コード例 #27
0
ファイル: LuaUtil.cs プロジェクト: yas-online/Oxide
        public object[] TableToArray(LuaTable table)
        {
            // First of all, check it's actually an array
            int size;
            if (!table.IsArray(out size))
            {
                throw new InvalidOperationException("Specified table is not an array");
            }

            // Get the length
            var arr = new object[size];

            // Create the array
            foreach (var key in table.Keys)
            {
                var index = Convert.ToInt32(key) - 1;
                arr[index] = table[key];
            }

            // Return it
            return arr;
        }
コード例 #28
0
        public static object Pop(IntPtr state)
        {
            LuaType type = LuaCore.GetType(state, -1);

            LuaDebugger.SetStackReferencePoint(state);

            object result;
            switch (type)
            {
                case LuaType.Nil:
                    result = null;
                    break;

                case LuaType.Number:
                    result = LuaCore.ToNumber(state, -1);
                    break;

                case LuaType.String:
                    result = LuaHelper.ToString(state, -1);
                    break;

                case LuaType.Table:
                    // LuaTable's constructor consumes one object from the stack
                    result = new LuaTable(state);
                    break;

                default:
                    throw new UnsupportedTypeException("The type associated with the specified global is unsupported.");
            }

            LuaDebugger.AssertStackIsBalanced(state);

            LuaHelper.Discard(state);

            return result;
        }
コード例 #29
0
ファイル: LuaExtension.cs プロジェクト: RuanPitout88/Oxide
 /// <summary>
 /// The __index metamethod of the type table
 /// </summary>
 /// <param name="tbl"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 private static object ReadStaticProperty(LuaTable tbl, object key)
 {
     Interface.Oxide.LogWarning("__index ReadStaticProperty {0}", key);
     string keystr = key as string;
     if (keystr == null) return null;
     if (keystr == "_sftbl") return null;
     LuaTable sftbl = tbl["_sftbl"] as LuaTable;
     if (sftbl == null)
     {
         Interface.GetMod().RootLogger.Write(LogType.Warning, "Tried to access _sftbl on type table when reading but it doesn't exist!");
         return null;
     }
     object prop = sftbl[keystr];
     if (prop == null) return null;
     FieldInfo field = prop as FieldInfo;
     if (field != null)
     {
         return field.GetValue(null);
     }
     return null;
 }
コード例 #30
0
ファイル: Main.cs プロジェクト: khwoo1004/Oxide
 private object lua_New(Type typ, LuaTable args, int argn)
 {
     if (typ == null)
     {
         Logger.Error(string.Format("Failed to instantiate object (typ is null)!"));
         return null;
     }
     if (args == null)
     {
         try
         {
             return Activator.CreateInstance(typ);
         }
         catch (Exception ex)
         {
             Logger.Error(string.Format("Failed to instantiate {0} (exception: {1})!", typ, ex));
             return null;
         }
     }
     else
     {
         object[] oargs = Array(argn);
         for (int i = 0; i < argn; i++)
             oargs[i] = args[i + 1];
         try
         {
             return Activator.CreateInstance(typ, oargs);
         }
         catch (Exception ex)
         {
             Logger.Error(string.Format("Failed to instantiate {0} (exception: {1})!", typ, ex));
             return null;
         }
     }
 }
コード例 #31
0
ファイル: LuaExtension.cs プロジェクト: RuanPitout88/Oxide
 /// <summary>
 /// The __index metamethod of overload selector
 /// </summary>
 /// <param name="tbl"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 private static MethodBase FindOverload(LuaTable tbl, object key)
 {
     // TODO: This
     // tbl.methodarray has an array of methods to search though
     // key should be a table of types defining the signature of the method to find
     return null;
 }
コード例 #32
0
ファイル: Main.cs プロジェクト: khwoo1004/Oxide
 private Array lua_CreateArrayFromTable(Type arrtype, LuaTable tbl, int argn)
 {
     object[] args = Array(1);
     args[0] = argn;
     Array arr = Activator.CreateInstance(arrtype.MakeArrayType(), args) as Array;
     for (int i = 0; i < argn; i++)
         arr.SetValue(tbl[i + 1], i);
     return arr;
 }
コード例 #33
0
ファイル: Main.cs プロジェクト: khwoo1004/Oxide
 private Type lua_MakeGenericType(Type typ, LuaTable args, int argn)
 {
     if (typ == null)
     {
         Logger.Error(string.Format("Failed to make generic type (typ is null)!"));
         return null;
     }
     Type[] targs = new Type[argn];
     for (int i = 0; i < argn; i++)
     {
         object obj = args[i + 1];
         if (obj == null)
         {
             Logger.Error(string.Format("Failed to make generic type {0} (an arg is null)!", typ));
             return null;
         }
         else if (obj is Type)
             targs[i] = obj as Type;
         else
         {
             Logger.Error(string.Format("Failed to make generic type {0} (an arg is invalid)!", typ));
             return null;
         }
     }
     try
     {
         return typ.MakeGenericType(targs);
     }
     catch (Exception ex)
     {
         Logger.Error(string.Format("Failed to make generic type {0}", typ), ex);
         return null;
     }
 }
コード例 #34
0
 public string ShowData(string title, NLua.LuaTable columns, NLua.LuaTable rows) =>
 ShowData(title, columns, rows, -1);
コード例 #35
0
ファイル: Main.cs プロジェクト: khwoo1004/Oxide
 private object lua_CallPlugins(string methodname, LuaTable args, int argn)
 {
     object[] arr = Array(argn);
     for (int i = 0; i < argn; i++)
         arr[i] = args[i + 1];
     return pluginmanager.Call(methodname, arr);
 }
コード例 #36
0
 /// <summary>
 /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
 /// </summary>
 private static string GetRelationshipKey(LuaInterface.LuaTable actor1, LuaInterface.LuaTable actor2, string relationshipType)
 {
     return(string.Format("Actor[\"{0}\"],Actor[\"{1}\"],\"{2}\"", new System.Object[] { StringToTableIndex(actor1["Name"].ToString()), StringToTableIndex(actor2["Name"].ToString()), relationshipType }));
 }
コード例 #37
0
ファイル: LuaTests.cs プロジェクト: The-Megax/NLua
			public LuaITestClassHandler (LuaTable luaTable, Type[][] returnTypes)
			{
				__luaInterface_luaTable = luaTable;
				__luaInterface_returnTypes = returnTypes;
			}
コード例 #38
0
ファイル: LuaExtension.cs プロジェクト: RuanPitout88/Oxide
 /// <summary>
 /// The __newindex metamethod of the type table
 /// </summary>
 /// <param name="tbl"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 private static void WriteStaticProperty(LuaTable tbl, object key, object value)
 {
     string keystr = key as string;
     if (keystr == null) return;
     if (keystr == "_sftbl") return;
     LuaTable sftbl = tbl["_sftbl"] as LuaTable;
     if (sftbl == null)
     {
         Interface.Oxide.LogWarning("Tried to access _sftbl on type table when writing but it doesn't exist!");
         return;
     }
     object prop = sftbl[keystr];
     if (prop == null) return;
     FieldInfo field = prop as FieldInfo;
     if (field != null)
     {
         field.SetValue(null, value);
     }
 }
コード例 #39
0
        /// <summary>
        /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
        /// </summary>
        public static float GetRelationship(LuaInterface.LuaTable actor1, LuaInterface.LuaTable actor2, string relationshipType)
        {
            string key = GetRelationshipKey(actor1, actor2, relationshipType);

            return(relationshipTable.ContainsKey(key) ? relationshipTable[key] : 0);
        }
コード例 #40
0
ファイル: Lua.cs プロジェクト: Azhei/NLua
		public Dictionary<object, object> GetTableDict (LuaTable table)
		{
			var dict = new Dictionary<object, object> ();
			int oldTop = LuaLib.lua_gettop (luaState);
			translator.push (luaState, table);
			LuaLib.lua_pushnil (luaState);

			while (LuaLib.lua_next(luaState, -2) != 0) {
				dict [translator.getObject (luaState, -2)] = translator.getObject (luaState, -1);
				LuaLib.lua_settop (luaState, -2);
			}

			LuaLib.lua_settop (luaState, oldTop);
			return dict;
		}
コード例 #41
0
 public int Choice(string title, NLua.LuaTable choices, bool isShowKey) =>
 Choice(title, choices, isShowKey, -1);
コード例 #42
0
        public int Choice(string title, NLua.LuaTable choices, bool isShowKey, int selected)
        {
            var list = global::Luna.Misc.Utils.LuaTableToList(choices, isShowKey);

            return(GetResultFromChoiceDialog(title, list.ToArray(), selected));
        }
コード例 #43
0
 /// <summary>
 /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
 /// </summary>
 public static void SetStatus(LuaInterface.LuaTable asset1, LuaInterface.LuaTable asset2, string statusValue)
 {
     statusTable[GetStatusKey(asset1, asset2)] = statusValue;
 }
コード例 #44
0
 /// <summary>
 /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
 /// </summary>
 public static void SetRelationship(LuaInterface.LuaTable actor1, LuaInterface.LuaTable actor2, string relationshipType, float value)
 {
     relationshipTable[GetRelationshipKey(actor1, actor2, relationshipType)] = value;
 }
コード例 #45
0
ファイル: CodeGeneration.cs プロジェクト: CartBlanche/NLua
        /*
         * Gets an instance of an implementation of the klass interface or
         * subclass of klass that delegates public virtual methods to the
         * luaTable table.
         * Caches the generated type.
         */
        public object GetClassInstance(Type klass, LuaTable luaTable)
        {
            LuaClassType luaClassType;

            if (classCollection.ContainsKey (klass))
                luaClassType = classCollection [klass];
            else {
                luaClassType = new LuaClassType ();
                GenerateClass (klass, out luaClassType.klass, out luaClassType.returnTypes);
                classCollection [klass] = luaClassType;
            }

            return Activator.CreateInstance (luaClassType.klass, new object[] {
                luaTable,
                luaClassType.returnTypes
            });
        }
コード例 #46
0
        /// <summary>
        /// Chat Mapper function. See the online Chat Mapper manual for more details: http://www.chatmapper.com
        /// </summary>
        public static string GetStatus(LuaInterface.LuaTable asset1, LuaInterface.LuaTable asset2)
        {
            string key = GetStatusKey(asset1, asset2);

            return(statusTable.ContainsKey(key) ? statusTable[key] : string.Empty);
        }
コード例 #47
0
 public List <int> Choices(string title, NLua.LuaTable choices) =>
 Choices(title, choices, false);
コード例 #48
0
        public string ShowData(string title, NLua.LuaTable columns, NLua.LuaTable rows, int defColumn)
        {
            var dt = LuaTableToDataTable(columns, rows);

            return(ShowDataGridDialog(title, dt, defColumn));
        }
コード例 #49
0
 public LuaTableWrapper(LuaInterface.LuaTable luaTable)
 {
     this.luaTable = luaTable;
 }
コード例 #50
0
        public List <int> Choices(string title, NLua.LuaTable choices, bool isShowKey)
        {
            var list = global::Luna.Misc.Utils.LuaTableToList(choices, isShowKey);

            return(GetResultFromChoicesDialog(title, list.ToArray()));
        }
コード例 #51
0
ファイル: Lua.cs プロジェクト: nobitagamer/NLua
		public Dictionary<object, object> GetTableDict (LuaTable table)
		{
			var dict = new Dictionary<object, object> ();
			int oldTop = LuaLib.LuaGetTop (luaState);
			translator.Push (luaState, table);
			LuaLib.LuaPushNil (luaState);

			while (LuaLib.LuaNext(luaState, -2) != 0) {
				dict [translator.GetObject (luaState, -2)] = translator.GetObject (luaState, -1);
				LuaLib.LuaSetTop (luaState, -2);
			}

			LuaLib.LuaSetTop (luaState, oldTop);
			return dict;
		}
コード例 #52
0
 public int Choice(string title, NLua.LuaTable choices) =>
 Choice(title, choices, false, -1);