Refactor #1220

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

Added by James Chen about 1 year ago. Updated 12 months ago.

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

100%

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

Description

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

History

Updated by James Chen about 1 year ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset commit:0b9ec253dca7c02815a3a0dc3e004a5876aa6906.

Updated by James Chen about 1 year ago

Applied in changeset commit:2d4ab02269c4fa93bb77fc9dda81b212d6fc4094.

Updated by Minggo Zhang 12 months ago

  • Status changed from Resolved to Closed

Updated by Zhe Wang 12 months ago

  • Project changed from cocos2d-x to native
  • Category deleted (2)

Updated by Zhe Wang 12 months ago

  • Target version deleted (26)

Updated by Zhe Wang 12 months ago

  • Target version set to cocos2d-2.0-rc0a-x-2.0

Also available in: Atom PDF