On Thursday, 2 January 2014 at 19:33:38 UTC, Dicebot wrote:
It looks actually pretty capable with current 2.064.2 to me:
[dicebot@fog ~]$ cat lib.d
void foo(int x)
{
import std.stdio;
writefln("got %s in shared lib", x);
}
[dicebot@fog ~]$ cat test.d
import lib : foo;
import core.runtime : Runtime;
import core.sys.posix.dlfcn : dlsym;
import std.exception : enforce;
void main()
{
auto handler = Runtime.loadLibrary("./lib.so");
scope(exit) Runtime.unloadLibrary(handler);
enforce(handler);
auto func = cast(void function(int)) dlsym(handler,
foo.mangleof.ptr);
enforce(func);
func(42);
}
[dicebot@fog ~]$ dmd -shared -fPIC -defaultlib=libphobos2.so
lib.d
[dicebot@fog ~]$ dmd -L-ldl -defaultlib=libphobos2.so -run
test.d
got 42 in shared lib
That's not cross-platform though.