summaryrefslogtreecommitdiff
path: root/src/con_.h
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-17 20:18:48 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-06-21 14:50:00 +0100
commitac7e7d0f21978afc70fe3ef76db69d575742b974 (patch)
tree6fd25c7ded6cfeba7c55b1c26abc82a28878a14e /src/con_.h
parent1f2d9ce197eafd16803de087cc5b6f8b8f4345a6 (diff)
downloadsst-ac7e7d0f21978afc70fe3ef76db69d575742b974.tar.gz
sst-ac7e7d0f21978afc70fe3ef76db69d575742b974.zip
Separate our command callbacks from Source's
This improves the ergonomics of a few different things, and sets us up somewhat for the fact OE had a different interface for commands too (it was v1 only and had a separate API call for getting the args).
Diffstat (limited to 'src/con_.h')
-rw-r--r--src/con_.h26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/con_.h b/src/con_.h
index 8fc9756..b491aad 100644
--- a/src/con_.h
+++ b/src/con_.h
@@ -66,10 +66,13 @@ enum {
CON_CCMDEXEC = 1 << 30 /* ClientCmd() function may run the command */
};
-/* A callback function invoked to execute a command. */
-typedef void (*con_cmdcb)(const struct con_cmdargs *cmd);
+/* A callback function invoked by SST to execute its own commands. */
+typedef void (*con_cmdcb)(int argc, const char *const *argv);
-/* Obsolete callback; not used by SST, but might still exist in the engine. */
+/* A callback function used by most commands in most versions of the engine. */
+typedef void (*con_cmdcbv2)(const struct con_cmdargs *cmd);
+
+/* An older style of callback function used by some old commands, and in OE. */
typedef void (*con_cmdcbv1)();
/*
@@ -101,9 +104,11 @@ struct con_cmdbase { // ConCommandBase in engine
struct con_cmd { // ConCommand in engine
struct con_cmdbase base;
union {
+ con_cmdcb cb; // N.B.: only used by *our* commands!
con_cmdcbv1 cb_v1;
- con_cmdcb cb;
- /*ICommandCallback*/ void *cb_iface; // does source even use this?
+ con_cmdcbv2 cb_v2;
+ const uchar *cb_insns; // for the sake of instruction-scanning and such
+ /*ICommandCallback*/ void *cb_iface; // what in Source even uses this?
};
union {
con_complcb complcb;
@@ -160,7 +165,7 @@ void con_setvari(struct con_var *v, int i);
* callback being requested. If this is already known, consider just grabbing
* the member directly to avoid the small amount of unnecessary work.
*/
-con_cmdcb con_getcmdcb(const struct con_cmd *cmd);
+con_cmdcbv2 con_getcmdcbv2(const struct con_cmd *cmd);
con_cmdcbv1 con_getcmdcbv1(const struct con_cmd *cmd);
/*
@@ -264,7 +269,6 @@ extern struct _con_vtab_iconvar_wrap {
.name = "" #name_, .help = "" desc, .flags = (flags_) \
}, \
.cb = &func, \
- .use_newcb = true \
}; \
struct con_cmd *varname = &_ccmd_##varname;
@@ -282,13 +286,13 @@ extern struct _con_vtab_iconvar_wrap {
/*
* Defines a console command with the handler function body immediately
- * following the macro (like in Source itself). The function takes the argument
- * `struct con_cmdargs *cmd` for command arguments.
+ * following the macro (like in Source itself). The function takes the implicit
+ * arguments `int argc` and `const char *const *argv` for command arguments.
*/
#define DEF_CCMD_HERE(name, desc, flags) \
- static void _cmdf_##name(const struct con_cmdargs *cmd); \
+ static void _cmdf_##name(int argc, const char *const *argv); \
_DEF_CCMD(name, name, desc, _cmdf_##name, flags) \
- static void _cmdf_##name(const struct con_cmdargs *cmd) \
+ static void _cmdf_##name(int argc, const char *const *argv) \
/* { body here } */
/*