Function Pointers
Universe allows the use of function pointers. Function are considered first order objects. This means they can be stored in a variable, passed to a function, or returned from a function. Below are some univese examples that display the possibilities and also how these examples are translated to galaxy.
Example1: using function pointers
void Bliep(int i, bool b) {}
void Blap(int j, bool c) {}
void Blaap(int j){}
void Foo(void(int,bool) func1) { func1(3,true); }
void Bar() { Foo(Bliep); Foo(Blap); }
Example1 output
void rRedirectvoidintbool(int funcIndex, int param0, bool param1) { if (funcIndex == 1) { Bliep(param0, param1); } else if (funcIndex == 0) { Blap(param0, param1); } return; }
void Bliep(int i, bool b) { }
void Blap(int j, bool c) { }
void Blaap(int j) { }
void Foo(int func1) { rRedirectvoidintbool(func1, 3, true); }
void Bar() { Foo(1); Foo(0); }
Example2: input using composite calls
int Bla(int a) { return a; } int(int) Bliep(bool b) { return Bla; } void Foo(int(int)(bool) func1) { (func1(true))(3); } void Bar() { Foo(Bliep); }
Example2 output
int r__Redirectintbool(int funcIndex, bool param0) { if (funcIndex == 0) { return Bliep(param0); } return 0; } int r__Redirectintint(int funcIndex, int param0) { if (funcIndex == 0) { return Bla(param0); } return 0; } int Bla(int a) { return a; } int Bliep(bool b) { return 0; } void Foo(int func1) { r__Redirectintint(r__Redirectintbool(func1, true), 3); } void Bar() { Foo(0); }
Comments