www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10719] New: Loading classes in runtime


           Summary: Loading classes in runtime
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: freeslave93 gmail.com

--- Comment #0 from Roman <freeslave93 gmail.com> 2013-07-26 17:37:00 PDT ---
There is kinda plugin here (code is for linux or other posix system with dlfcn)
Why does it crush when using interface instead of abstract class?

module dinter;

version(inter) {
    pragma(msg, "Using interface");
    interface Dinter {
        int foo(int a, int b);
else {
    pragma(msg, "Using abstract class");
    abstract class Dinter {
        int foo(int a, int b);

//dmd -shared -fPIC dimpl.d dinter.d -oflibdimpl.so
//dmd -shared -fPIC dimpl.d dinter.d -oflibdimpl.so -verstion=inter
module dimpl;
import dinter;

class Dimpl : Dinter {
    override int foo(int a, int b) {
        return a+b;
extern(C) Dinter create() {
    return new Dimpl;

//dmd dmain.d -L-rpath=. -L-ldl
//dmd dmain.d -L-rpath=. -L-ldl -version=inter

import dinter;
import std.c.linux.linux;
import std.string : toStringz;

alias extern(C) Dinter function() CreateFn;

int main(string[] args) {
    void* lib = dlopen(toStringz("./libdimpl.so"), RTLD_LAZY);
    auto create = cast(CreateFn)dlsym(lib, toStringz("create"));
    Dinter d = create();
    return 0;

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2013