Website | Source

ArkScript is

Embedding in C++

#include <Ark/Ark.hpp>
 
int main()
{
    // A state can be shared by multiple VM ; they can't overwrite it
    Ark::State state;
 
    // This will compile the code, but you can also give a file with state.doFile()
    state.doString("(let foo (fun (x y) (+ x y 2)))");
    // You can register C++ function (only before calling vm.run())
    state.loadFunction("cpp_foo", [](std::vector<Ark::Value>& args, Ark::VM* vm) {
        return Ark::Value(static_cast<int>(args.size()));
    });
 
    Ark::VM vm(state);
    vm.run();
 
    auto value = vm.call("foo", 5, 6.0);
    // displays 13
    std::cout << value << "\n";
 
    return 0;
}


Tags: language   functional   native  

Last modified 16 December 2024