gpt4 book ai didi

java - 在java中执行lua脚本

转载 作者:行者123 更新时间:2023-12-02 01:19:33 26 4
gpt4 key购买 nike

我试图在 android studio 中执行一个 lua 脚本,为此我使用了 http://www.luaj.org/luaj/3.0/README.html 中的 Luaj 库。 ? .

String script = "assets/hello.lua";
Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.loadfile(script);
m.setText(chunk.call( LuaValue.valueOf(script) ).tojstring());

我使用了这个,我的lua文件在 Assets 中,我只是将print(“hello”)放入我的lua文件中,所以我应该在我的 TextView 中得到hello结果,但我总是在我的 TextView 中得到“nil”有没有任何解决方案?

最佳答案

print("hello") 打印“hello”,然后返回 nil。从 chunk.call 获得的值是 Lua 代码返回的值,而不是打印的值。

关于java - 在java中执行lua脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57964206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com