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


C# Lua.GetFunction方法代码示例

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


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

示例1: GUIAddon

        public GUIAddon(string a_filePath)
        {
            m_lua = new Lua();
            ((GameState)Game.getInstance().getCurrentState()).getGUI().registerFunctions(m_lua);
            m_lua.DoFile(a_filePath);

            m_onLoad = m_lua.GetFunction("OnLoad");
            m_onUpdate = m_lua.GetFunction("OnUpdate");
            m_onDraw = m_lua.GetFunction("OnDraw");
        }
开发者ID:Joxe,项目名称:TacticsRPG,代码行数:10,代码来源:GuiElement.cs

示例2: UnWrapObject

 /// <summary>
 /// Unwaps an object comming from LuaInterface for use in DynamicLua.
 /// </summary>
 public static object UnWrapObject(object wrapped, Lua state, string name = null)
 {
     if (wrapped is LuaTable)
         return new DynamicLuaTable(wrapped as LuaTable, state, name);
     else if (wrapped is LuaFunction)
         return new DynamicLuaFunction(wrapped as LuaFunction);
     else if (wrapped is MulticastDelegate)
         return new DynamicLuaFunction(state.GetFunction(name));
     else
         return wrapped;
 }
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:14,代码来源:LuaHelper.cs

示例3: IsBotTemplate

        private bool IsBotTemplate(string file)
        {
            LuaInterface.Lua lua = new LuaInterface.Lua();

            try
            {

                lua.DoFile(file);

                LuaFunction on_event = lua.GetFunction("OnEvent");

                if(on_event == null)
                    return false;

                return true;
            }
            catch (Exception e)
            {
                AppContext.WriteLog(e.Message);
                return false;
            }
        }
开发者ID:lythm,项目名称:orb3d,代码行数:22,代码来源:BotTemplateList.cs

示例4: cmdTreePhFolder_newFile_Click

        /// <summary>
        /// 新建文件
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void cmdTreePhFolder_newFile_Click(object sender, EventArgs e)
        {
            if (treePh.SelectedNode != null)
            {
                // 开始和lua交互
                string strFullPath = treePh.SelectedNode.FullPath;
                Lua plua = new Lua();
                object[] oRet = null;
                
                plua.DoString(DataBaseManager.GetDataBaseManager().GetScriptData(this.getFileIDsFromPath("Template")[0].ToString()));
                LuaFunction fun = plua.GetFunction("LoadParms");

                if (fun != null)
                {
                    object[] args = { strFullPath };
                    oRet = fun.Call(args);

                    if (oRet == null)
                    {
                        return;
                    }
                }                            
                
                string strControls = oRet[0] as string;

                // 孙韬返回的内容
                object[] strParms;

                // 文件名
                string strName = "";
                string[] asp1 = { "|" };
                ModelForm mf = new ModelForm(strControls.Split(asp1, StringSplitOptions.RemoveEmptyEntries));

                if (mf.ShowDialog() == DialogResult.OK)
                {
                    List<string> list = mf.InputList;

                    if (list.Count >= 2)
                    {
                        strParms = list.ToArray();
                        strName = strParms[1] as string;

                        string strCode = "";
                        fun = plua.GetFunction("LoadScript");

                        if (fun != null)
                        {
                            oRet = fun.Call(strParms);
                            strCode = oRet[0] as string;
                        }
                        else
                        {
                            return;
                        }                

                        // 交互完毕
                        if (string.IsNullOrEmpty(strName))
                        {
                            return;
                        }

                        if (CheckNodeExist(treePh.SelectedNode, strName))
                        {
                            MessageBox.Show("当前树结点已经存在!", "新建文件",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }

                        Hashtable infoTable = new Hashtable();
                        infoTable["type"] = "file";

                        // 存数据库
                        DataBaseManager dbm = DataBaseManager.GetDataBaseManager();
                        string strPath = treePh.SelectedNode.FullPath;
                        string[] asp = { "\\" };
                        string[] as_Path = strPath.Split(asp, StringSplitOptions.RemoveEmptyEntries);

                        if (as_Path.Length < 2 && as_Path[0] == "scripts")
                        {
                            MessageBox.Show("暂时不支持在其他地图以外的目录建文件", "新建文件", 
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        string id = dbm.CreateScriptData(string.Format("{0}\\{1}", strPath, strName));

                        if (id == null)
                        {
                            MessageBox.Show("新建文件失败!", "新建文件", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            // 新建成功,更新树缓存
                            treePh.Tag = dbm.GetScriptInformation();
//.........这里部分代码省略.........
开发者ID:viticm,项目名称:pap2,代码行数:101,代码来源:MainForm.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: processScript

 //won't passing a params object be equivalent to just passing array as first param? Can't have arbitrary amount of arguments when calling a method (in code) during runtime?
 public static void processScript(String script)
 {
     Lua lua = new Lua();
     lua[""] = "";
     lua.GetFunction("orz").Call();
 }
开发者ID:Zhangerr,项目名称:pulse,代码行数:7,代码来源:LuaScript.cs

示例7: Main

        static void Main(string[] args)
        {
            Helper helper = Helper.GetHelper();
            helper.RecordLogText("开始准备合并AIType.tab文件");
            string fileName = Path.Combine(Application.StartupPath, @"config.ini");

            if (File.Exists(fileName))
            {
                string content = helper.GetFileContent(fileName);
                IniStructure iniStructure = IniStructure.ReadIniWithContent(content);

                string rootPath = iniStructure.GetValue("General", "RootDirectory");
                string parameterCountString = iniStructure.GetValue("General", "ParameterCount");
                int parameterCount = int.Parse(parameterCountString);

                // 需要导出一张旧的AIType表作为中间文件
                fileName = Path.Combine(rootPath, @"settings\AIType.tab");
                content = helper.GetFileContent(fileName);
                
                StringBuilder defaultLine = new StringBuilder();
                defaultLine.Append("0\t");

                for (int i = 0; i < parameterCount; i++)
                {
                    defaultLine.Append(string.Format("{0}\t", iniStructure.GetValue("DefaultValue", string.Format("ParameterValue{0}", i))));
                }

                defaultLine.Remove(defaultLine.Length - 1, 1);

                string newContent = CreateNewAITypeContent(content, defaultLine.ToString());
                helper.SaveData(fileName, newContent);

                string mapCountString = iniStructure.GetValue("General", "MapCount");
                int mapCount = int.Parse(mapCountString);                   
                List<string> mapList = new List<string>();

                for (int i = 0; i < mapCount; i++)
                {
                    string mapEnable = iniStructure.GetValue("MapList", string.Format("Enable{0}", i));

                    if (mapEnable == "1")
                    {
                        mapList.Add(iniStructure.GetValue("MapList", string.Format("MapName{0}", i)));
                    }
                }

                try
                {
                    Lua lua = new Lua(); // lua虚拟机
                    string luaFile = Path.Combine(Application.StartupPath, "exportScript.lua");
                    lua.DoFile(luaFile);

                    LuaFunction function = lua.GetFunction("ExportAIData");
                    string filePath = Path.Combine(rootPath, @"settings\NpcTemplate.tab");
                    function.Call(filePath, mapList);

                    helper.RecordLogText("AIType.tab合并完成");
                }
                catch (Exception ex)
                {
                    helper.RecordLogText("合并AIType文件时产生异常:" + ex.Message);
                }               

                fileName = Path.Combine(Application.StartupPath, "log.txt");
                helper.SaveData(fileName, helper.LogText);
            }
            else
            {
                helper.RecordLogText(string.Format("配置文件{0}不存在", fileName));
            }            
        }
开发者ID:viticm,项目名称:pap2,代码行数:71,代码来源:Program.cs


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