当前位置:首页 > C#教程 > C#高级

Lua与C#的交互1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;

namespace LuaTest001
{
    /// <summary>
    /// 1.把LuaInterface.dll,Lua51.dll,luanet.dll放在exe文件里
    /// 2.引用LuaInterface.dll类库
    /// 3.在C#定义的函数和Lua同步的函数一定要注意命名,大小写和访问类型一定要一致,否则会出现报错(真的感觉坑爹)
    /// 4.导出的Unity文件,需要把1中的dll放在同级,在editor中,直接放入assert下面,引用就可以。
    /// </summary>
    class Program
    {

        private static Lua m_lua = new Lua();
        public static void Init()
        {
            Program p = new Program();
            m_lua.RegisterFunction("Print_Lua", p, p.GetType().GetMethod("Print_Csharp"));
            m_lua.DoFile(@"C:test.lua");
        }

        public void Print_Csharp(string s)
        {
            Console.WriteLine(s);
        }
        static void Main(string[] args)
        {
            Init();
            m_lua.GetFunction("Show").Call();
        }
    }
}

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!