A very basic scripting language implemented in C++.
bool, long, std::string,
std::vector<riddle::Val> and std::map<riddle::Val,riddle::Val>.Run make install to install:
$(PREFIX)$(includedir)/riddle/$(HOME)/.local/include/riddle/$(PREFIX)$(libdir)$(HOME)/.local/libYou can remove the installed files with make uninstall.
A C++ program can use Riddle by linking with either libriddle.a or
libriddle.so and including riddle/riddle.hh.
To use Riddle you first create a global scope where values and functions are exported. Riddle does not provide any function beyond basic operators, so you need to provide anything that the users can require:
riddle::Scope global;
global.add("print", riddle::Val(&fun_print_));
global.add("scan", riddle::Val(&fun_scan_));
global.add("type", riddle::Val(riddle::make_fun(&fun_type_)));
...
If you want to execute some Riddle code stored in a plain string, you can use
the riddle::eval() function as follows:
try {
std::cout << riddle::eval(global, TEXT) << "\n";
} catch (std::exception& ex) {
std::cerr << ex.what() << "\n";
}
If you want to compile some Riddle code and then call it repeated times, you want to do this instead:
riddle::Standalone snippet{global, TEXT};
try {
std::cout << snippet(ARGS, ARGN) << "\n";
} catch (std::exception& ex) {
std::cerr << ex.what() << "\n";
}
And if you want to run an interactive shell where the user can store additional values in a context and every line that's run is discarded you can do this:
riddle::Interactive interactive{global, ARGS, ARGN};
while (READ NEW LINE) {
try {
std::cout << interactive(LINE) << "\n";
} catch (std::exception& ex) {
std::cerr << ex.what() << "\n";
}
}