有谁知道如何编写一个返回 LuaTable 值的 C# 函数(例如 {1 = "example1", 2 = 234, "foo" = "Foo Example"}
我测试过的所有类型都返回非配对/ipairable 的 LuaUserData 值。
提前致谢。

- 更新 -
在我看来,最接近 luaTable 的类型是 ListDictionary:

        [LuaFunc(Name = "table", Desc = "returns test LuaTable", Params = new string[] { })]
    public System.Collections.Specialized.ListDictionary table()
    {
        var k = new System.Collections.Specialized.ListDictionary(){
            {"1",1},
            {2,"2"}
        };

        return k;
    }

但它在 Lua 中仍然被识别为 LuaUserData 并且不能配对/ipaired

最佳答案

这个问题有两种可能的解决方案。

第一个是,让 Lua 返回表:

LuaTable lt = (LuaTable) lua.DoString("return {1 = "example1", 2 = 234, "foo" = "Foo Example"}")[0];

第二种可能是创建一个新表
LuaTable lt = lua.NewTable("ThisTable")
lt["1"] = "example1"
lt["2"] = 234
lt["foo"] = "Foo Example"

您可以通过 Lua 访问第二个表
ThisTable[1] = ThisTable["foo"]

关于c# - LuaInterface - 一个返回 LuaTable 值的函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14299634/

10-13 07:06