mirror of https://github.com/axmolengine/axmol.git
debugging lua code in package support
This commit is contained in:
parent
52780dff28
commit
9fefad5f35
|
@ -52,7 +52,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
if(!glview) {
|
||||
Size viewSize = ConfigParser::getInstance()->getInitViewSize();
|
||||
string title = ConfigParser::getInstance()->getInitViewName();
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) && (COCOS2D_DEBUG > 0 && CC_CODE_IDE_DEBUG_SUPPORT > 0)
|
||||
extern void createSimulator(const char* viewName, float width, float height, bool isLandscape = true, float frameZoomFactor = 1.0f);
|
||||
bool isLanscape = ConfigParser::getInstance()->isLanscape();
|
||||
createSimulator(title.c_str(),viewSize.width,viewSize.height, isLanscape);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "json/stringbuffer.h"
|
||||
#include "json/writer.h"
|
||||
#include "ConfigParser.h"
|
||||
#include "FileServer.h"
|
||||
|
||||
#define CONFIG_FILE "config.json"
|
||||
#define CONSOLE_PORT 6010
|
||||
|
@ -30,8 +31,22 @@ void ConfigParser::purge()
|
|||
|
||||
void ConfigParser::readConfig()
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// add writable path to search path temporarily for reading config file
|
||||
vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths();
|
||||
searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath());
|
||||
FileUtils::getInstance()->setSearchPaths(searchPathArray);
|
||||
#endif
|
||||
|
||||
// read config file
|
||||
string fullPathFile = FileUtils::getInstance()->fullPathForFilename(CONFIG_FILE);
|
||||
string fileContent = FileUtils::getInstance()->getStringFromFile(fullPathFile);
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// revert search path
|
||||
searchPathArray.erase(searchPathArray.end() - 1);
|
||||
FileUtils::getInstance()->setSearchPaths(searchPathArray);
|
||||
#endif
|
||||
|
||||
if(fileContent.empty())
|
||||
return;
|
||||
|
|
|
@ -162,7 +162,7 @@ void ConsoleCommand::onSendCommand(int fd, const std::string &args)
|
|||
if(strcmp(strcmd.c_str(), "start-logic") == 0)
|
||||
{
|
||||
char szDebugArg[1024] = {0};
|
||||
sprintf(szDebugArg, "require('debugger')(%s,'%s')",dArgParse["debugcfg"].GetString(), _fileserver->getWritePath().c_str());
|
||||
sprintf(szDebugArg, "require('debugger')(%s,'%s')",dArgParse["debugcfg"].GetString(), "");
|
||||
startScript(szDebugArg);
|
||||
dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator());
|
||||
|
||||
|
@ -255,7 +255,7 @@ void ConsoleCommand::onSendCommand(int fd, const std::string &args)
|
|||
}
|
||||
|
||||
dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
|
||||
}else if(strcmp(strcmd.c_str(),"shutdownapp")==0)
|
||||
} else if(strcmp(strcmd.c_str(), "shutdownapp") == 0)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
extern void shutDownApp();
|
||||
|
@ -263,7 +263,7 @@ void ConsoleCommand::onSendCommand(int fd, const std::string &args)
|
|||
#else
|
||||
exit(0);
|
||||
#endif
|
||||
} else if(strcmp(strcmd.c_str(),"getplatform") == 0)
|
||||
} else if(strcmp(strcmd.c_str(), "getplatform") == 0)
|
||||
{
|
||||
string platform="UNKNOW";
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
|
@ -280,6 +280,18 @@ void ConsoleCommand::onSendCommand(int fd, const std::string &args)
|
|||
platformValue.SetString(platform.c_str(), dReplyParse.GetAllocator());
|
||||
bodyvalue.AddMember("platform", platformValue, dReplyParse.GetAllocator());
|
||||
dReplyParse.AddMember("body", bodyvalue, dReplyParse.GetAllocator());
|
||||
dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator());
|
||||
} else if(strcmp(strcmd.c_str(), "usewritablepath") == 0)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// only iOS and Android need to open using write path by Code IDE
|
||||
FileServer::getShareInstance()->setIsUsingWritePath(true);
|
||||
|
||||
std::vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths();
|
||||
searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath());
|
||||
FileUtils::getInstance()->setSearchPaths(searchPathArray);
|
||||
#endif
|
||||
|
||||
dReplyParse.AddMember("code", 0, dReplyParse.GetAllocator());
|
||||
}
|
||||
|
||||
|
|
|
@ -228,6 +228,13 @@ _writeEndThread(false),
|
|||
_responseRunning(false),
|
||||
_responseEndThread(false)
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
// need to be opened by Code IDE
|
||||
_isUsingWritePath = false;
|
||||
#else
|
||||
_isUsingWritePath = true;
|
||||
#endif
|
||||
|
||||
_writePath = FileUtils::getInstance()->getWritablePath();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
void addResFileInfo(const char* filename,uint64_t u64);
|
||||
void removeResFileInfo(const char *filename);
|
||||
rapidjson::Document* getFileCfgJson() { return &_filecfgjson; }
|
||||
bool getIsUsingWritePath() { return _isUsingWritePath; }
|
||||
void setIsUsingWritePath(bool use) { _isUsingWritePath = use; }
|
||||
std::string getWritePath() { return _writePath; }
|
||||
std::string getTransingFileName();
|
||||
void setTransingFileName(const std::string& filename);
|
||||
|
@ -124,6 +126,7 @@ private:
|
|||
std::string _recvErrorFile;
|
||||
std::string _writeErrorFile;
|
||||
|
||||
bool _isUsingWritePath;
|
||||
std::string _writePath;
|
||||
};
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ std::string& replaceAll(std::string& str, const std::string& old_value, const st
|
|||
|
||||
const char* getRuntimeVersion()
|
||||
{
|
||||
return "1.5";
|
||||
return "1.6";
|
||||
}
|
||||
|
||||
int lua_cocos2dx_runtime_addSearchPath(lua_State* tolua_S)
|
||||
|
@ -134,24 +134,30 @@ int lua_cocos2dx_runtime_addSearchPath(lua_State* tolua_S)
|
|||
|
||||
ok &= luaval_to_std_string(tolua_S, 2,&arg0);
|
||||
|
||||
if (argc == 2) {
|
||||
if (argc == 2)
|
||||
{
|
||||
ok &= luaval_to_boolean(tolua_S, 3, &arg1);
|
||||
}
|
||||
|
||||
if(!ok)
|
||||
return 0;
|
||||
std::string originPath = arg0;
|
||||
if (!FileUtils::getInstance()->isAbsolutePath(originPath))
|
||||
arg0 = FileServer::getShareInstance()->getWritePath() + originPath;
|
||||
cobj->addSearchPath(arg0, arg1);
|
||||
|
||||
if (!FileUtils::getInstance()->isAbsolutePath(originPath))
|
||||
if (! FileUtils::getInstance()->isAbsolutePath(arg0))
|
||||
{
|
||||
// add write path to search path
|
||||
if (FileServer::getShareInstance()->getIsUsingWritePath())
|
||||
{
|
||||
cobj->addSearchPath(FileServer::getShareInstance()->getWritePath() + arg0, arg1);
|
||||
} else
|
||||
{
|
||||
cobj->addSearchPath(arg0, arg1);
|
||||
}
|
||||
|
||||
#if(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
cobj->addSearchPath(g_projectPath + originPath, arg1);
|
||||
#endif
|
||||
#if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
cobj->addSearchPath(originPath, arg1);
|
||||
// add project path to search path
|
||||
cobj->addSearchPath(g_projectPath + arg0, arg1);
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "addSearchPath",argc, 1);
|
||||
|
@ -193,9 +199,9 @@ int lua_cocos2dx_runtime_setSearchPaths(lua_State* tolua_S)
|
|||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 1)
|
||||
{
|
||||
std::vector<std::string> vecPaths;
|
||||
std::vector<std::string> vecPaths, writePaths;
|
||||
|
||||
ok &= luaval_to_std_vector_string(tolua_S, 2,&vecPaths);
|
||||
ok &= luaval_to_std_vector_string(tolua_S, 2, &vecPaths);
|
||||
if(!ok)
|
||||
return 0;
|
||||
std::vector<std::string> originPath; // for IOS platform.
|
||||
|
@ -205,16 +211,23 @@ int lua_cocos2dx_runtime_setSearchPaths(lua_State* tolua_S)
|
|||
if (!FileUtils::getInstance()->isAbsolutePath(vecPaths[i]))
|
||||
{
|
||||
originPath.push_back(vecPaths[i]); // for IOS platform.
|
||||
projPath.push_back(g_projectPath+vecPaths[i]); //for Desktop platform.
|
||||
vecPaths[i] = FileServer::getShareInstance()->getWritePath() + vecPaths[i];
|
||||
projPath.push_back(g_projectPath + vecPaths[i]); //for Desktop platform.
|
||||
writePaths[i] = FileServer::getShareInstance()->getWritePath() + vecPaths[i];
|
||||
}
|
||||
}
|
||||
vecPaths.clear();
|
||||
|
||||
#if(CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
vecPaths.insert(vecPaths.end(),projPath.begin(),projPath.end());
|
||||
#endif
|
||||
#if(CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
vecPaths.insert(vecPaths.end(),originPath.begin(),originPath.end());
|
||||
vecPaths.insert(vecPaths.end(), projPath.begin(), projPath.end());
|
||||
#endif
|
||||
if (FileServer::getShareInstance()->getIsUsingWritePath())
|
||||
{
|
||||
vecPaths.insert(vecPaths.end(), writePaths.begin(), writePaths.end());
|
||||
} else
|
||||
{
|
||||
vecPaths.insert(vecPaths.end(), originPath.begin(), originPath.end());
|
||||
}
|
||||
|
||||
cobj->setSearchPaths(vecPaths);
|
||||
return 0;
|
||||
}
|
||||
|
@ -242,28 +255,26 @@ static void register_runtime_override_function(lua_State* tolua_S)
|
|||
|
||||
void initRuntime()
|
||||
{
|
||||
vector<string> searchPathArray = FileUtils::getInstance()->getSearchPaths();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
// add peoject's root directory to search path
|
||||
if (g_projectPath.empty())
|
||||
{
|
||||
extern std::string getCurAppPath();
|
||||
string appPath = getCurAppPath();
|
||||
vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths();
|
||||
|
||||
extern std::string getCurAppPath();
|
||||
std::string appPath = getCurAppPath();
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
appPath.append("/../../");
|
||||
appPath.append("/../../");
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
appPath.append("/../../../");
|
||||
appPath.append("/../../../");
|
||||
#endif
|
||||
appPath = replaceAll(appPath, "\\", "/");
|
||||
g_projectPath = appPath;
|
||||
}
|
||||
appPath = replaceAll(appPath, "\\", "/");
|
||||
g_projectPath = appPath;
|
||||
|
||||
// add project's root directory to search path
|
||||
searchPathArray.insert(searchPathArray.begin(), g_projectPath);
|
||||
#endif
|
||||
|
||||
// add writable path to search path
|
||||
searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath());
|
||||
FileUtils::getInstance()->setSearchPaths(searchPathArray);
|
||||
#endif
|
||||
|
||||
auto engine = LuaEngine::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
||||
|
|
Loading…
Reference in New Issue