Provide a 'placement-spawn' feature, so mods don't need to hardcode spawnfunc_ prefixes in their code.

This commit is contained in:
Shpoike 2023-06-29 01:38:29 +01:00
parent e8b36da22f
commit d59c63f545

View file

@ -7883,7 +7883,9 @@ static QCC_sref_t QCC_PR_ParseFunctionCall (QCC_ref_t *funcref) //warning, the f
}
else if (!strcmp(funcname, "spawn"))
{
QCC_sref_t result;
//foo_c e = spawn(foo_c, fld:val, fld:val); //regular spawn...
//foo_c e = spawn(existingent, foo_c, fld:val, fld:val); //placement-spawn...
QCC_sref_t result = nullsref;
QCC_type_t *rettype;
/*
@ -7896,16 +7898,25 @@ static QCC_sref_t QCC_PR_ParseFunctionCall (QCC_ref_t *funcref) //warning, the f
if (!QCC_PR_CheckToken(")"))
{
char *nam = QCC_PR_ParseName();
rettype = QCC_TypeForName(nam);
rettype = QCC_PR_ParseType(false, true);
if (!rettype)
{
result = QCC_PR_Expression(TOP_PRIORITY, EXPR_DISALLOW_COMMA);
QCC_PR_Expect(",");
rettype = QCC_PR_ParseType(false, true);
}
//FIXME: C++'s Placement New syntax: obj *p= new(ptr) obj();
if (!rettype || rettype->type != ev_entity)
QCC_PR_ParseError(ERR_NOTANAME, "Spawn operator with undefined class: %s", nam);
QCC_PR_ParseError(ERR_NOTANAME, "Spawn operator with undefined class: %s", QCC_PR_ParseName());
}
else
rettype = NULL; //default, corrected to entity later
//ret = spawn()
result = QCC_PR_GenerateFunctionCallRef(nullsref, func, NULL, 0);
if (!result.cast)
{
//ret = spawn()
result = QCC_PR_GenerateFunctionCallRef(nullsref, func, NULL, 0);
}
if (rettype)
{