Cocos2d-x Android operating environment io Lua script
Because android after installation package is installed, the file is stored in compressed form.
Therefore, in lua script, direct use io operations (such as: io.open, etc.) can not find the file (ios and windows platform no such problem).
The principle is called the lua CCString:createWithContentsOfFile
method, using c ++ code to open the file. Specific code:
local str = CCString:createWithContentsOfFile(CCFileUtils:sharedFileUtils():fullPathForFilename("config/config_skill.json")):getCString();
After release iteration, the code is as follows:
local path = 'res/config.json'
local fp = cc.FileUtils:getInstance():fullPathForFilename(path)
local content = CCString:createWithContentsOfFile(fp):getCString()