xLua——快速入门

作者:追风剑情 发布于:2017-7-15 16:13 分类:Lua

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using XLua;
  5.  
  6. public class Test1 : MonoBehaviour {
  7.  
  8. [XLua.CSharpCallLua]
  9. public delegate double LuaMax(double a, double b);
  10.  
  11. void Start () {
  12. //创建Lua虚拟机,建议创建一次重复使用。
  13. LuaEnv luaenv = new LuaEnv();
  14. //Lua调用C#函数
  15. luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
  16. //C#调用Lua函数
  17. var max = luaenv.Global.GetInPath<LuaMax>("math.max");
  18. Debug.Log("max:" + max(32, 12));
  19.  
  20. //释放绑定
  21. //Lua虚拟机在调用Dispose()前必须释放所有函数绑定,否则会报以下错:
  22. //InvalidOperationException: try to dispose a LuaEnv with C# callback!
  23. max = null;
  24.  
  25. //释放Lua虚拟机
  26. luaenv.Dispose();
  27. }
  28. }

运行测试

11111.png

标签: xLua

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号