diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index 039a21dab..9baf61bbc 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -9127,6 +9127,31 @@ ExpEmit FxVMFunctionCall::Emit(VMFunctionBuilder *build) { count += EmitParameter(build, ArgList[i], ScriptPosition, &tempstrings); } + // Complete the parameter list from the defaults. + auto &defaults = Function->Variants[0].Implementation->DefaultArgs; + for (unsigned i = count; i < defaults.Size(); i++) + { + FxConstant *constant; + switch (defaults[i].Type) + { + default: + case REGT_INT: + constant = new FxConstant(defaults[i].i, ScriptPosition); + break; + case REGT_FLOAT: + constant = new FxConstant(defaults[i].f, ScriptPosition); + break; + case REGT_POINTER: + constant = new FxConstant(defaults[i].a, ScriptPosition); + break; + case REGT_STRING: + constant = new FxConstant(defaults[i].s(), ScriptPosition); + break; + } + count += EmitParameter(build, constant, ScriptPosition, &tempstrings); + delete constant; + } + ArgList.DeleteAndClear(); ArgList.ShrinkToFit(); diff --git a/src/scripting/backend/codegen.h b/src/scripting/backend/codegen.h index 092503282..87084596c 100644 --- a/src/scripting/backend/codegen.h +++ b/src/scripting/backend/codegen.h @@ -501,6 +501,13 @@ public: isresolved = true; } + FxConstant(void *state, const FScriptPosition &pos) : FxExpression(EFX_Constant, pos) + { + value.pointer = state; + ValueType = value.Type = TypeVoidPtr; + isresolved = true; + } + FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos) { value.pointer = nullptr;