A C++ wrapper around the GearLoader's api struct pointer.
More...
#include <gearLoader.hpp>
|
| | Api (GearLoaderApi *c_api, GearLoaderContext *ctx) |
| bool | VersionError () |
| template<typename ApiType> |
| int | RetrieveModApi (std::string name, std::string versionConstraint, const ApiType **pApi, SemanticVersion *retrievedVersion) |
| | Retrieves an exported API of another loaded mod.
|
| int | RegisterApi (const void *api, std::string name, SemanticVersion version) |
| | Registers an API with the mod loader.
|
| int | Log (LogLevel logLevel, std::string str) |
| | Logs the given string to the GearLoader.log file.
|
A C++ wrapper around the GearLoader's api struct pointer.
Handles version checks and type conversions.
◆ Api()
| GearLoader::Api::Api |
( |
GearLoaderApi * | c_api, |
|
|
GearLoaderContext * | ctx ) |
|
inline |
39: base(c_api), _ctx(ctx) { }
◆ Log()
| int GearLoader::Api::Log |
( |
LogLevel | logLevel, |
|
|
std::string | str ) |
|
inline |
Logs the given string to the GearLoader.log file.
Logs will be prefixed with a timestamp, a [DEBUG] label, and a [mod-name] label where "mod-name" is the calling mod's name provided in its config.json file.
- Parameters
-
| str | The string to be logged. |
- Returns
- An error code if an error occurred, otherwise 0.
109 {
111 return base->Log(_ctx, static_cast<uint32_t>(logLevel), str.c_str());
112 }
bool VersionError()
Definition gearLoader.hpp:44
◆ RegisterApi()
| int GearLoader::Api::RegisterApi |
( |
const void * | api, |
|
|
std::string | name, |
|
|
SemanticVersion | version ) |
|
inline |
Registers an API with the mod loader.
APIs are given by a generic pointer and expected to be reinterpreted by other mods that retrieve it. The registering mod still owns the underlying API struct and is expected to keep it alive for the duration of the application's lifetime. A mod may register multiple APIs differing by name and/or version. Registering a mod with the same name and version will not override the previous API and will result in an error.
- Parameters
-
| api | A pointer the the API struct to be registered. |
| name | The name of the registered API. This same name will need to be passed to RetrieveModApi. |
| version | The version of the registered API. Used when resolving the version constraint passed to RetrieveModApi. |
- Returns
- An error code if an error occurred, otherwise 0.
96 {
98 return base->RegisterApi(_ctx, api, name.c_str(), version);
99 }
◆ RetrieveModApi()
template<typename ApiType>
| int GearLoader::Api::RetrieveModApi |
( |
std::string | name, |
|
|
std::string | versionConstraint, |
|
|
const ApiType ** | pApi, |
|
|
SemanticVersion * | retrievedVersion ) |
|
inline |
Retrieves an exported API of another loaded mod.
To ensure the requested mod is installed and loaded, list it in your mod's config.json file.
- Parameters
-
| name | The name of the requested API. |
| versionConstraint | A constraint on the API version to retrieve. Takes the form of "[operator][semanticVersion]" where operator may be any of ["<", "<=", "=", ">=", ">"]. Examples: ">=0.1.0" or "1.0.0" |
| pApi | A pointer to a pointer variable that receives the API pointer. |
| retrievedVersion | A pointer to a SemanticVersion structure that receives version information of the received version. |
- Returns
- An error code if an error occurred, otherwise 0
65 {
67
68 const void* retApi;
69 int result = base->RetrieveModApi(
70 _ctx,
71 name.c_str(),
72 versionConstraint.c_str(),
73 &retApi,
74 retrievedVersion
75 );
76 *pApi = reinterpret_cast<const ApiType*>(retApi);
77 return result;
78 }
◆ VersionError()
| bool GearLoader::Api::VersionError |
( |
| ) |
|
|
inline |
Returns true if there is a difference in major version number between actual and expected GearLoader versions.
44 {
45 return (GEARLOADER_VERSION_NUM & 0xFF0000) != (base->version & 0xFF0000);
46 }
The documentation for this class was generated from the following file: