Hi all,
I made a small header-only library called
conco ("console commands") designed to make building simple command interpreters, REPLs, or Quake-like game consoles trivial.The core idea is to take a raw string like
add 10 20 and automatically dispatch it to a C++ function like int add(int x, int y);. The library handles tokenization, type conversion, argument passing and result stringification for you.You can bind regular functions, capturing lambdas or member functions as your commands. There is no global state and no dynamic memory allocations. The library is well suited for embedded development, where creating text-based debug interfaces over UART/serial port might come handy.
Basic example:
void logenable() { ... }
int sum(int a, int b) { return a + b; }
int main()
{
// List of available commands
const conco::command commands[] = {
{ logenable, "log.enable;Enable logging" },
{ sum, "sum;Sum of two integers" }
};
// Calls
log_enableconco::execute(commands, "log.enable");
char buffer256 = { 0 };
// Calls
sum(123, 456), writes stringified result to bufferconco::execute(commands, "sum 123 456", buffer);
std::println("{}", buffer); // Outputs: 579
}
I would love to hear your feedback or roast of the implementation! Check out the GitHub repository link here:
https://github.com/P-i-N/conco
Cheers!
https://redd.it/1pwvui8
@r_cpp