By native I mean written in C++ or C
I'm making a programming language based off Java, in that it has a VM and a language to bytecode compiler.
Implementing the language's features, such as for
loops, variables, arithmetic and so on, isn't a problem for me; however, executing native functions like Java can is.
I need the native functions in order to make it possible for programs written in my language to create windows, interface with hardware and the OS, and do just about anything that isn't simple mathematics.
I've heard about the JNI, and it definitely seems like something I'd want, however, I am not sure how to implement something like that.
As my VM is implemented in C++, I know that I could have it #include
hpp files of my native functions at compile-time, and then it could dynamically load dll
's or so
's, however, this doesn't really seem like a good solution because you'd have to recompile the VM every time you'd want it to be able to execute another native function.
The problem comes down to this: how can a C++ program (the VM), dynamically (at runtime, as instructed by bytecode, to be more precise) load libraries with C++ functions, and then execute those functions without them being predeclared in some header file?