Q1:
Can I put lua code in directoy different assets?
Q2:
I cannot get table arg that stores arguments in function. Is cocos2dx modify lua?
local cclog = function(…)
print(type(arg))
end
the result is: nil
Q3:
Can I use functions such as dofile, loadfile to get lua code chunk? It seems fail to because they are packed in apk file.
Answers for
Q1:
Sure, just add the directory to FileUtils’s search path by cc.FileUtils:getInstance():addSearchPath( … ) in lua or FileUtils::getInstance()->addSearchPath(…) in AppDelegate.cpp .
Q2:
it is lua 5.1.x change. you can get the args in this way
local cclog = function(…)
local args = {…}
for _, arg in ipairs(args) do
print(arg)
end
end
Q3:
absolutely.
eg.
local luaString = cc.FileUtils:getInstance():getStringFromFile(‘my.lua’)
local chunk = loadstring(luaString)
chunk()
@edwardzhou
Q2 is ok
Q1:
if you rename assets to “mydir” and add to search path, the file cannot be found. i noticed that var m_strDefaultResRootPath is defined to be “assets”. is it the reason for that?
Q3:
there is no cc.FileUtils:getInstance():getStringFromFile. can it only be used js?
thanks for your kindness.
Thank you for edwardzhou.
@windfree,which version did you use?
@samuele3hu Sorry for replying util today.
the version is cocos2d-x-2.2.2 and android-ndk-r9d. I notice that url given by @edwardzhou is V3.0beta2.