"Lambda" functions
Add support for lambda functions. Like this:
void DisplayDBTablesInServerConsole() {
g_hDB.Query( [] (Database hDB, DBResultSet hResults, const char[] szError, any data) -> void {
char szTable[64];
while (hResults.FetchRow()) {
hResults.FetchString(0, szTable, sizeof(szTable));
PrintToServer("Found table in DB: %s", szTable);
}
}, "SHOW TABLES;", 0, DBPrio_Low);
}
This use case was a motivating reason for the experimental v2 parser; it has almost zero chance of happening at the moment though. It’s out of scope for spcomp1 (making newfunc reentrant would be a nightmare) and v2 is not under active development.
It’s possible that, If we made newfunc reentrant, we could make your example work. But access to local scope would be impossible without v2 and a garbage collection safe API.
Was support for lambda-type calls ever added to Sourcemod? j/w as I'd like to use them in my rpgmaker, if at all possible...
With the new compiler, it's actually in the realm of feasible. But we're talking "can see it through the Hubble telescope".
so, what needs to be done to get us a little-bit-closer?
non-capturing lambdas could be done right now. capturing lambdas would need garbage collection, which is a pretty invasive set of changes.
I'm really looking forward to this change, which means I won't have to write those extra callbacks😘
I have made an experimental test parse on adding function literals to SP, here's the grammar I got to:
Primary = identifier | ... | '(' Expr ')' | '{' Expr '}' | FuncLit .
FuncLit = SignatureSpec BlockStmt .
SignatureSpec = 'function' AbstractDecl ParamsList .
BlockStmt = '{' *Statement '}' .