5 ms·
I wrote this to add a REPL-like interface to existing programs. It can call normal functions with automatic parsing and type safety. class Arithmetic : publi
by chrisaycock 5y ago
I wrote this to add a REPL-like interface to existing programs. It can call normal functions with automatic parsing and type safety.
class Arithmetic : public CommandInterface {
int add(int x, int y) {
return x + y;
}
void register_commands() override {
register_command(&Arithmetic::add, "add", "Add two numbers");
}
};
Simply evaluate a string to invoke the function.
Arithmetic arithmetic;
arithmetic.eval("add 3 4"); // returns "7"
The user can place the eval() call behind any interface that has a string for its input and output. I personally use it behind a TCP socket on my trading application; I can query my strategy's state and change its parameters on the fly.
If funky C++ interests you, the prop firm I work for is looking to hire engineers. Feel free to contact me directly: chris -AT- chrisaycock -DOT- com
- dmalecaut 5y agoProp firms sure like their esoteric C++!
- sfgweilr4f 5y ago"prop"?
- dmalecaut 5y agoProprietary trading firm
- choeger 5y agoNice work. Thanks for releasing it as free software. If I understand the design correctly, one can provide a custom argument parser by specializing lexical_cast?
- chrisaycock 5y agoYes, in theory. I've never tried to specialize lexical_cast since it's a Boost library and likely has its own assumptions. But I imagine it's possible if you want to handle things like arrays or user-defined types.
- gpderetta 5y agoLexical cast, aside a couple of specializations, is just a wrapper over iostream, so probably you only need to define operator>> and <<.
- agumonkey 5y agofunny I was thinking of something similar but for vuejs/keymaps (yeah I like keyboard oriented interfaces even on reactive webapps)