本文共 1743 字,大约阅读时间需要 5 分钟。
之前需要引用luainterface.dll,luanet.dll。
c#注册进lua的全局方法
[C#] 纯文本查看 复制代码
static void Main(string[] args) { Lua lua = new Lua(); Program obj = new Program();//把一个类中的普通方法注册进去 lua.RegisterFunction("NormalMethod", obj, obj.GetType().GetMethod("NormalMethod")); lua.DoString("NormalMethod()");//把一个类中的普通方法注册进去 lua.RegisterFunction("MyStaticMethod", null, typeof(Program).GetMethod("MyStaticMethod")); lua.DoString("MyStaticMethod()"); Console.ReadLine(); } public void NormalMethod() {Console.WriteLine("wahaha"); } public static void MyStaticMethod() { Console.WriteLine("static"); }C#中执行lua代码和脚本
[C#] 纯文本查看 复制代码
Lua lua = new Lua();//在c#中lua代码lua.DoString("num=2"); lua.DoString("name='YDL'"); lua.DoString("flag=true"); object[] values= lua.DoString("return num,name,flag"); foreach(object obj in values) { Console.WriteLine(obj); }//在c#中执行lua脚本 lua.DoFile("helloword.lua"); Console.ReadLine();LUA脚本中的代码
[C++] 纯文本查看 复制代码
print("hello!")C#中执行lua脚本,lua脚本调用c#中的方法 lua脚本中的代码
[AppleScript] 纯文本查看 复制代码
require "luanet"luanet.load_assembly("testLuainterface")--testLuainterface是命名空间Program=luanet.import_type("testLuainterface.Program")program1=Program()s=program1:TestOut("ydl")print(s)c#中的代码
[AppleScript] 纯文本查看 复制代码
static void Main(string[] args) { Lua lua = new Lua(); lua.DoFile("helloword.lua"); Console.ReadLine(); } public int TestOut(string name) { return name.Length; }从siki老师的热更新里面学到的~~~~~
转载地址:http://nwrdz.baihongyu.com/