【发布时间】:2014-04-03 14:54:28
【问题描述】:
我正在尝试编译具有两个要调用并从中获取一些信息的函数的 Lua 代码,但是当我在 LuaValue 对象上使用 invokemethod 时,出现此错误
LuaError: 尝试索引? (一个函数值)
代码位于我为方便而创建的 LuaScript 类中
首先调用该方法编译文件
public void compile(File file) {
try {
Globals globals = JmePlatform.standardGlobals();
compiledcode = globals.load(new FileReader(file), "script");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
然后这用于从我的 lua 脚本中调用函数 getSameTiles
public Object invoke(String func, Object... parameters) {
if (parameters != null && parameters.length > 0) {
LuaValue[] values = new LuaValue[parameters.length];
for (int i = 0; i < parameters.length; i++)
values[i] = CoerceJavaToLua.coerce(parameters[i]);
return compiledcode.invokemethod(func, LuaValue.listOf(values));
} else
return compiledcode.invokemethod(func);
}
错误LuaError: attempt to index ? (a function value) 发生在return compiledcode.invokemethod(func); 行,其中"getSameTiles" 作为func 的字符串传递
这是我的 Lua 代码
function getSameTiles()
--My code here
end
【问题讨论】: