小编ner*_*and的帖子

使用luaj将参数传递给lua函数

我正在尝试使用LuaJ在Java程序中调用lua函数.当我没有向闭包传递任何参数时,它工作正常:

String script = "print 'Hello World!'";
InputStream input = new ByteArrayInputStream(script.getBytes());
Prototype prototype = LuaC.compile(input, "script");
LuaValue globals = JsePlatform.standardGlobals();
LuaClosure closure = new LuaClosure(prototype, globals);
closure.call();
Run Code Online (Sandbox Code Playgroud)

但是现在我正在尝试一个带有顶级函数的lua脚本,该函数接受一个参数而我无法弄清楚如何从Java中传入参数.这是我到目前为止所得到的:

String script = "function something(argument)\n"+
                            "test_string = 'Hello World!'\n"+
                            "print(test_string)\n"+
                            "print(argument)\n"+
                "end";

InputStream input = new ByteArrayInputStream(script.getBytes());
Prototype prototype = LuaC.compile(input, "script");
LuaValue globals = JsePlatform.standardGlobals();
LuaClosure closure = new LuaClosure(prototype, globals);
closure.invokemethod("something", CoerceJavaToLua.coerce("Foo"));
Run Code Online (Sandbox Code Playgroud)

这会导致invoke方法行出现异常:

org.luaj.vm2.LuaError:尝试索引?(函数值)

谢谢你的帮助!

java lua luaj

5
推荐指数
1
解决办法
2426
查看次数

libgdx 中 BoundingBox 和 Sphere 之间的碰撞检测

在我的 libgdx 游戏中,我有用于地图和玩家对象的 3D BoundingBox 和球体。我想计算它们是否相互碰撞,以便正确模拟这些物体的运动。我可以用什么方法来计算这些物体是否碰撞/相交?

java android collision-detection game-physics libgdx

3
推荐指数
1
解决办法
5092
查看次数

标签 统计

java ×2

android ×1

collision-detection ×1

game-physics ×1

libgdx ×1

lua ×1

luaj ×1