Luaj: 如何导入或要求Lua函数库

在Java中的LuaJ库,我想知道如何通过Java通过lua闭包来调用另一个lua函数脚本中的lua函数。例如,以下代码无法工作:

public static LuaValue runInputStreamLua(InputStream inputStream) throws Exception {
    Prototype luaScriptPrototype = LuaC.instance.compile(inputStream, "");
    Globals luaScriptStandardGlobals = JsePlatform.standardGlobals();
    luaScriptStandardGlobals.loadfile("mycoolmathfunctions.lua");
    LuaClosure luaClosure = new LuaClosure(luaScriptPrototype, luaScriptStandardGlobals);
    return luaClosure.call();
}

这里的输入流是指另一个lua脚本的内容:

import 'mycoolmathfunctions'
-- 或者,也许是require mycoolmathfunctions?

return sum({1, 2, 3})
-- 或者是mycoolmathfunctions.sum({1, 2, 3})?

我该怎么办?

点赞