assyrianic / SourceGo

SourceGo is a transpiler that transforms a subset of Golang-like code to equivalent SourcePawn.
https://forums.alliedmods.net/showthread.php?t=328269
MIT License
25 stars 3 forks source link

Allow Function Literals to capture local vars #6

Open assyrianic opened 3 years ago

assyrianic commented 3 years ago

Golang allows one to use (outside) local variables within the code of a function literal. Technically, this can be supported but would have to be changed by analyzing the type of used variables that are outside the function literal's scope and then passed by reference.

so something like:

var n int
func() {
  n++
}()

would have to be like:

void fn(int& param1) {
  param1++
}

...
int n;
fn(n);

Not impossible but rather difficult to support.