marmalade / OpenQuick

Marmalade Open Quick
113 stars 24 forks source link

load lua files from apk #7

Open o-khotskin opened 11 years ago

o-khotskin commented 11 years ago

I'm trying to use OpenQuick with Android but get the runtime error: "Failed to load QConfig.lua file". Most likely, it is because 'luaL_loadfile' function can't load files from a apk archive.

timcloss commented 11 years ago

You are right. Lua uses standard C I/O functions like fopen(), fread(). Whilst these compile with the Android NDK, they can only open/read assets that have already been decompressed to somewhere on the device filesystem... they cannot read them directly from the compressed APK.

Your best bet is probably to write some Java code that decompresses the contents of the APK's resource folder to disk, then the Lua file operations should behave themselves.

e.g. Google "Android fopen", for discussions like this: http://stackoverflow.com/questions/1992953/file-operations-in-android-ndk

o-khotskin commented 11 years ago

I'm new in Android programming, but I think extracting apk's content to a disk is not good practice. May be it will be better if OpenQuick extracts lua files to the memory and then executes it.