Index: generic/nsf.c =================================================================== diff -u -r40b842e5b218cc6144506ff4689671b780c4e8c5 -rb2781b9db53d2d06c1c82a62d8f4140b461ec47e --- generic/nsf.c (.../nsf.c) (revision 40b842e5b218cc6144506ff4689671b780c4e8c5) +++ generic/nsf.c (.../nsf.c) (revision b2781b9db53d2d06c1c82a62d8f4140b461ec47e) @@ -28728,12 +28728,13 @@ /* cmd parseargs NsfParseArgsCmd { + {-argName "-asdict" -nrargs 0 -required 0 -type switch} {-argName "argspec" -required 1 -type tclobj} {-argName "arglist" -required 1 -type tclobj} } {-nxdoc 0} */ static int -NsfParseArgsCmd(Tcl_Interp *interp, Tcl_Obj *argspecObj, Tcl_Obj *arglistObj) { +NsfParseArgsCmd(Tcl_Interp *interp, int withAsDict, Tcl_Obj *argspecObj, Tcl_Obj *arglistObj) { NsfParsedParam parsedParam; Tcl_Obj **objv; int result, objc; @@ -28766,18 +28767,32 @@ Tcl_Obj *resultObj; int i; + if (withAsDict == 1) { + resultObj = Tcl_NewDictObj(); + } + for (i = 0, paramPtr = paramDefs->paramsPtr; paramPtr->name != NULL; paramPtr++, i++) { Tcl_Obj *valueObj = pc.objv[i]; if (valueObj != NsfGlobalObjs[NSF___UNKNOWN__]) { /*fprintf(stderr, "param %s -> <%s>\n", paramPtr->name, ObjStr(valueObj));*/ - resultObj = Tcl_ObjSetVar2(interp, paramPtr->nameObj, NULL, valueObj, TCL_LEAVE_ERR_MSG); - if (resultObj == NULL) { - result = TCL_ERROR; - break; + if (withAsDict == 0) { + resultObj = Tcl_ObjSetVar2(interp, paramPtr->nameObj, NULL, valueObj, TCL_LEAVE_ERR_MSG); + if (resultObj == NULL) { + result = TCL_ERROR; + break; + } + } else { + result = Tcl_DictObjPut(interp, resultObj, paramPtr->nameObj, valueObj); + if (result == TCL_ERROR) { + break; + } } } } + if (withAsDict == 1 && result == TCL_OK) { + Tcl_SetObjResult(interp, resultObj); + } } ParamDefsRefCountDecr(paramDefs); ParseContextRelease(&pc); @@ -32447,7 +32462,7 @@ /* * The value exists. */ - Tcl_SetObjResult(interp, resultObj); + Tcl_SetObjResult(interp, resultObj); } } } Index: generic/nsfAPI.decls =================================================================== diff -u -rf0f87b41b6bb57a518fc1bc52fd2f3422d7a9b07 -rb2781b9db53d2d06c1c82a62d8f4140b461ec47e --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision f0f87b41b6bb57a518fc1bc52fd2f3422d7a9b07) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision b2781b9db53d2d06c1c82a62d8f4140b461ec47e) @@ -148,6 +148,7 @@ } cmd parseargs NsfParseArgsCmd { + {-argName "-asdict" -nrargs 0 -required 0 -type switch} {-argName "argspec" -required 1 -type tclobj} {-argName "arglist" -required 1 -type tclobj} } {-nxdoc 0} Index: generic/nsfAPI.h =================================================================== diff -u -rf0f87b41b6bb57a518fc1bc52fd2f3422d7a9b07 -rb2781b9db53d2d06c1c82a62d8f4140b461ec47e --- generic/nsfAPI.h (.../nsfAPI.h) (revision f0f87b41b6bb57a518fc1bc52fd2f3422d7a9b07) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision b2781b9db53d2d06c1c82a62d8f4140b461ec47e) @@ -791,8 +791,8 @@ NSF_nonnull(1) NSF_nonnull(3); static int NsfParameterSpecsCmd(Tcl_Interp *interp, int withConfigure, int withNonposargs, Tcl_Obj *slotobjsObj) NSF_nonnull(1) NSF_nonnull(4); -static int NsfParseArgsCmd(Tcl_Interp *interp, Tcl_Obj *argspecObj, Tcl_Obj *arglistObj) - NSF_nonnull(1) NSF_nonnull(2) NSF_nonnull(3); +static int NsfParseArgsCmd(Tcl_Interp *interp, int withAsdict, Tcl_Obj *argspecObj, Tcl_Obj *arglistObj) + NSF_nonnull(1) NSF_nonnull(3) NSF_nonnull(4); static int NsfProcCmd(Tcl_Interp *interp, int withAd, int withCheckalways, int withDebug, int withDeprecated, Tcl_Obj *procNameObj, Tcl_Obj *argumentsObj, Tcl_Obj *bodyObj) NSF_nonnull(1) NSF_nonnull(6) NSF_nonnull(7) NSF_nonnull(8); static int NsfProfileClearDataStub(Tcl_Interp *interp) @@ -2588,11 +2588,12 @@ method_definitions[NsfParseArgsCmdIdx].paramDefs, method_definitions[NsfParseArgsCmdIdx].nrParameters, 0, NSF_ARGPARSE_BUILTIN, &pc) == TCL_OK)) { - Tcl_Obj *argspecObj = (Tcl_Obj *)pc.clientData[0]; - Tcl_Obj *arglistObj = (Tcl_Obj *)pc.clientData[1]; + int withAsdict = (int )PTR2INT(pc.clientData[0]); + Tcl_Obj *argspecObj = (Tcl_Obj *)pc.clientData[1]; + Tcl_Obj *arglistObj = (Tcl_Obj *)pc.clientData[2]; assert(pc.status == 0); - return NsfParseArgsCmd(interp, argspecObj, arglistObj); + return NsfParseArgsCmd(interp, withAsdict, argspecObj, arglistObj); } else { @@ -4171,7 +4172,8 @@ {"-nonposargs", 0, 0, Nsf_ConvertTo_Boolean, NULL,NULL,"switch",NULL,NULL,NULL,NULL,NULL}, {"slotobjs", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, -{"::nsf::parseargs", NsfParseArgsCmdStub, 2, { +{"::nsf::parseargs", NsfParseArgsCmdStub, 3, { + {"-asdict", 0, 0, Nsf_ConvertTo_Boolean, NULL,NULL,"switch",NULL,NULL,NULL,NULL,NULL}, {"argspec", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"arglist", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, Index: tests/parameters.test =================================================================== diff -u -r78c12b94b4cdcd5edb70a546b7bbb7c0a4724668 -rb2781b9db53d2d06c1c82a62d8f4140b461ec47e --- tests/parameters.test (.../parameters.test) (revision 78c12b94b4cdcd5edb70a546b7bbb7c0a4724668) +++ tests/parameters.test (.../parameters.test) (revision b2781b9db53d2d06c1c82a62d8f4140b461ec47e) @@ -3467,6 +3467,10 @@ list [info exists foo] [info exists bar] [info exists baz] } "0 1 1" + ? { + nsf::parseargs -asdict {-foo:int {-bar:int 2} baz} {hi} + } "bar 2 baz hi" + # # Test with empty list of actual arguments #