Index: TODO =================================================================== diff -u -r6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- TODO (.../TODO) (revision 6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1) +++ TODO (.../TODO) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -4452,6 +4452,13 @@ * "/obj/ delete object property" * "/obj/ delete object variable" +- extended parameter extractor. new functionality + + ::nsf::parameter get default /parameter/ ?/varname/? + ::nsf::parameter get type /parameter/ + /obj/ info parameter get default /parameter/ ?/varname/? + /obj/ info parameter get type /parameter/ + ======================================================================== TODO: - The two names are not appropriate @@ -4462,7 +4469,6 @@ - valuechangedcmd implemented via initcmd does not work with "configure" method - info AddSlotObjects(): handle full-qualified name for private slots -- NsfParameterGetCmd should/could handle more than "list|name|syntax" - fix property inheritance in traits (nx-traits.tcl) - maybe remove unneeded values, align naming in enumeration of first arg of *::info::objectparameter and *::info::method Index: generic/nsf.c =================================================================== diff -u -r98b60429d7f10bf637fa2cfa2bb88d4069e2445f -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- generic/nsf.c (.../nsf.c) (revision 98b60429d7f10bf637fa2cfa2bb88d4069e2445f) +++ generic/nsf.c (.../nsf.c) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -20986,46 +20986,86 @@ /* cmd parameter::get NsfParameterGetCmd { - {-argName "parametersubcmd" -type "list|name|syntax" -required 1} - {-argName "parameterspec" -required 1 -type tclobj} + {-argName "parametersubcmd" -type "default|list|name|syntax|type" -required 1} + {-argName "parameterspec" -required 1 -type tclobj} + {-argName "varname" -required 0 -type tclobj} } */ static int -NsfParameterGetCmd(Tcl_Interp *interp, int parametersubcmd, Tcl_Obj *parameterspec) { +NsfParameterGetCmd(Tcl_Interp *interp, int parametersubcmd, Tcl_Obj *parameterspec, Tcl_Obj *varname) { NsfParsedParam parsedParam; - Tcl_Obj *paramsObj = Tcl_NewListObj(1, ¶meterspec), *listObj = NULL; + Tcl_Obj *paramsObj, *listObj = NULL; Nsf_Param *paramsPtr; int result; + if (parametersubcmd != ParametersubcmdDefaultIdx && varname != NULL) { + return NsfPrintError(interp, "parameter::get: provided third arguement is only valid for querying defaults"); + } + + paramsObj = Tcl_NewListObj(1, ¶meterspec); + INCR_REF_COUNT(paramsObj); result = ParamDefsParse(interp, NULL, paramsObj, NSF_DISALLOWED_ARG_OBJECT_PARAMETER, 1, &parsedParam); + DECR_REF_COUNT(paramsObj); + if (result != TCL_OK) { return result; } paramsPtr = parsedParam.paramDefs->paramsPtr; switch (parametersubcmd) { + case ParametersubcmdDefaultIdx: + if (paramsPtr->defaultValue) { + if (varname) { + Tcl_Obj *resultObj = Tcl_ObjSetVar2(interp, varname, NULL, + paramsPtr->defaultValue, + TCL_LEAVE_ERR_MSG|TCL_PARSE_PART1); + if (resultObj == NULL) { + ParamDefsRefCountDecr(parsedParam.paramDefs); + return TCL_ERROR; + } + } + Tcl_SetObjResult(interp, NsfGlobalObjs[NSF_ONE]); + } else { + Tcl_SetObjResult(interp, NsfGlobalObjs[NSF_ZERO]); + } + break; + case ParametersubcmdListIdx: listObj = ParamDefsList(interp, paramsPtr); + Tcl_SetObjResult(interp, listObj); + DECR_REF_COUNT2("paramDefsObj", listObj); break; + case ParametersubcmdNameIdx: listObj = ParamDefsNames(interp, paramsPtr); + Tcl_SetObjResult(interp, listObj); + DECR_REF_COUNT2("paramDefsObj", listObj); break; - /* case InfoobjectparametersubcmdParameterIdx: - listObj = ParamDefsFormat(interp, paramsPtr); - break;*/ + case ParametersubcmdSyntaxIdx: listObj = NsfParamDefsSyntax(paramsPtr); + Tcl_SetObjResult(interp, listObj); + DECR_REF_COUNT2("paramDefsObj", listObj); break; + + case ParametersubcmdTypeIdx: + if (paramsPtr->type) { + if (paramsPtr->converter == Nsf_ConvertToTclobj && paramsPtr->converterArg) { + Tcl_SetObjResult(interp, paramsPtr->converterArg); + } else { + Tcl_SetObjResult(interp, Tcl_NewStringObj(paramsPtr->type, -1)); + } + } else { + Tcl_SetObjResult(interp, NsfGlobalObjs[NSF_EMPTY]); + } + break; } - assert(listObj); - Tcl_SetObjResult(interp, listObj); - - DECR_REF_COUNT2("paramDefsObj", listObj); ParamDefsRefCountDecr(parsedParam.paramDefs); + return TCL_OK; } Index: generic/nsfAPI.decls =================================================================== diff -u -rfc77eaadabdd690239694a6f1cf155a7d16b5cd4 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision fc77eaadabdd690239694a6f1cf155a7d16b5cd4) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -71,8 +71,9 @@ cmd parameter::get NsfParameterGetCmd { - {-argName "parametersubcmd" -type "list|name|syntax" -required 1} - {-argName "parameterspec" -required 1 -type tclobj} + {-argName "parametersubcmd" -type "default|list|name|syntax|type" -required 1} + {-argName "parameterspec" -required 1 -type tclobj} + {-argName "varname" -required 0 -type tclobj} } cmd parameter:invalidate::classcache NsfParameterInvalidateClassCacheCmd { Index: generic/nsfAPI.h =================================================================== diff -u -rfc77eaadabdd690239694a6f1cf155a7d16b5cd4 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- generic/nsfAPI.h (.../nsfAPI.h) (revision fc77eaadabdd690239694a6f1cf155a7d16b5cd4) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -162,12 +162,12 @@ return result; } -enum ParametersubcmdIdx {ParametersubcmdNULL, ParametersubcmdListIdx, ParametersubcmdNameIdx, ParametersubcmdSyntaxIdx}; +enum ParametersubcmdIdx {ParametersubcmdNULL, ParametersubcmdDefaultIdx, ParametersubcmdListIdx, ParametersubcmdNameIdx, ParametersubcmdSyntaxIdx, ParametersubcmdTypeIdx}; static int ConvertToParametersubcmd(Tcl_Interp *interp, Tcl_Obj *objPtr, Nsf_Param CONST *pPtr, ClientData *clientData, Tcl_Obj **outObjPtr) { int index, result; - static CONST char *opts[] = {"list", "name", "syntax", NULL}; + static CONST char *opts[] = {"default", "list", "name", "syntax", "type", NULL}; (void)pPtr; result = Tcl_GetIndexFromObj(interp, objPtr, opts, "parametersubcmd", 0, &index); *clientData = (ClientData) INT2PTR(index + 1); @@ -230,7 +230,7 @@ {ConvertToConfigureoption, "debug|dtrace|filter|profile|softrecreate|objectsystems|keepinitcmd|checkresults|checkarguments"}, {ConvertToObjectproperty, "initialized|class|rootmetaclass|rootclass|volatile|slotcontainer|hasperobjectslots|keepcallerself|perobjectdispatch"}, {ConvertToAssertionsubcmd, "check|object-invar|class-invar"}, - {ConvertToParametersubcmd, "list|name|syntax"}, + {ConvertToParametersubcmd, "default|list|name|syntax|type"}, {NULL, NULL} }; @@ -401,7 +401,7 @@ static int NsfObjectPropertyCmd(Tcl_Interp *interp, NsfObject *objectName, int objectproperty, Tcl_Obj *value); static int NsfObjectQualifyCmd(Tcl_Interp *interp, Tcl_Obj *objectName); static int NsfObjectSystemCreateCmd(Tcl_Interp *interp, Tcl_Obj *rootClass, Tcl_Obj *rootMetaClass, Tcl_Obj *systemMethods); -static int NsfParameterGetCmd(Tcl_Interp *interp, int parametersubcmd, Tcl_Obj *parameterspec); +static int NsfParameterGetCmd(Tcl_Interp *interp, int parametersubcmd, Tcl_Obj *parameterspec, Tcl_Obj *varname); static int NsfParameterInvalidateClassCacheCmd(Tcl_Interp *interp, NsfClass *class); static int NsfParameterInvalidateObjectCacheCmd(Tcl_Interp *interp, NsfObject *object); static int NsfParameterSpecsCmd(Tcl_Interp *interp, int withConfigure, int withNonposargs, Tcl_Obj *slotobjs); @@ -1659,9 +1659,10 @@ &pc) == TCL_OK)) { int parametersubcmd = (int )PTR2INT(pc.clientData[0]); Tcl_Obj *parameterspec = (Tcl_Obj *)pc.clientData[1]; + Tcl_Obj *varname = (Tcl_Obj *)pc.clientData[2]; assert(pc.status == 0); - return NsfParameterGetCmd(interp, parametersubcmd, parameterspec); + return NsfParameterGetCmd(interp, parametersubcmd, parameterspec, varname); } else { return TCL_ERROR; @@ -2911,9 +2912,10 @@ {"rootMetaClass", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"systemMethods", 0, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, -{"::nsf::parameter::get", NsfParameterGetCmdStub, 2, { +{"::nsf::parameter::get", NsfParameterGetCmdStub, 3, { {"parametersubcmd", NSF_ARG_REQUIRED|NSF_ARG_IS_ENUMERATION, 1, ConvertToParametersubcmd, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {"parameterspec", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} + {"parameterspec", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, + {"varname", 0, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, {"::nsf::parameter:invalidate::classcache", NsfParameterInvalidateClassCacheCmdStub, 1, { {"class", NSF_ARG_REQUIRED, 1, Nsf_ConvertToClass, NULL,NULL,"class",NULL,NULL,NULL,NULL,NULL}} Index: library/nx/nx.tcl =================================================================== diff -u -r6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- library/nx/nx.tcl (.../nx.tcl) (revision 6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1) +++ library/nx/nx.tcl (.../nx.tcl) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -726,8 +726,16 @@ # # Parameter extractors # - :method "info parameter syntax" {p:parameter} {::nsf::parameter::get syntax $p} - :method "info parameter name" {p:parameter} {::nsf::parameter::get name $p} + :method "info parameter default" {p:parameter varName:optional} { + if {[info exists varName]} { + uplevel [list ::nsf::parameter::get default $p $varName] + } else { + ::nsf::parameter::get default $p + } + } + :method "info parameter name" {p:parameter} {::nsf::parameter::get name $p} + :method "info parameter syntax" {p:parameter} {::nsf::parameter::get syntax $p} + :method "info parameter type" {p:parameter} {::nsf::parameter::get type $p} :alias "info parent" ::nsf::methods::object::info::parent :alias "info precedence" ::nsf::methods::object::info::precedence Index: tests/info-method.test =================================================================== diff -u -r0ae1c72ceda94c7f6c99b86a1d7f14eaaef12e78 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- tests/info-method.test (.../info-method.test) (revision 0ae1c72ceda94c7f6c99b86a1d7f14eaaef12e78) +++ tests/info-method.test (.../info-method.test) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -729,7 +729,7 @@ ? {lsort [::nx::Object info methods -path "info lookup *"]} \ "{info lookup configure parameters} {info lookup configure syntax} {info lookup filter} {info lookup method} {info lookup methods} {info lookup slots} {info lookup variables}" ? {lsort [::nx::Object info methods -path "info *parameter*"]} \ - "{info lookup configure parameters} {info object method parameters} {info parameter name} {info parameter syntax} {info variable parameter}" + "{info lookup configure parameters} {info object method parameters} {info parameter default} {info parameter name} {info parameter syntax} {info parameter type} {info variable parameter}" ? {lsort [::nx::Object info methods "slots"]} "" ? {lsort [::nx::Object info methods "*slots*"]} "" ? {lsort [::nx::Object info methods -path "*slot*"]} \ Index: tests/info-variable.test =================================================================== diff -u -r6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1 -r2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4 --- tests/info-variable.test (.../info-variable.test) (revision 6fd5b9d632efe378ecf7df0ecfb0a2ef6b39b7c1) +++ tests/info-variable.test (.../info-variable.test) (revision 2d9fcf7f4dc9ccd8ac52702850f60724a04bcba4) @@ -52,6 +52,9 @@ ? {Person info parameter syntax -force:switch} "?-force?" ? {Person info parameter name "a b"} "a" + ? {lmap p [Person info configure parameters] {nsf::parameter::get default $p}} "0 0 0 0 0 0 0 0" + ? {lmap p [Person info method parameters foo] {nsf::parameter::get default $p}} "1 0 1" + nx::Class create Bar { :property {p 9} } @@ -68,6 +71,13 @@ :create f1 } + ? {lmap p [Foo info configure parameters] {nsf::parameter::get name $p}} \ + "i a b p volatile noinit object-mixin class object-filter __initcmd" + ? {lmap p [Foo info configure parameters] {nsf::parameter::get default $p}} \ + "0 0 1 1 0 0 0 0 0 0" + ? {lmap p [Foo info configure parameters] {nsf::parameter::get type $p}} \ + "{} integer integer {} {} {} mixinreg class filterreg {}" + ? {join [lsort [::Foo info slots]] \n} \ "::Foo::slot::____Foo.p ::Foo::slot::a @@ -85,7 +95,7 @@ ? {::Foo::slot::d definition} "::Foo variable -accessor none d:lower abc" ? {::Foo::slot::e definition} "::Foo variable -accessor public e:lower efg" ? {::Foo::slot::q definition} "::Foo variable -accessor protected q" - + ? {join [lsort [::f1 info lookup slots]] \n} \ "::Bar::slot::p ::Foo::slot::____Foo.p @@ -153,7 +163,9 @@ ::Foo property -accessor public -incremental i:0..n ::Foo variable -accessor protected q" - ? {join [lmap handle $::vs {::Foo info variable parameter $handle}] \n} \ + set ::ps [lmap handle $::vs {::Foo info variable parameter $handle}] + + ? {join $::ps \n} \ "p 19 a:integer b:integer 123 @@ -165,6 +177,20 @@ ? {lmap handle $::vs {::Foo info variable name $handle}} \ "__private(::Foo,p) a b c d e i q" + + ? {lmap handle $::ps {::Foo info parameter name $handle}} \ + "p a b c d e i q" + ? {lmap handle $::ps {::Foo info parameter default $handle}} \ + "1 0 1 1 1 1 0 0" + ? {lmap handle $::ps {::Foo info parameter type $handle}} \ + "{} integer integer {} lower lower {} {}" + + ? {nsf::parameter::get default "b:integer 123" ::var1} "1" + ? {set ::var1} "123" + + ? {::Foo info parameter default "b:integer 123" ::var2} "1" + ? {set ::var2} "123" + } nx::Test case object-variables {