LuaSvr luaSvr;
luaSvr = new LuaSvr();
luaSvr.init(null, () =>
{
LuaState.main.loaderDelegate += LuaLoader;
// luaSvr.start("launcher");
});
//self =(LuaTable)luaSvr.start("launcher");
luaSvr.start("launcher");
object o = LuaSvr.mainState.getFunction("demo").call(1, 2, 3);//lua函数-》参数
//返回数组时处理
//object[] array = (object[])o;
//for (int n = 0; n < array.Length; n++)
// Debug.Log(array[n]);
//string s = (string)LuaSvr.mainState.getFunction("str").call(new object[0]);
Debug.Log(o);
private byte[] LuaLoader(string fn, ref string absoluteFn)
{
string path = Application.dataPath + "/lua/" + fn + ".lua";
byte[] data = null;
if (File.Exists(path))
{
data = File.ReadAllBytes(path);
}
else
{
TextAsset txt = Resources.Load<TextAsset>(fn);
}
return data;
}
launcher.lua文件
import "UnityEngine"
function main()
-- 创建Cube对象
local cube=UnityEngine.GameObject.CreatePrimitive(UnityEngine.PrimitiveType.Cube)
-- 获取transform组件上的position属性
local pos = cube.transform.position
pos.x = 10
-- 修改transform组件的position属性
cube.transform.position = pos
print("创建Cube对象")
end
function demo(a,b,c)
print("demo"..a..b..c)
end