lua api compatible

This commit is contained in:
halx99 2021-01-09 18:32:22 +08:00
parent abc87f8cd5
commit f771a92ca2
3 changed files with 46 additions and 22 deletions

View File

@ -208,14 +208,12 @@ void GUIReader::registerTypeAndCallBack(const std::string& classType,
Widget* GUIReader::widgetFromJsonFile(const char *fileName)
{
auto thiz = GUIReader::getInstance();
std::string jsonpath;
rapidjson::Document jsonDict;
jsonpath = fileName;
// jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
size_t pos = jsonpath.find_last_of('/');
thiz->m_strFilePath = jsonpath.substr(0,pos+1);
m_strFilePath = jsonpath.substr(0,pos+1);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
jsonDict.Parse<0>(contentStr.c_str());
if (jsonDict.HasParseError())
@ -227,22 +225,22 @@ Widget* GUIReader::widgetFromJsonFile(const char *fileName)
WidgetPropertiesReader * pReader = nullptr;
if (fileVersion)
{
int versionInteger = thiz->getVersionInteger(fileVersion);
int versionInteger = this->getVersionInteger(fileVersion);
if (versionInteger < 250)
{
pReader = new (std::nothrow) WidgetPropertiesReader0250();
widget = pReader->createWidget(jsonDict, thiz->m_strFilePath.c_str(), fileName);
widget = pReader->createWidget(jsonDict, this->m_strFilePath.c_str(), fileName);
}
else
{
pReader = new (std::nothrow) WidgetPropertiesReader0300();
widget = pReader->createWidget(jsonDict, thiz->m_strFilePath.c_str(), fileName);
widget = pReader->createWidget(jsonDict, this->m_strFilePath.c_str(), fileName);
}
}
else
{
pReader = new (std::nothrow) WidgetPropertiesReader0250();
widget = pReader->createWidget(jsonDict, thiz->m_strFilePath.c_str(), fileName);
widget = pReader->createWidget(jsonDict, this->m_strFilePath.c_str(), fileName);
}
CC_SAFE_DELETE(pReader);
@ -366,14 +364,12 @@ WidgetReaderProtocol* WidgetPropertiesReader::createWidgetReaderProtocol(const s
Widget* GUIReader::widgetFromBinaryFile(const char *fileName)
{
auto thiz = GUIReader::getInstance();
std::string jsonpath;
rapidjson::Document jsonDict;
jsonpath = fileName;
// jsonpath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
size_t pos = jsonpath.find_last_of('/');
thiz->m_strFilePath = jsonpath.substr(0,pos+1);
m_strFilePath = jsonpath.substr(0,pos+1);
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
auto fileData = FileUtils::getInstance()->getDataFromFile(fullPath);
auto fileDataBytes = fileData.getBytes();
@ -406,7 +402,7 @@ Widget* GUIReader::widgetFromBinaryFile(const char *fileName)
WidgetPropertiesReader * pReader = nullptr;
if (fileVersion)
{
int versionInteger = thiz->getVersionInteger(fileVersion);
int versionInteger = this->getVersionInteger(fileVersion);
if (versionInteger < 250)
{
CCASSERT(0, "You current studio doesn't support binary format, please upgrade to the latest version!");

View File

@ -1,4 +1,4 @@
/****************************************************************************
/****************************************************************************
Copyright (c) 2013-2017 Chukong Technologies Inc.
http://www.cocos2d-x.org
@ -62,9 +62,9 @@ public:
static GUIReader* getInstance();
static void destroyInstance();
static cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
cocos2d::ui::Widget* widgetFromJsonFile(const char* fileName);
static cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
cocos2d::ui::Widget* widgetFromBinaryFile(const char* fileName);
int getVersionInteger(const char* str);
/**

View File

@ -14941,73 +14941,101 @@ int lua_cocos2dx_studio_GUIReader_destroyInstance(lua_State* tolua_S)
int lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile(lua_State* tolua_S)
{
int argc = 0;
cocostudio::GUIReader* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"ccs.GUIReader",0,&tolua_err)) goto tolua_lerror;
if (!tolua_isusertype(tolua_S,1,"ccs.GUIReader",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocostudio::GUIReader*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
const char* arg0;
std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "ccs.GUIReader:widgetFromBinaryFile"); arg0 = arg0_tmp.c_str();
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile'", nullptr);
return 0;
}
cocos2d::ui::Widget* ret = cocostudio::GUIReader::widgetFromBinaryFile(arg0);
cocos2d::ui::Widget* ret = cobj->widgetFromBinaryFile(arg0);
object_to_luaval<cocos2d::ui::Widget>(tolua_S, "ccui.Widget",(cocos2d::ui::Widget*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.GUIReader:widgetFromBinaryFile",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_GUIReader_widgetFromBinaryFile'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_studio_GUIReader_widgetFromJsonFile(lua_State* tolua_S)
{
int argc = 0;
cocostudio::GUIReader* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"ccs.GUIReader",0,&tolua_err)) goto tolua_lerror;
if (!tolua_isusertype(tolua_S,1,"ccs.GUIReader",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocostudio::GUIReader*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_GUIReader_widgetFromJsonFile'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
const char* arg0;
std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "ccs.GUIReader:widgetFromJsonFile"); arg0 = arg0_tmp.c_str();
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_GUIReader_widgetFromJsonFile'", nullptr);
return 0;
}
cocos2d::ui::Widget* ret = cocostudio::GUIReader::widgetFromJsonFile(arg0);
cocos2d::ui::Widget* ret = cobj->widgetFromJsonFile(arg0);
object_to_luaval<cocos2d::ui::Widget>(tolua_S, "ccui.Widget",(cocos2d::ui::Widget*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.GUIReader:widgetFromJsonFile",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_GUIReader_widgetFromJsonFile'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_studio_GUIReader_getInstance(lua_State* tolua_S)