ToLua 注入和获取lua变量
private string luaString = @"
	print(a)
	b = 'hello'
	c = {}
	c.id = 16485
	
	function test()
	print('hehe')
	end
";

// Use this for initialization
void Start () {
	LuaState lua = new LuaState ();
	lua.Start ();
	lua["a"] = "这是我C#传过去的";
	lua.DoString (luaString);
	Debug.Log (lua ["b"]);

	LuaTable t = lua ["c"] as LuaTable;
	Debug.Log (t.GetStringField("id"));
	t.Dispose ();

	LuaFunction func = lua ["test"] as LuaFunction;
	func.Call ();
	func.Dispose ();


	lua.CheckTop ();
	lua.Dispose ();
}

好像没什么好说的,都是通过LuaState 索引的形式设置和获取到变量,给予相应的类型


首页 我的博客
粤ICP备17103704号