
import std.stdio, core.memory, std.exception;

static string[string] lookup; //map from names to mangled names

extern(C) string dload(string name) {
//get mangled name; toy example: ignore possibiliy of overloading
  return lookup[name]; 
}


static this() {
  //make this module GC safe here
  static string[string]* lptr;
  lptr = &lookup;
  //wrong?, ask expert, need clean solution
  GC.addRoot( &lptr); //why does this callback work when not loaded fully?
  //can call stdio functions here with no problem too

  //exception handling problematic for execution in here
  //not yet loaded fully, so callbacks for throwing &c not linkable yet?

  //setup all callback names
  lookup["concat"] = concat.mangleof;
  lookup["sum"] = sum.mangleof;

}

//example functions to call after load

string concat(string[] arg...) {
  string ans;
  foreach( s ; arg ) ans ~= s;
  return ans;
}

int sum(int[] num...) {
  int total = 0;
  foreach( x ; num ) total += x;
  return total;
}
