ulua與unity互傳陣列
阿新 • • 發佈:2019-02-03
using UnityEngine; using System.Collections; using LuaInterface; using System; public class LuaTest : MonoBehaviour { private string lua = @" --定義一個函式 function luaFunc(objs, len) for i = 0, len - 1 do print(objs[i]) end --返回一個列表 local table1 = {'111', '222', '333'} return table1 end "; string[] objs = { "aaa", "bbb", "ccc" }; void Start () { LuaScriptMgr luaMgr = new LuaScriptMgr(); LuaState luaState = luaMgr.lua; luaState.DoString(lua); //呼叫lua的函式獲取返回值 LuaFunction f = luaState.GetFunction("luaFunc"); object[] rs = f.Call(objs, objs.Length); //輸出lua的返回值 LuaTable table = rs[0] as LuaTable; foreach (DictionaryEntry de in table) { Debug.Log(de.Value); } } }