i want to use “require” to import some other lua module. it should set package.path for require command. but how to get application bundle path? CCFileUtils class disappeared in the lua. i have no way to set package.path. how to solve it? Thanks in advance.
ok, you are right on android platform. but on the iOS platform i have no way to copy lua files to a appointed directory, like the directory “/data/data/” in the file CCFileUtils_android.cpp. but it is easy to get application bundle path. and of course, there is no problem to get lua file path on iOS path.
on the current version for iOS platform, no way to copy lua file, no way to get application boundle path, and no way to use require. so i think CCFileUtils is necessary for some platform.
Some developer said, in iOS, if your lua files are in the same directory. Then you can use require.
In Android, you can’t use it through you add a search path. Because all the lua files are packed in the apk.
it is a good way to modify script engine. if i can do this in lua code, it would be perfect. i don’t want to modify the engine code. it make upgrading cocos2d hard in furture. but for now, it seems i have no choice. thanks for your reply
lua_getglobal( d_state, "package" );
lua_getfield( d_state, -1, "path" ); // get field "path" from table at top of stack (-1)
const char* cur_path = lua_tostring( d_state, -1 ); // grab path string from top of stack
Has come up with a way of exposing a native fread/fopen directly from a zip using libzip to expose the APK file. Do you think its reasonable for us to patch loadlib.c to use this fread-in-zip approach to allow loading in the lua included files within android or is there a better / more obvious solution that I’m missing?
Hi,
I’m aware that this issue is quite old now, but I tried using the code in android to get the various lua files that reside in sub folders with no success using the latest cocos2dx version.
The addSearchPath although has the root folder in assets, does not make the rest of the lua files reach the other lua files follow the require path.