Android and iOS read Lua's search path (just copy others, not tested)

Source: Internet
Author: User
Tags lua

In the Lua language, the require statement search module has a built-in order and can be used package.path to maintain the module's search strategy.
But in Cocos2d-x, that 's not true!

The cocos2d-x overloaded the original LUA require loading mode. (See COCOS2DXLUALOADER.CPP)
The Cocos2dxlualoader logic is in effect before Package.path, and Package.path on Android does not handle the problem of loading the PKG package internal files very well.
So in actual use, we only use cocos2d-x overloaded method is possible.

How do you do it?

Cocos2dxlualoader internal is used CCFileUtils::getFileData() to load LUA code.
So if we want to add our own Lua script search path, we can just call CCFileUtils::addSearchPath() it.

The following C + + code is implemented on iOS and Android platforms, the program looks for LUA files from the Scripts folder under the download path, and then looks for the Lua file target from the Scripts folder under the program's built-in resource path.

#if(Cc_target_platform = = Cc_platform_ios)std::stringDownloadedscriptpath = Ccfileutils::sharedfileutils ()->getwritablepath () +"Scripts"; Ccfileutils::sharedfileutils ()-Addsearchpath (Downloadedscriptpath.c_str ()); STD::stringScriptPath = Ccfileutils::sharedfileutils ()->fullpathforfilename ("Scripts"); Ccfileutils::sharedfileutils ()-Addsearchpath (Scriptpath.c_str ());#elif(Cc_target_platform = = cc_platform_android)std::stringDownloadedscriptpath = Ccfileutils::sharedfileutils ()->getwritablepath () +"/scripts"; Ccfileutils::sharedfileutils ()-Addsearchpath (Downloadedscriptpath.c_str ()); Ccfileutils::sharedfileutils ()->addsearchpath ("assets/scripts");#elif(Cc_target_platform = = Cc_platform_win32)//TODO#else_error_#endif

Android and iOS read Lua's search path (just copy others, not tested)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.