Am Sat, 14 Dec 2013 14:59:42 +0100 schrieb "hoya" <[email protected]>:
> On Saturday, 14 December 2013 at 13:44:01 UTC, Marco Leise wrote: > > > You can load libraries at runtime like OpenGL or a database > > driver. This applies to all C and D libraries as well as C++ > > libraries to some extent. > > > Can you give me an example how to do this? Hmm, there are two options when it comes to dynamic linking. You can directly refer to the functions you use from some library. An example is std.net.curl in Phobos. You compile your program with "dmd -L-lcurl <source>" to link to the curl library which is written in C and common on Linux systems. This is the simple case where you don't need to write any extra code. If you want to load a plugin at runtime or OpenGL (which is a different library for each graphics card vendor) you will need to use the dynamic linker (libdl.so) which handles this case: "dmd -L-ldl <source>" and then use "dlopen" and "dlsym" in your program to find the addresses of functions. Derelict 3 is a good example of loading libraries at runtime this way: https://github.com/aldacron/Derelict3 It is a wrapper/binding collection for many multimedia/game related libraries and you can reuse its derelict.util module to load your own libraries at runtime. Which case are you interested in? > > Or does Java have an eval() method of some sort now? > Not directly, you can read this: > http://rosettacode.org/wiki/Runtime_evaluation/In_an_environment#Java But that is what I described above. A Java compiler is not a requirement for a proper Java installation. It is an external tool that they load and the expression evaluation is done by writing the code to a Java source file on the file system, compiling that and loading it. This can be done with dmd as well, but in both cases it is crutch to bring eval()-like functionality to a statically compiled language. :) -- Marco
