Load files in C++ (Android extension)

I have mentioned this in slack chat before. I am adding a functionality to the hx-lua library to allow using Lua’s luaL_dofile function to load a Lua script file. On desktop it worked fine but on Android seems that the whole application is being compressed in the apk so the C++ code cannot access the file by the given filename. Joshua you have mentioned that I should use some Java API to uncompress the apk like what Lime does. Would you please point me to the source code of such functionality in the Lime library please?

Could you use the ByteArray APIs to load the file into memory, and then pass it into your native script?

The Lua C API provides a function luaL_dofile that accepts a file path as argument. And it will load other Lua files if there are dependencies. So I think loading the file into memory is not a viable option for this specific problem.

Instead, I came across this post telling that I can override the fopen function in C such that the whole thing will work fine in Android environment. But that leads to another problem, how can I get the assetManager object in ExternalInterface.cpp? [Reference (android)] (http://stackoverflow.com/questions/10941802/cant-access-aassetmanager-in-native-code-passed-from-java-in-wallpaperservice)

I would like to know how Lime handle files in android but I cannot find the relevant codes in Github. I appreciate if anyone could point me to the relevant source codes.

Edit: found the code here

Is it possible to link to the cpp file in lime when writing ExternalInterface.cpp?

Maybe you could use luaL_dostring and call it a day? :slight_smile:

var string = Assets.getText (“my.lua”);
my_lua_extension (string);

Inside a .lua file it may refer to other .lua files by require "some/other/module" so eventually it is going to use file path to open files.

So are there no way to link to the cpp files in lime? Seems that if I can link to this file I can get the android asset manager in cpp. https://github.com/openfl/lime/blob/e511c0d2a5d616081a7826416d111aff1d428025/legacy/project/src/android/AndroidCommon.cpp

It would be easier to try and do that by editing the core, rather than doing an external extension