java - LuaJ:超过3个参数

时间:2015-03-04 14:41:27

标签: java luaj

在lua函数中是否有可能使用三个以上的参数?

这是我的代码:

LuaValue luaGlobals = JsePlatform.standardGlobals();
            luaGlobals.get("dofile").call(LuaValue.valueOf("./data/Actions/" + a_itemScript));

            LuaValue luaValLevel = CoerceJavaToLua.coerce(a_level);
            LuaValue luaValPlayer = CoerceJavaToLua.coerce(a_player);
            LuaValue luaValItem = CoerceJavaToLua.coerce(a_thing);
            LuaValue luaValItemX = CoerceJavaToLua.coerce(a_fromX);
            LuaValue luaValItemY = CoerceJavaToLua.coerce(a_fromY);

            LuaValue luaOnUse = luaGlobals.get("onUse");

            if(!luaOnUse.isnil())
            {
                luaOnUse.call(luaValLevel, luaValItemX, luaValItemY);
            }
            else
            {
                a_parent.WriteInConsole("\nx Cannot Run Script: " + a_itemScript);
            }

1 个答案:

答案 0 :(得分:0)

使用LuaValue.invoke()而不是LuaValue.call()。它需要一个包含任意数量参数的Varargs,并返回包含所有返回值的Varargs:

Varargs results = luaOnUse.invoke(
    LuaValue.varargsOf(new LuaValue[] { 
        luaValLevel, luaValPlayer, luaValItem, luaValItemX, luaValItemY }));