当前位置: 首页>>代码示例>>C#>>正文


C# NLua.LuaTable类代码示例

本文整理汇总了C#中NLua.LuaTable的典型用法代码示例。如果您正苦于以下问题:C# LuaTable类的具体用法?C# LuaTable怎么用?C# LuaTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LuaTable类属于NLua命名空间,在下文中一共展示了LuaTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeLua

        /// <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;
        }
开发者ID:RuanPitout88,项目名称:Oxide,代码行数:96,代码来源:LuaExtension.cs

示例2: BitwiseOr

        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);
        }
开发者ID:906507516,项目名称:Oxide,代码行数:28,代码来源:LuaUtil.cs

示例3: LuaGame

 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"];
 }
开发者ID:CallumDev,项目名称:BubbleEngine,代码行数:27,代码来源:LuaGame.cs

示例4: getTableDictionary

        public Dictionary<object, object> getTableDictionary(LuaTable table)
        {
            if (!loaded)
                return null;

            return lua.GetTableDict(table);
        }
开发者ID:horato,项目名称:IntWarsSharp,代码行数:7,代码来源:LuaScript.cs

示例5: Call

        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;
        }
开发者ID:nondev,项目名称:kaizo,代码行数:25,代码来源:Task.cs

示例6: LuaToVector2

        public static Vector2 LuaToVector2(LuaTable table)
        {
            Vector2 vector = new Vector2();
            vector.X = (float)(double)table[0];
            vector.Y = (float)(double)table[1];

            return vector;
        }
开发者ID:noogai03sprojects,项目名称:AerialArchitect,代码行数:8,代码来源:LuaHelper.cs

示例7: BubbleLua

 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"));
 }
开发者ID:CallumDev,项目名称:BubbleEngine,代码行数:9,代码来源:BubbleLua.cs

示例8: TableToLangDict

 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;
 }
开发者ID:yas-online,项目名称:Oxide,代码行数:10,代码来源:LuaUtil.cs

示例9: SetConfigFromTable

 /// <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;
     }
 }
开发者ID:yas-online,项目名称:Oxide,代码行数:16,代码来源:Utility.cs

示例10: Start

		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);
		}
开发者ID:SD-J,项目名称:UnityLua,代码行数:12,代码来源:RequireExample.cs

示例11: RegisterComponent

        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;
        }
开发者ID:RoyAwesome,项目名称:Watertight-Engine,代码行数:12,代码来源:EntityComponentDictionary.cs

示例12: fillRectangle

 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)
     );
 }
开发者ID:CallumDev,项目名称:BubbleEngine,代码行数:13,代码来源:Graphics.cs

示例13: SendDecisionMessage

 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] ) );
         }
     }
 }
开发者ID:Black-Eagle-Software,项目名称:BES_Survivalism,代码行数:13,代码来源:LuaCustomFunctions.cs

示例14: ObjFromTable

        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;
        }
开发者ID:yangsookimm,项目名称:Goose,代码行数:14,代码来源:Util.cs

示例15: ObjArrayFromTable

 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;
 }
开发者ID:yangsookimm,项目名称:Goose,代码行数:15,代码来源:Util.cs


注:本文中的NLua.LuaTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。