From 21f55eaeeb1c4774070739b609a5d9f061c41005 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 7 May 2020 19:51:53 +0100 Subject: [PATCH] Handle no object for context.getObject correctly --- src/openrct2/scripting/Duktape.hpp | 6 ++++++ src/openrct2/scripting/ScContext.hpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/openrct2/scripting/Duktape.hpp b/src/openrct2/scripting/Duktape.hpp index fe47adf8d1..54f26c8eee 100644 --- a/src/openrct2/scripting/Duktape.hpp +++ b/src/openrct2/scripting/Duktape.hpp @@ -193,6 +193,12 @@ namespace OpenRCT2::Scripting template DukValue ToDuk(duk_context* ctx, const T& value) = delete; template T FromDuk(const DukValue& s) = delete; + template<> inline DukValue ToDuk(duk_context* ctx, const std::nullptr_t&) + { + duk_push_null(ctx); + return DukValue::take_from_stack(ctx); + } + } // namespace OpenRCT2::Scripting #endif diff --git a/src/openrct2/scripting/ScContext.hpp b/src/openrct2/scripting/ScContext.hpp index 5b1e1d9878..2d6c17ac1d 100644 --- a/src/openrct2/scripting/ScContext.hpp +++ b/src/openrct2/scripting/ScContext.hpp @@ -82,7 +82,7 @@ namespace OpenRCT2::Scripting { duk_error(ctx, DUK_ERR_ERROR, "Invalid object type."); } - return {}; + return ToDuk(ctx, nullptr); } std::vector getAllObjects(const std::string& typez) const