Changeset - r27358:8ec8021bd4c2
[Not reviewed]
master
0 4 0
Rubidium - 16 months ago 2023-05-06 07:53:57
rubidium@openttd.org
Codechange: use std::string for script library category
4 files changed with 8 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_info.cpp
Show inline comments
 
@@ -126,17 +126,12 @@ bool AIInfo::CanLoadFromVersion(int vers
 
{
 
	if (version == -1) return true;
 
	return version >= this->min_loadable_version && version <= this->GetVersion();
 
}
 

	
 

	
 
AILibrary::~AILibrary()
 
{
 
	free(this->category);
 
}
 

	
 
/* static */ void AILibrary::RegisterAPI(Squirrel *engine)
 
{
 
	/* Create the AILibrary class, and add the RegisterLibrary function */
 
	engine->AddClassBegin("AILibrary");
 
	engine->AddClassEnd();
 
	engine->AddMethod("RegisterLibrary", &AILibrary::Constructor, 2, "tx");
 
@@ -151,13 +146,13 @@ AILibrary::~AILibrary()
 
	if (res != 0) {
 
		delete library;
 
		return res;
 
	}
 

	
 
	/* Cache the category */
 
	if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethodStrdup(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
 
	if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
 
		delete library;
 
		return SQ_ERROR;
 
	}
 

	
 
	/* Register the Library to the base system */
 
	library->GetScanner()->RegisterScript(library);
src/ai/ai_info.hpp
Show inline comments
 
@@ -53,14 +53,13 @@ private:
 
	std::string api_version;  ///< API version used by this AI.
 
};
 

	
 
/** All static information from an AI library like name, version, etc. */
 
class AILibrary : public ScriptInfo {
 
public:
 
	AILibrary() : ScriptInfo(), category(nullptr) {};
 
	~AILibrary();
 
	AILibrary() : ScriptInfo() {};
 

	
 
	/**
 
	 * Register the functions of this class.
 
	 */
 
	static void RegisterAPI(Squirrel *engine);
 

	
 
@@ -69,13 +68,13 @@ public:
 
	 */
 
	static SQInteger Constructor(HSQUIRRELVM vm);
 

	
 
	/**
 
	 * Get the category this library is in.
 
	 */
 
	const char *GetCategory() const { return this->category; }
 
	const std::string &GetCategory() const { return this->category; }
 

	
 
private:
 
	const char *category; ///< The category this library is in.
 
	std::string category; ///< The category this library is in.
 
};
 

	
 
#endif /* AI_INFO_HPP */
src/game/game_info.cpp
Show inline comments
 
@@ -96,17 +96,12 @@ bool GameInfo::CanLoadFromVersion(int ve
 
{
 
	if (version == -1) return true;
 
	return version >= this->min_loadable_version && version <= this->GetVersion();
 
}
 

	
 

	
 
GameLibrary::~GameLibrary()
 
{
 
	free(this->category);
 
}
 

	
 
/* static */ void GameLibrary::RegisterAPI(Squirrel *engine)
 
{
 
	/* Create the GameLibrary class, and add the RegisterLibrary function */
 
	engine->AddClassBegin("GSLibrary");
 
	engine->AddClassEnd();
 
	engine->AddMethod("RegisterLibrary", &GameLibrary::Constructor, 2, "tx");
 
@@ -121,13 +116,13 @@ GameLibrary::~GameLibrary()
 
	if (res != 0) {
 
		delete library;
 
		return res;
 
	}
 

	
 
	/* Cache the category */
 
	if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethodStrdup(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
 
	if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(*library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
 
		delete library;
 
		return SQ_ERROR;
 
	}
 

	
 
	/* Register the Library to the base system */
 
	library->GetScanner()->RegisterScript(library);
src/game/game_info.hpp
Show inline comments
 
@@ -45,14 +45,13 @@ private:
 
	std::string api_version;  ///< API version used by this Game.
 
};
 

	
 
/** All static information from an Game library like name, version, etc. */
 
class GameLibrary : public ScriptInfo {
 
public:
 
	GameLibrary() : ScriptInfo(), category(nullptr) {};
 
	~GameLibrary();
 
	GameLibrary() : ScriptInfo() {};
 

	
 
	/**
 
	 * Register the functions of this class.
 
	 */
 
	static void RegisterAPI(Squirrel *engine);
 

	
 
@@ -61,13 +60,13 @@ public:
 
	 */
 
	static SQInteger Constructor(HSQUIRRELVM vm);
 

	
 
	/**
 
	 * Get the category this library is in.
 
	 */
 
	const char *GetCategory() const { return this->category; }
 
	const std::string &GetCategory() const { return this->category; }
 

	
 
private:
 
	const char *category; ///< The category this library is in.
 
	std::string category; ///< The category this library is in.
 
};
 

	
 
#endif /* GAME_INFO_HPP */
0 comments (0 inline, 0 general)