查看: 1560|回复: 1
打印 上一主题 下一主题

[其他] LUA学习之与C#交互001

[复制链接]

2317

主题

54

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
20645
精华
62

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2014-9-24 22:21:52 |只看该作者 |倒序浏览
  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. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

0

主题

2

听众

4092

积分

中级设计师

Rank: 5Rank: 5

纳金币
530
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2014-9-25 09:27:49 |只看该作者
thanks for sharing
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-5-21 13:42 , Processed in 0.056836 second(s), 27 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部