This is a really cool new language! Can it be used as a scripting language inside other software? #126
the-LONS-network
started this conversation in
General
Replies: 1 comment
-
Yes. Blade can be embedded into other softwares. At it's core, the BVM and compiler are different entities from the complete Blade package. See src/blade.c for how its done. Below is a simple integration: #include <blade.h>
#include <stdlib.h>
#include <string.h>
int main() {
const char * source = "echo 'It works'";
// initialize the VM
b_vm *vm = (b_vm *) malloc(sizeof(b_vm));
if (vm != NULL) {
memset(vm, 0, sizeof(b_vm));
init_vm(vm);
// always do this before calling `repl` or `run_file`
// this allows access to all the built-in functions.
// NOTE: You can skip it if you don't need any of the
// built-in functions
bind_native_modules(vm);
// instantiate the base module (prefereably to an empty
// name to avoid conflicts with user defined module and
// packages.)
b_obj_module *module = new_module(vm, "", "<std-file-path>");
add_module(vm, module);
interpret(vm, module, source);
}
return 0;
} Don't forget to link libblade and add blade include directory to header source. For example, with export BLADE_ROOT=/your/blade/install/path
clang sample.c -I$BLADE_ROOT/includes -L$BLADE_ROOT/blade -lblade -o ./sample If you are getting sudo ln -s $BLADE_ROOT/libblade.dylib /usr/local/lib/libblade.dylib # .so for Linux, .dylib for MacOS I think I should add this to the documentation. :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please tell me this language can be embedded into other software!!
It would be perfect for things not decadent for python but way above lua's paygrade
Beta Was this translation helpful? Give feedback.
All reactions