News for hackers. Stuff that matters.
Re:Show HN: Add a command-line interface to any C++ program by chrisaycock on Saturday October 16, 2021 @04:13AM (#28886331)
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

Re:Show HN: Add a command-line interface to any C++ program by choeger on Saturday October 16, 2021 @07:57AM (#28887230)
Nice 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?

Re:Show HN: Add a command-line interface to any C++ program by gpderetta on Saturday October 16, 2021 @10:58AM (#28888294)
Lexical cast, aside a couple of specializations, is just a wrapper over iostream, so probably you only need to define operator>> and <<.
Re:Show HN: Add a command-line interface to any C++ program by chrisaycock on Saturday October 16, 2021 @09:21AM (#28887696)
Yes, 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.
Re:Show HN: Add a command-line interface to any C++ program by agumonkey on Saturday October 16, 2021 @08:33AM (#28887391)
funny I was thinking of something similar but for vuejs/keymaps (yeah I like keyboard oriented interfaces even on reactive webapps)
Re:Show HN: Add a command-line interface to any C++ program by dmalecaut on Saturday October 16, 2021 @03:05PM (#28890482)
Prop firms sure like their esoteric C++!
Re:Show HN: Add a command-line interface to any C++ program by sfgweilr4f on Sunday October 17, 2021 @08:15AM (#28895904)
"prop"?
Re:Show HN: Add a command-line interface to any C++ program by dmalecaut on Wednesday October 20, 2021 @06:24AM (#28928979)
Proprietary trading firm