reference event callbacks by name, not by internal index.

This is needed to allow writing new callbacks.
This commit is contained in:
Christoph Oelckers 2023-10-06 00:26:25 +02:00
parent 47f09c61fc
commit 11f094c7fb
14 changed files with 92 additions and 20 deletions

View file

@ -1639,6 +1639,23 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
// don't go through the entire list if the types are the same.
goto basereturn;
}
else if ((basex->ValueType == TypeString || basex->ValueType == TypeName) && ValueType == TypeVMFunction && basex->isConstant())
{
FxExpression* x = new FxStringCast(basex);
x = x->Resolve(ctx);
basex = nullptr;
auto c = static_cast<FxConstant*>(x)->GetValue().GetString().GetChars();
auto func = FindVMFunction(c);
if (func == nullptr)
{
ScriptPosition.Message(MSG_ERROR, "VM function %s not found", c);
delete this;
return nullptr;
}
auto newx = new FxConstant(func, ScriptPosition);
delete this;
return newx->Resolve(ctx);
}
else if (basex->ValueType == TypeNullPtr && ValueType->isPointer())
{
goto basereturn;

View file

@ -506,6 +506,13 @@ public:
isresolved = true;
}
FxConstant(VMFunction* state, const FScriptPosition& pos) : FxExpression(EFX_Constant, pos)
{
value.pointer = state;
ValueType = value.Type = TypeVMFunction;
isresolved = true;
}
FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
{
value.pointer = nullptr;