From fda3c8f86d0dca09286b3f27bb19f9e8c8a6a207 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 19 Sep 2020 15:57:20 +0200 Subject: [PATCH] Support not including standard angelscript libraries such as string and array. --- .../AngelScript/AngelScriptResolver.cpp | 14 ++++++++------ .../AngelScript/AngelScriptResolver.hpp | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp index 73507b0..95467b2 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp @@ -42,7 +42,7 @@ static void TranslateException(asIScriptContext* ctx, void* /*userParam*/) { } } -void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) { +void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg, bool includeStandard) { for (auto scriptCategory : ScriptCategoryHelper::GetValues()) { _typeDatabase.Insert(scriptCategory, {}); } @@ -67,16 +67,18 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) _engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2); _engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2); - RegisterStdString(_engine); - ConstStringRegister::Register(_engine); + if (includeStandard){ + RegisterStdString(_engine); + ConstStringRegister::Register(_engine); - // Register Script Array type - RegisterScriptArray(_engine, true); + // Register Script Array type + RegisterScriptArray(_engine, true); + RegisterScriptHandle(_engine); + } r = _engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(Print), asCALL_CDECL); if (r < 0) throw ArbUt::Exception("Registering print function failed."); - RegisterScriptHandle(_engine); _builder.StartNewModule(_engine, "pkmn"); _mainModule = _builder.GetModule(); diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp index 53265f0..8f63f6e 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp @@ -38,7 +38,10 @@ public: _engine->ShutDownAndRelease(); } - void Initialize(CreatureLib::Battling::BattleLibrary* library) override; + void Initialize(CreatureLib::Battling::BattleLibrary* library) override{ + Initialize(library, true); + } + void Initialize(CreatureLib::Battling::BattleLibrary* library, bool includeStandard); void CreateScript(const char* name, const char* script); const asIScriptModule* GetMainModule() const noexcept { return _mainModule; }