Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Command Parser

The command parser in Yuneta validates and processes commands defined in a GClass’s command_table. It ensures commands sent to a GObj are properly formatted and conform to the schema for that GClass. The parser dynamically selects between an instance-specific method (mt_command), a global parser, or an internal parser to handle commands.

Commands are executed using the API gobj_command:

json_t *gobj_command(hgobj gobj, const char *cmd, json_t *kw, hgobj src);

Source code in:


How the Command Parser Works

1. Command Validation

The parser checks the cmd and kw arguments to ensure:

2. Dynamic Handling

When gobj_command() is called:

  1. Instance-Specific Handling:

    • If the GClass defines an mt_command method, this method is invoked.

    • This allows GClasses to handle their own commands with custom logic.

  2. Global Parser Handling:

    • If mt_command is not defined, the global command parser (provided in gobj_start_up()) is used.

    • The global parser applies standardized command validation and execution.

  3. Fallback to Internal Parser:

    • If no global command parser is defined (null), the internal parser is used.

3. Parameter Handling


Command Execution API

ParameterDescription
gobjThe GObj instance executing the command.
cmdThe name of the command, optionally including parameters.
kwA JSON object containing the command’s parameters if not included in cmd.
srcThe source GObj sending the command.

Command Table

The command_table defines the commands supported by a GObj. Each entry includes:


Workflow for gobj_command()

  1. Receiving a Command:

    • A command is sent to a GObj using gobj_command().

    • The cmd and kw arguments specify the command and its parameters.

  2. Command Resolution:

    • If the GClass defines mt_command, it is invoked to handle the command.

    • If mt_command is not defined, the global command parser is used.

    • If no global parser is defined, the internal parser is used as a fallback.

  3. Parsing and Validation:

    • The command name is checked against the command_table.

    • Parameters are validated based on the schema.

  4. Execution:

    • The handler function associated with the command is invoked, processing the command and returning the result.


Benefits of the Command Parser


Use Cases

1. Service-Oriented Gobjs

2. Custom Command Logic

3. Dynamic Parameter Handling