C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System.IO;
using System.Text;
using UnityEngine.UI;
public class TestXLua : MonoBehaviour
{
LuaEnv lua;
void Start()
{
lua = new LuaEnv();
//加载Lua
lua.AddLoader(LoadLua);
lua.DoString("require 'TestLua'");
}
byte[] LoadLua(ref string file)
{
Debug.Log(file);
string slua = File.ReadAllText(Application.dataPath + "/Lua/" + file + ".lua");
byte[] bytes = new UTF8Encoding().GetBytes(slua);
return bytes;
}
void OnDestroy()
{
lua.Dispose();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
public class Player
{
public int PFunction(int a, out int b, ref int c)
{
Debug.Log("PFunction");
b = 25;
c = 36;
return a + 9;
}
}
Lua
player = CS.Player()
a = 1;
b = 2;
r1,r2,r3 = player:PFunction(a,b)
print("a:"..r1)
print("a:"..r2)
print("a:"..r3)