什么是luaj

luaj是一个Java的一个lua语言引擎,他可以让你在java上运行Lua代码。

在安卓中使用lua干嘛

lua代码可以用来书写布局,或者一些业务逻辑。

为什么要在安卓中使用代码

lua作为脚本语言可以很容易的进行热更新。也有很强的拓展性。

怎么在安卓用使用luaj

  • 添加依赖implementation group: 'org.luaj', name: 'luaj-jse', version: '3.0.1'
  • 创建类LuaLoader
final public class LuaLoader implements ResourceFinder {
    private Context context;
    private static Globals globals;
    public LuaLoader(Context context) {
        this.context = context;
        LuaLoader.globals = JsePlatform.standardGlobals();
        LuaLoader.globals.finder = this;
    }
    public Globals getGlobals(){
        return globals;
    }
    @Override
    public InputStream findResource(String filename) {
        try {
            return context.getAssets().open(filename);
        } catch (java.io.IOException ioe) {
            return null;
        }
    }

}
  • 之后我们可以
    • 通过LuaLoader.getGlobals.load()来加载字符串代码。
    • 通过LuaLoader.getGlobals.loadFile()来加载assets里面的代码。

<未完待续>

相关文章:

  • 2021-04-17
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-01-10
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2022-01-09
  • 2022-01-20
  • 2021-09-30
  • 2022-01-16
  • 2021-05-02
  • 2021-04-25
相关资源
相似解决方案