From 5a5bed5c31e8a5e4515f681d72c6a35354d93521 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Thu, 20 Feb 2025 01:58:34 -0500 Subject: [PATCH] Added FindClass Allows for classes to be looked up during run time without having to use string casting. --- src/common/scripting/backend/codegen.cpp | 2 +- wadsrc/static/zscript/engine/base.zs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 92b68d703..1fcaeae2c 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -12367,7 +12367,7 @@ static PClass *NativeNameToClass(int _clsname, PClass *desttype) if (clsname != NAME_None) { cls = PClass::FindClass(clsname); - if (cls != nullptr && (cls->VMType == nullptr || !cls->IsDescendantOf(desttype))) + if (cls != nullptr && (cls->VMType == nullptr || (desttype != nullptr && !cls->IsDescendantOf(desttype)))) { // does not match required parameters or is invalid. return nullptr; diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 28d8a5604..f33966f7c 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -767,6 +767,7 @@ class Object native private native static bool CheckDeprecatedFlags(Object obj, int index); native static Name ValidateNameIndex(int index); + static class FindClass(Name cls, class baseType = null) { return BuiltinNameToClass(cls, baseType); } native static uint MSTime(); native static double MSTimeF();