Projects > cpp > Issues > Refactor #1220

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

(gles20) Using CCString::stringWithContentsOfFile to get string from lua script files.

Refactor #1220 [Closed]
dumganhar 2012-05-04 03:23 . Updated over 4 years ago

Old method:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    unsigned long size;
    char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);

    if (pFileContent)
    {
        // copy the file contents and add '\0' at the end, or the lua parser can not parse it
        char *pCodes = new char[size + 1];
        pCodes[size] = '\0';
        memcpy(pCodes, pFileContent, size);
        delete[] pFileContent;

        pEngine->executeString(pCodes);
        delete []pCodes;
    }
#endif

New method:

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    CCString* pstrFileContent = CCString::stringWithContentsOfFile("hello.lua");
    if (pstrFileContent)
    {
       pEngine->executeString(pstrFileContent->getCString());
    }
#endif
dumganhar 2012-05-04 06:44
  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset commit:0b9ec253dca7c02815a3a0dc3e004a5876aa6906.

dumganhar 2012-05-04 06:44

Applied in changeset commit:2d4ab02269c4fa93bb77fc9dda81b212d6fc4094.

zhangxm 2012-05-23 03:56
  • Status changed from Resolved to Closed
walzer@cocos2d-x.org 2012-05-25 07:57
  • Project changed from cocos2d-x to cpp
  • Category deleted (2)
walzer@cocos2d-x.org 2012-05-25 07:58
  • Target version deleted (26)
walzer@cocos2d-x.org 2012-05-25 09:25
  • Target version set to cocos2d-2.0-rc0a-x-2.0

Atom PDF

Status:Closed
Start date:2012-05-04
Priority:Normal
Due date:
Assignee:dumganhar
% Done:

100%

Category:-
Target version:cocos2d-2.0-rc0a-x-2.0

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.