function f(a, b)
print('a', a, 'b', b)
return 1, {f1 = 1024}, 999, "hello,world"
end
有返回值4个
1——为函数的返回值
{f1=1024}——带出返回值table
999——带出返回值int
hello,world——带出返回值string
C#端代码:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XLua;
using System;
namespace Tutorial
{
public class CSCallLua : MonoBehaviour
{
LuaEnv luaenv = null;
public class DClass
{
public int f1;
public int f2;
}
[CSharpCallLua]
public delegate int FDelegate(int a, string b, out DClass c, ref int x, ref string y);
void Start()
{
luaenv = new LuaEnv();
TextAsset luaScript = Resources.Load<TextAsset>("hello");
luaenv.DoString(luaScript.text);
FDelegate f = luaenv.Global.Get<FDelegate>("f");
DClass d_ret;
int x = 0;
string y = string.Empty;
int f_ret = f(100, "John", out d_ret, ref x, ref y);
}
void OnDestroy()
{
luaenv.Dispose();
}
}
}