您的位置:首页 > 编程语言 > Lua

Lua_ uLua_C#调用Lua方法_019

2017-09-09 10:30 507 查看
using UnityEngine;
using System.Collections;
using LuaInterface;

public class CallLuaFunction_01 : MonoBehaviour {

private string script = @"
function luaFunc(message)
print(message)
return 42
end
";

// Use this for initialization
void Start () {
LuaState l = new LuaState();

// First run the script so the function is created
l.DoString(script);

// Get the function object
LuaFunction f = l.GetFunction("luaFunc");

// Call it, takes a variable number of object parameters and attempts to interpet them appropriately
object[] r = f.Call("I called a lua function!");

// Lua functions can have variable returns, so we again store those as a C# object array, and in this case print the first one
print(r[0]);
}

// Update is called once per frame
void Update () {

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: