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


C# Lua.NewTable方法代码示例

本文整理汇总了C#中LuaInterface.Lua.NewTable方法的典型用法代码示例。如果您正苦于以下问题:C# Lua.NewTable方法的具体用法?C# Lua.NewTable怎么用?C# Lua.NewTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LuaInterface.Lua的用法示例。


在下文中一共展示了Lua.NewTable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnActivate

        public void OnActivate()
        {
            // Create the lua state
            luastate = new Lua();

            // Setup hooks
            dctHooks = new Dictionary<string, List<LuaFunction>>();

            // Bind functions
            BindFunction("print", "print");

            luastate.NewTable("hook");
            BindFunction("hook.Add", "hook_Add");

            luastate.NewTable("library");
            BindFunction("library.AddWeapon", "library_AddWeapon");
            BindFunction("library.AddSystem", "library_AddSystem");
            BindFunction("library.AddRace", "library_AddRace");
            BindFunction("library.AddShipGenerator", "library_AddShipGenerator");
            BindFunction("library.AddSectorMapGenerator", "library_AddSectorMapGenerator");
            BindFunction("library.GetWeapon", "library_GetWeapon");
            BindFunction("library.GetSystem", "library_GetSystem");
            BindFunction("library.GetRace", "library_GetRace");
            BindFunction("library.GetShip", "library_GetShipGenerator");
            BindFunction("library.GetSectorMapGenerator", "library_GetSectorMapGenerator");
            BindFunction("library.CreateAnimation", "library_CreateAnimation");

            luastate.NewTable("ships");
            BindFunction("ships.NewDoor", "ships_NewDoor"); // Is there any way to call the constructor directly from lua code?

            // Load lua files
            if (!Directory.Exists("lua")) Directory.CreateDirectory("lua");
            foreach (string name in Directory.GetFiles("lua"))
                luastate.DoFile("lua/" + name);
        }
开发者ID:danielrh,项目名称:ftl-overdrive,代码行数:35,代码来源:ModdingAPI.cs

示例2: Main

        public static void Main(string[] args)
        {
            if(args.Length > 0)
            {
                // For attaching from the debugger
                // Thread.Sleep(20000);

                using(Lua lua = new Lua())
                {
                    //lua.OpenLibs();			// steffenj: Lua 5.1.1 API change (all libs already opened in Lua constructor!)
                    lua.NewTable("arg");
                    LuaTable argc = (LuaTable)lua["arg"];
                    argc[-1] = "LuaRunner";
                    argc[0] = args[0];

                    for(int i = 1; i < args.Length; i++)
                        argc[i] = args[i];

                    argc["n"] = args.Length - 1;

                    try
                    {
                        //Console.WriteLine("DoFile(" + args[0] + ");");
                        lua.DoFile(args[0]);
                    }
                    catch(Exception e)
                    {
                        // steffenj: BEGIN error message improved, output is now in decending order of importance (message, where, stacktrace)
                        // limit size of strack traceback message to roughly 1 console screen height
                        string trace = e.StackTrace;

                        if(e.StackTrace.Length > 1300)
                            trace = e.StackTrace.Substring(0, 1300) + " [...] (traceback cut short)";

                        Console.WriteLine();
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.Source + " raised a " + e.GetType().ToString());
                        Console.WriteLine(trace);

                        // wait for keypress if there is an error
                        Console.ReadKey();
                        // steffenj: END error message improved
                    }
                }
            }
            else
            {
                Console.WriteLine("LuaRunner -- runs Lua scripts with CLR access");
                Console.WriteLine("Usage: luarunner <script.lua> [{<arg>}]");
            }
        }
开发者ID:lenzener,项目名称:LuaInterface,代码行数:51,代码来源:LuaNetRunner.cs

示例3: OnActivate

        public void OnActivate(params object[] args)
        {
            // Create the lua state
            luastate = new Lua();

            // Setup hooks
            dctHooks = new Dictionary<string, List<LuaFunction>>();

            // Bind functions
            BindFunction("print", "print");

            luastate.NewTable("hook");
            BindFunction("hook.Add", "hook_Add");

            luastate.NewTable("library");
            BindFunction("library.AddWeapon", "library_AddWeapon");
            BindFunction("library.AddSystem", "library_AddSystem");
            BindFunction("library.AddRace", "library_AddRace");
            BindFunction("library.AddItem", "library_AddItem");
            BindFunction("library.AddShipGenerator", "library_AddShipGenerator");
            BindFunction("library.AddSectorMapGenerator", "library_AddSectorMapGenerator");
            BindFunction("library.GetWeapon", "library_GetWeapon");
            BindFunction("library.GetSystem", "library_GetSystem");
            BindFunction("library.GetRace", "library_GetRace");
            BindFunction("library.GetItem", "library_GetItem");
            BindFunction("library.GetShip", "library_GetShipGenerator");
            BindFunction("library.GetSectorMapGenerator", "library_GetSectorMapGenerator");
            BindFunction("library.CreateAnimation", "library_CreateAnimation");

            luastate.NewTable("ships");
            // You can't pass non-empty LuaTables to constructors. Possibly a bug in LI.
            BindFunction("ships.NewDoor", "ships_NewDoor");

            // Load lua files
            if (!Directory.Exists("lua")) Directory.CreateDirectory("lua");
            foreach (string name in Directory.GetFiles("lua"))
                luastate.DoFile(name);
        }
开发者ID:DiEvAl,项目名称:ftl-overdrive,代码行数:38,代码来源:ModdingAPI.cs

示例4: ToLuaTable

		public static LuaTable ToLuaTable(Lua lua, object obj)
		{
			var table = lua.NewTable();

			var type = obj.GetType();

			var methods = type.GetMethods();
			foreach (var method in methods)
			{
				if (method.IsPublic)
				{
					table[method.Name] = lua.RegisterFunction("", obj, method);
				}
			}

			return table;
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:17,代码来源:LuaHelper.cs

示例5: Main

        /*
         * Sample test script that shows some of the capabilities of
         * LuaInterface
         */
        public static void Main()
        {
            Console.WriteLine("Starting interpreter...");
            Lua l=new Lua();

            Console.WriteLine("Reading test.lua file...");
            l.DoFile("test.lua");
            double width=l.GetNumber("width");
            double height=l.GetNumber("height");
            string message=l.GetString("message");
            double color_r=l.GetNumber("color.r");
            double color_g=l.GetNumber("color.g");
            double color_b=l.GetNumber("color.b");
            Console.WriteLine("Printing values of global variables width, height and message...");
            Console.WriteLine("width: "+width);
            Console.WriteLine("height: "+height);
            Console.WriteLine("message: "+message);
            Console.WriteLine("Printing values of the 'color' table's fields...");
            Console.WriteLine("color.r: "+color_r);
            Console.WriteLine("color.g: "+color_g);
            Console.WriteLine("color.b: "+color_b);
            width=150;
            Console.WriteLine("Changing width's value and calling Lua function print to show it...");
            l["width"]=width;
            l.GetFunction("print").Call(width);
            message="LuaNet Interface Test";
            Console.WriteLine("Changing message's value and calling Lua function print to show it...");
            l["message"]=message;
            l.GetFunction("print").Call(message);
            color_r=30;
            color_g=10;
            color_b=200;
            Console.WriteLine("Changing color's fields' values and calling Lua function print to show it...");
            l["color.r"]=color_r;
            l["color.g"]=color_g;
            l["color.b"]=color_b;
            l.DoString("print(color.r,color.g,color.b)");
            Console.WriteLine("Printing values of the tree table's fields...");
            double leaf1=l.GetNumber("tree.branch1.leaf1");
            string leaf2=l.GetString("tree.branch1.leaf2");
            string leaf3=l.GetString("tree.leaf3");
            Console.WriteLine("leaf1: "+leaf1);
            Console.WriteLine("leaf2: "+leaf2);
            Console.WriteLine("leaf3: "+leaf3);
            leaf1=30; leaf2="new leaf2";
            Console.WriteLine("Changing tree's fields' values and calling Lua function print to show it...");
            l["tree.branch1.leaf1"]=leaf1; l["tree.branch1.leaf2"]=leaf2;
            l.DoString("print(tree.branch1.leaf1,tree.branch1.leaf2)");
            Console.WriteLine("Returning values from Lua with 'return'...");
            object[] vals=l.DoString("return 2,3");
            Console.WriteLine("Returned: "+vals[0]+" and "+vals[1]);
            Console.WriteLine("Calling a Lua function that returns multiple values...");
            object[] vals1=l.GetFunction("func").Call(2,3);
            Console.WriteLine("Returned: "+vals1[0]+" and "+vals1[1]);
            Console.WriteLine("Creating a table and filling it from C#...");
            l.NewTable("tab");
            l.NewTable("tab.tab");
            l["tab.a"]="a!";
            l["tab.b"]=5.5;
            l["tab.tab.c"]=6.5;
            l.DoString("print(tab.a,tab.b,tab.tab.c)");
            Console.WriteLine("Setting a table as another table's field...");
            l["tab.a"]=l["tab.tab"];
            l.DoString("print(tab.a.c)");
            Console.WriteLine("Registering a C# static method and calling it from Lua...");

            // Pause so we can connect with the debugger
            // Thread.Sleep(30000);

            l.RegisterFunction("func1",null,typeof(TestLuaInterface).GetMethod("func"));
            vals1=l.GetFunction("func1").Call(2,3);
            Console.WriteLine("Returned: "+vals1[0]);
            TestLuaInterface obj=new TestLuaInterface();
            Console.WriteLine("Registering a C# instance method and calling it from Lua...");
            l.RegisterFunction("func2",obj,typeof(TestLuaInterface).GetMethod("funcInstance"));
            vals1=l.GetFunction("func2").Call(2,3);
            Console.WriteLine("Returned: "+vals1[0]);

            Console.WriteLine("Testing throwing an exception...");
            obj.ThrowUncaughtException();

            Console.WriteLine("Testing catching an exception...");
            obj.ThrowException();

            Console.WriteLine("Testing inheriting a method from Lua...");
            obj.LuaTableInheritedMethod();

            Console.WriteLine("Testing overriding a C# method with Lua...");
            obj.LuaTableOverridedMethod();

            Console.WriteLine("Stress test RegisterFunction (based on a reported bug)..");
            obj.RegisterFunctionStressTest();

            Console.WriteLine("Test structures...");
            obj.TestStructs();

//.........这里部分代码省略.........
开发者ID:bobbyzhu,项目名称:MonoLuaInterface,代码行数:101,代码来源:TestLua.cs

示例6: Register

 public static void Register(Lua L)
 {
     L.NewTable("utils");
     LuaRegistrationHelper.TaggedStaticMethods(L,typeof(MyClass));
 }
开发者ID:bobbyzhu,项目名称:MonoLuaInterface,代码行数:5,代码来源:CallLua.cs


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