diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index f91188f80..bcada45cf 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -64,11 +64,13 @@ static double GetFloatConst(FxExpression *ex, FCompileContext &ctx) return ex ? static_cast(ex)->GetValue().GetFloat() : 0; } -static FString GetStringConst(FxExpression *ex, FCompileContext &ctx) +const char * ZCCCompiler::GetStringConst(FxExpression *ex, FCompileContext &ctx) { ex = new FxStringCast(ex); ex = ex->Resolve(ctx); - return ex ? static_cast(ex)->GetValue().GetString() : FString(); + if (!ex) return ""; + // The string here must be stored in a persistent place that lasts long enough to have it processed. + return AST.Strings.Alloc(static_cast(ex)->GetValue().GetString())->GetChars(); } int ZCCCompiler::IntConstFromNode(ZCC_TreeNode *node, PStruct *cls) @@ -1851,6 +1853,12 @@ void ZCCCompiler::DispatchProperty(FPropertyInfo *prop, ZCC_PropertyStmt *proper params[0].i++; } exp = static_cast(exp->SiblingNext); + if (exp != property->Values) + { + ex = ConvertNode(exp); + ex = ex->Resolve(ctx); + if (ex == nullptr) return; + } } while (exp != property->Values); goto endofparm; } @@ -1988,7 +1996,7 @@ void ZCCCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *prop } else if (f->Type == TypeColor && ex->ValueType == TypeString) // colors can also be specified as ints. { - *(PalEntry*)addr = V_GetColor(nullptr, GetStringConst(ex, ctx).GetChars(), &ex->ScriptPosition); + *(PalEntry*)addr = V_GetColor(nullptr, GetStringConst(ex, ctx), &ex->ScriptPosition); } else if (f->Type->IsKindOf(RUNTIME_CLASS(PInt))) { @@ -2012,7 +2020,7 @@ void ZCCCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *prop } else if (!cls->IsDescendantOf(static_cast(f->Type)->ClassRestriction)) { - Error(property, "class %s is not compatible with property type %s", clsname.GetChars(), static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); + Error(property, "class %s is not compatible with property type %s", clsname, static_cast(f->Type)->ClassRestriction->TypeName.GetChars()); } *(PClass**)addr = cls; } diff --git a/src/scripting/zscript/zcc_compile.h b/src/scripting/zscript/zcc_compile.h index 5af5418ab..9d54f925b 100644 --- a/src/scripting/zscript/zcc_compile.h +++ b/src/scripting/zscript/zcc_compile.h @@ -92,6 +92,8 @@ public: int Compile(); private: + const char * GetStringConst(FxExpression *ex, FCompileContext &ctx); + int IntConstFromNode(ZCC_TreeNode *node, PStruct *cls); FString StringConstFromNode(ZCC_TreeNode *node, PStruct *cls); void ProcessClass(ZCC_Class *node, PSymbolTreeNode *tnode);