Skip to content

Instantly share code, notes, and snippets.

@crazymonkyyy
Created March 14, 2026 20:14
Show Gist options
  • Select an option

  • Save crazymonkyyy/a90053aa9799e395a3ba7a1ceb2c3518 to your computer and use it in GitHub Desktop.

Select an option

Save crazymonkyyy/a90053aa9799e395a3ba7a1ceb2c3518 to your computer and use it in GitHub Desktop.
import std;
import core.stdc.stdlib;
import core.sys.posix.dlfcn;
void printdelegate(string link){
auto f=cast(int function(int delegate(ref string)))dlsym(null,link.toStringz);
foreach(e;toDelegate(f)){
e.writeln;
}}
unittest{
printdelegate("foo");
printdelegate("bar");
}
extern(C):
int foo(int delegate(ref string) f){
string s="a";
f(s);
s="b";
f(s);
return 0;
}
int bar(int delegate(ref string) f){
string s="APPLE";
f(s);
s="BANANA";
f(s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment