diff options
author | Steve Bennett <steveb@workware.net.au> | 2025-07-06 10:02:18 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2025-07-16 09:34:08 +1000 |
commit | 0bcff3278972ea30330d1a1e0e729991c79a0642 (patch) | |
tree | fc8aba300d630eee7303cb1da4109bb092d7b702 | |
parent | a30b03ea100a0c38d1650fa0c9497f46be02147d (diff) | |
download | jimtcl-0bcff3278972ea30330d1a1e0e729991c79a0642.zip jimtcl-0bcff3278972ea30330d1a1e0e729991c79a0642.tar.gz jimtcl-0bcff3278972ea30330d1a1e0e729991c79a0642.tar.bz2 |
Update examples.api and examples.ext to use Jim_RegisterCommand
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | examples.api/jim_command.c | 14 | ||||
-rw-r--r-- | examples.api/jim_return.c | 8 | ||||
-rw-r--r-- | examples.ext/helloworld.c | 4 |
3 files changed, 8 insertions, 18 deletions
diff --git a/examples.api/jim_command.c b/examples.api/jim_command.c index ce9a8ac..431b262 100644 --- a/examples.api/jim_command.c +++ b/examples.api/jim_command.c @@ -44,16 +44,11 @@ MySampleCommandFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) const char *str; int len; - if (argc != 2) { - Jim_WrongNumArgs(interp, 1, argv, "string"); - return (JIM_ERR); - } - + /* No need to check arg count here as this is checked by Jim_RegisterCmd() */ str = Jim_GetString(argv[1], &len); - assert(str != NULL); printf("%s\n", str); - return (JIM_OK); + return JIM_OK; } /* @@ -77,9 +72,8 @@ main(int argc, char **argv) /* And initialise any static extensions */ Jim_InitStaticExtensions(interp); - /* Register our Jim commands. */ - Jim_CreateCommand(interp, "MySampleCommand", MySampleCommandFunc, - NULL, NULL); + /* Register our Jim commands. This includes usage and min/max arg count */ + Jim_RegisterSimpleCmd(interp, "MySampleCommand", "string", 1, 1, MySampleCommandFunc); /* Run a script. */ error = Jim_Eval(interp, JIM_PROGRAM); diff --git a/examples.api/jim_return.c b/examples.api/jim_return.c index 4f5a272..383b428 100644 --- a/examples.api/jim_return.c +++ b/examples.api/jim_return.c @@ -44,10 +44,6 @@ static int CountCharsFunc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - if (argc != 2) { - Jim_WrongNumArgs(interp, 1, argv, "string"); - return (JIM_ERR); - } Jim_SetResult(interp, Jim_NewIntObj(interp, Jim_Length(argv[1]))); return (JIM_OK); } @@ -73,10 +69,8 @@ main(int argc, char **argv) /* And initialise any static extensions */ Jim_InitStaticExtensions(interp); - /* Register our Jim command. */ - Jim_CreateCommand(interp, "CountChars", CountCharsFunc, - NULL, NULL); + Jim_RegisterSimpleCmd(interp, "CountChars", "string", 1, 1, CountCharsFunc); /* Run a script. */ error = Jim_Eval(interp, JIM_PROGRAM); diff --git a/examples.ext/helloworld.c b/examples.ext/helloworld.c index 371a23d..db0fc44 100644 --- a/examples.ext/helloworld.c +++ b/examples.ext/helloworld.c @@ -19,6 +19,8 @@ Hello_Cmd(Jim_Interp *interp, int objc, Jim_Obj *const objv[]) int Jim_helloworldInit(Jim_Interp *interp) { - Jim_CreateCommand(interp, "hello", Hello_Cmd, NULL, NULL); + /* Register the package with Jim and check that the ABI matches the interpreter */ + Jim_PackageProvideCheck(interp, "helloworld"); + Jim_RegisterSimpleCmd(interp, "hello", "", 0, 0, Hello_Cmd); return JIM_OK; } |