一:LuaInteractface 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)
https://www.cnblogs.com/sundajade/articles/3735663.html
解决:参考以上链接。
设置vs的目标平台为x86即可。
二:基本的lua和c#交互参考:
https://www.cnblogs.com/sifenkesi/p/3901831.html
https://blog.csdn.net/qq_26413641/article/details/54575210
三:Lua Dostring返回object[] 输出是Double类型,如输出int需要转换下。
static void Main(string[] args) { Lua test = new Lua(); test["a"] = 1; object[] v = test.DoString("return 1"); foreach(object item in v) { Console.WriteLine(Convert.ChangeType(item, typeof(int))); Console.WriteLine(item.GetType()); } }
思考:Unable to cast object of type 'System.Double' to type 'System.Int32
类型之间的强制转换不能跳跃。 实际为double的object不能直接用(int)val 需要Convert.ChangeType(item, typeof(int))
举例子:如下,注释的可运行,object a的报错Unable to cast object of type 'System.Double' to type 'System.Int32
static void Main(string[] args)
{
Lua test = new Lua();
//System.Double a = 1.00;
object a = 1.00;
Console.WriteLine((int)a);
}
=============实际项目 xlua C# 思考
1. C# Action 函数尽量写短些
2.C# 函数传参 尽量传整个class的引用 而不是其中的某个值 C#类中尽量用 变量生命类 缓存可能以后要用的数据
3.C# 技能等类, 提供个 可给xlua调用的、测试过的、简单的,流程通的 填坑类