libhatchet
Loading...
Searching...
No Matches
hxconsole.hpp File Reference

Go to the source code of this file.

Macros

#define hxconsole_command(x_)
#define hxconsole_command_named(x_, name_)
#define hxconsole_variable(x_)
#define hxconsole_variable_named(x_, name_)

Functions

HX_NS_BEGIN_ void hxconsole_deregister (const char *id_)
bool hxconsole_exec_line (const char *command_)
bool hxconsole_help (void)
bool hxconsole_exec_file (hxfile &file_)
bool hxconsole_exec_filename (const char *filename_)

Detailed Description

Implements a simple console for debugging, remote use or for parsing configuration files.

Output is directed to the system log with hxlog_level_console. Requires C++20 or later. Set HX_USE_CONSOLE=2 to enable the debug console. See hxconsole.cpp for details. This is optimized for generated code size and not speed.

Here is how to write lambdas that cease to exist entirely when the console is disabled:

hxconsole_command_named(*+[](void) -> bool { return true; }, command_name);

Macro Definition Documentation

◆ hxconsole_command

#define hxconsole_command ( x_)
Value:
static HX_NS_PREFIX_ hxdetail_::hxconsole_constructor_ \
hxg_console_symbol_##x_(HX_NS_PREFIX_ hxdetail_::hxconsole_command_factory_(&(x_)), #x_)

hxconsole_command - Registers a function using a global constructor.

Use in a global scope. The command uses the same name and arguments as the function. E.g., hxconsole_command(srand);

  • x : Valid C identifier that evaluates to a function pointer.

◆ hxconsole_command_named

#define hxconsole_command_named ( x_,
name_ )
Value:
static HX_NS_PREFIX_ hxdetail_::hxconsole_constructor_ \
hxg_console_symbol_##name_(HX_NS_PREFIX_ hxdetail_::hxconsole_command_factory_(&(x_)), #name_)

hxconsole_command_named - Registers a named function using a global constructor.

Use in a global scope. The provided name must be a valid C identifier. E.g., hxconsole_command_named(srand, seed_rand);

  • x : Any expression that evaluates to a function pointer.
  • name : Valid C identifier that identifies the command.

◆ hxconsole_variable

#define hxconsole_variable ( x_)
Value:
static HX_NS_PREFIX_ hxdetail_::hxconsole_constructor_ \
hxg_console_symbol_##x_(HX_NS_PREFIX_ hxdetail_::hxconsole_variable_factory_(&(x_)), #x_)

hxconsole_variable - Registers a variable.

Use in a global scope. The command has the same name as the variable. E.g.,

static bool is_my_hack_enabled=false;
hxconsole_variable(is_my_hack_enabled);
#define hxconsole_variable(x_)
hxconsole_variable - Registers a variable.
Definition hxconsole.hpp:84
  • x : Valid C identifier that evaluates to a variable.

◆ hxconsole_variable_named

#define hxconsole_variable_named ( x_,
name_ )
Value:
static HX_NS_PREFIX_ hxdetail_::hxconsole_constructor_ \
hxg_console_symbol_##name_(HX_NS_PREFIX_ hxdetail_::hxconsole_variable_factory_(&(x_)), #name_)

hxconsole_variable_named - Registers a named variable.

Use in a global scope. The provided name must be a valid C identifier. E.g.,

static bool is_my_hack_enabled=false;
hxconsole_variable_named(is_my_hack_enabled, f_hack); // add "f_hack" to the console.
#define hxconsole_variable_named(x_, name_)
hxconsole_variable_named - Registers a named variable.
Definition hxconsole.hpp:95
  • x : Any expression that evaluates to a variable.
  • name : Valid C identifier that identifies the variable.

Function Documentation

◆ hxconsole_deregister()

HX_NS_BEGIN_ void hxconsole_deregister ( const char * id_)

hxconsole_deregister - Explicitly deregisters a console symbol.

  • id : Non-null identifier string for the variable or command being removed.

◆ hxconsole_exec_file()

bool hxconsole_exec_file ( hxfile & file_)

hxconsole_exec_file - Executes a configuration file that is opened for reading.

Ignores blank lines and comments that start with #. Disables asserts so that EOF is allowed. WARNING: file must not have asserts enabled as this call reads past the end.

  • file : A file containing commands.

◆ hxconsole_exec_filename()

bool hxconsole_exec_filename ( const char * filename_)

hxconsole_exec_filename - Opens a configuration file by name and executes it.

  • filename : Non-null UTF-8 path to a file containing commands.

◆ hxconsole_exec_line()

bool hxconsole_exec_line ( const char * command_)

hxconsole_exec_line - Evaluates a console command to either call a function or set a variable.

E.g., srand 77 or a_variable 5.

  • command : Non-null UTF-8 command string executed by the console.

◆ hxconsole_help()

bool hxconsole_help ( void )

hxconsole_help - Logs every console symbol to the console log.