Pretty much yes, expect that you'll need to null-terminate the table.
Also, you should use STDVAR argument list with your function. Your function should return TCL_OK upon success, and TCL_ERROR upon error. Any results returned to the tcl environment need to first be exported using the
Tcl_AppendResult(...) function call (documented in the tcl library docs).
Finally, the function table should be declared static, as it is also used to unregister functions when the module is unloaded (done in a similar fashion to registering the functions, but using
rem_tcl_commands(...) ).
Below is a partial example, the _report and _expmen functions are not implemented, and the module has not been given a name (MODULE_NAME and MAKING_<name> macros have not been defined, and init-function is named mod_start). It should however provide a rough framework to start with, although I cannot guarantee this is free of any errors.
Code: Select all
static int myfunc STDVAR
{
BADARGS(2, 3, " string [key]"
Tcl_AppendResult(irp, argv[1], null);
if (argc == 3)
Tcl_AppendResult(irp, argv[2], null);
return TCL_OK;
}
static tcl_cmds mycmd[] = {
{"myproc", myfunc},
{NULL, NULL}
};
char *mod_close()
{
rem_tcl_commands(mycmd);
module_undepend(MODULE_NAME);
return NULL;
}
EXPORT_SCOPE char *mod_start();
static Function f_table[] = {
(Function) mod_start,
(Function) mod_close,
(Function) NULL,
(Function) NULL,
};
char *mod_start(Function *f_global)
{
if (f_global)
{
module_register(MODULE_NAME, f_table, 2, 1);
if (!module_depend(MODULE_NAME, "eggdrop", 106, 3)) {
module_undepend(MODULE_NAME);
return "This module requires Eggdrop 1.6.3 or later.";
}
}
add_tcl_commands(mycmd);
return NULL;
}