纳金网

标题: LUA学习之与C#交互001 [打印本页]

作者: 王者再临    时间: 2014-9-24 22:21
标题: LUA学习之与C#交互001
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using LuaInterface;

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

  16.         private static Lua m_lua = new Lua();
  17.         public static void Init()
  18.         {
  19.             Program p = new Program();
  20.             m_lua.RegisterFunction("Print_Lua", p, p.GetType().GetMethod("Print_Csharp"));
  21.             m_lua.DoFile(@"C:\test.lua");
  22.         }

  23.         public void Print_Csharp(string s)
  24.         {
  25.             Console.WriteLine(s);
  26.         }
  27.         static void Main(string[] args)
  28.         {
  29.             Init();
  30.             m_lua.GetFunction("Show").Call();
  31.         }
  32.     }
  33. }
复制代码

作者: Kadina    时间: 2014-9-25 09:27
thanks for sharing




欢迎光临 纳金网 (http://www.narkii.com/club/) Powered by Discuz! X2.5