From 09f1859c8343394340a0c22cf40a26b68d75b8f5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 21 Jan 2018 18:49:46 +0100 Subject: [PATCH] - allow retrieving the length of a string constant. --- src/scripting/backend/codegen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index a8aa1a897..a9c7e4fcc 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -9378,6 +9378,13 @@ FxExpression *FxStrLen::Resolve(FCompileContext &ctx) { SAFE_RESOLVE(Self, ctx); assert(Self->ValueType == TypeString); + if (Self->isConstant()) + { + auto constself = static_cast(Self); + auto constlen = new FxConstant((int)constself->GetValue().GetString().Len(), Self->ScriptPosition); + delete this; + return constlen->Resolve(ctx); + } ValueType = TypeUInt32; return this; }