Implements CInterface core, C Interface for LibrarySettings.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-14 16:36:54 +02:00
parent 24245957a5
commit 2ab9445b71
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 59 additions and 4 deletions

4
CInterface/Core.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "Core.hpp"
std::string ExceptionHandler::_lastException = "";
export const char* PkmnLib_GetLastException() { return ExceptionHandler::GetLastException(); }

29
CInterface/Core.hpp Normal file
View File

@ -0,0 +1,29 @@
#ifndef PKMNLIB_CORE_HPP
#define PKMNLIB_CORE_HPP
#include <cstring>
#include <exception>
#include <string>
#define export extern "C"
// CreatureLibException is 1, so use 2.
#define PkmnLibException 2
class ExceptionHandler {
static std::string _lastException;
public:
static void SetLastException(const std::exception& e) { _lastException = std::string(e.what()); }
static const char* GetLastException() { return _lastException.c_str(); }
};
#define Try(data) \
try { \
data; \
return 0; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(e); \
return PkmnLibException; \
}
#endif // PKMNLIB_CORE_HPP

View File

@ -0,0 +1,16 @@
#include "../../src/Library/LibrarySettings.hpp"
#include "../Core.hpp"
using namespace PkmnLib::Library;
export const LibrarySettings* PkmnLib_LibrarySettings_Construct(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate) {
return new LibrarySettings(maximalLevel, maximalMoves, shinyRate);
}
export void PkmnLib_LibrarySettings_Destruct(const LibrarySettings* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType PkmnLib_##type##_##name(const PkmnLib::Library::type* p) { return p->name(); }
SIMPLE_GET_FUNC(LibrarySettings, GetShinyRate, uint16_t);
#undef SIMPLE_GET_FUNC

View File

@ -56,6 +56,11 @@ SET(FILE_SOURCE
"src/Battling/*.hpp" "src/Battling/*.hpp"
"src/Library/*.cpp" "src/Library/*.cpp"
"src/Library/*.hpp" "src/Library/*.hpp"
"CInterface/Core.*"
"CInterface/Library/*.cpp"
"CInterface/Library/*.hpp"
"CInterface/Battling/*.cpp"
"CInterface/Battling/*.hpp"
) )
if (SCRIPT_PROVIDER STREQUAL "angelscript") if (SCRIPT_PROVIDER STREQUAL "angelscript")
SET(FILE_SOURCE ${FILE_SOURCE} SET(FILE_SOURCE ${FILE_SOURCE}
@ -63,6 +68,8 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript")
"src/ScriptResolving/AngelScript/*.hpp" "src/ScriptResolving/AngelScript/*.hpp"
"extern/angelscript_addons/*.cpp" "extern/angelscript_addons/*.cpp"
"extern/angelscript_addons/*.h" "extern/angelscript_addons/*.h"
"CInterface/AngelScript/*.cpp"
"CInterface/AngelScript/*.hpp"
) )
ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1) ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1)
endif() endif()

View File

@ -8,10 +8,10 @@ namespace PkmnLib::Library {
uint16_t _shinyRate; uint16_t _shinyRate;
public: public:
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate) LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves, uint16_t shinyRate) noexcept
: CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {} : CreatureLib::Library::LibrarySettings(maximalLevel, maximalMoves), _shinyRate(shinyRate) {}
uint16_t GetShinyRate() const { return _shinyRate; } uint16_t GetShinyRate() const noexcept { return _shinyRate; }
}; };
} }

View File

@ -1 +0,0 @@
#include "PokemonLibrary.hpp"