Index: generic/nsf.c =================================================================== diff -u -r3301d2725d88fb4bd485ef4024f4fb31eea65c9e -r7f58a3a3dd12990de3dfc8096a85d2341cf02075 --- generic/nsf.c (.../nsf.c) (revision 3301d2725d88fb4bd485ef4024f4fb31eea65c9e) +++ generic/nsf.c (.../nsf.c) (revision 7f58a3a3dd12990de3dfc8096a85d2341cf02075) @@ -25734,6 +25734,24 @@ } /* +cmd "definitionnamespace" NsfDefinitionNamespaceCmd { +} +*/ +static int +NsfDefinitionNamespaceCmd(Tcl_Interp *interp) +{ + Tcl_Namespace *nsPtr; + + nonnull_assert(interp != NULL); + + nsPtr = CallingNameSpace(interp); + Tcl_SetObjResult(interp, Tcl_NewStringObj(nsPtr->fullName, -1)); + + return TCL_OK; +} + + +/* cmd "directdispatch" NsfDirectDispatchCmd { {-argName "object" -required 1 -type object} {-argName "-frame" -required 0 -nrargs 1 -type "method|object|default" -default "default"} Index: generic/nsfAPI.decls =================================================================== diff -u -r81788340d06828bb7131be38cc31858cf842612e -r7f58a3a3dd12990de3dfc8096a85d2341cf02075 --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision 81788340d06828bb7131be38cc31858cf842612e) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision 7f58a3a3dd12990de3dfc8096a85d2341cf02075) @@ -95,6 +95,9 @@ cmd colon NsfColonCmd { {-argName "args" -type allargs} } +cmd "definitionnamespace" NsfDefinitionNamespaceCmd { +} + cmd "directdispatch" NsfDirectDispatchCmd { {-argName "object" -required 1 -type object} {-argName "-frame" -typeName "frame" -required 0 -type "method|object|default" -default "default"} Index: generic/nsfAPI.h =================================================================== diff -u -r81788340d06828bb7131be38cc31858cf842612e -r7f58a3a3dd12990de3dfc8096a85d2341cf02075 --- generic/nsfAPI.h (.../nsfAPI.h) (revision 81788340d06828bb7131be38cc31858cf842612e) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision 7f58a3a3dd12990de3dfc8096a85d2341cf02075) @@ -281,7 +281,7 @@ /* just to define the symbol */ -static Nsf_methodDefinition method_definitions[119]; +static Nsf_methodDefinition method_definitions[120]; static const char *method_command_namespace_names[] = { "::nsf::methods::object::info", @@ -363,6 +363,8 @@ NSF_nonnull(2) NSF_nonnull(4); static int NsfDebugShowObjStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) NSF_nonnull(2) NSF_nonnull(4); +static int NsfDefinitionNamespaceCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) + NSF_nonnull(2) NSF_nonnull(4); static int NsfDirectDispatchCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) NSF_nonnull(2) NSF_nonnull(4); static int NsfDispatchCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) @@ -600,6 +602,8 @@ NSF_nonnull(1); static int NsfDebugShowObj(Tcl_Interp *interp, Tcl_Obj *obj) NSF_nonnull(1) NSF_nonnull(2); +static int NsfDefinitionNamespaceCmd(Tcl_Interp *interp) + NSF_nonnull(1); static int NsfDirectDispatchCmd(Tcl_Interp *interp, NsfObject *object, FrameIdx_t withFrame, Tcl_Obj *command, int nobjc, Tcl_Obj *CONST* nobjv) NSF_nonnull(1) NSF_nonnull(2) NSF_nonnull(4); static int NsfDispatchCmd(Tcl_Interp *interp, NsfObject *object, int withIntrinsic, int withSystem, Tcl_Obj *command, int nobjc, Tcl_Obj *CONST* nobjv) @@ -801,6 +805,7 @@ NsfDebugGetDictIdx, NsfDebugRunAssertionsCmdIdx, NsfDebugShowObjIdx, + NsfDefinitionNamespaceCmdIdx, NsfDirectDispatchCmdIdx, NsfDispatchCmdIdx, NsfFinalizeCmdIdx, @@ -1791,6 +1796,22 @@ } static int +NsfDefinitionNamespaceCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { + (void)clientData; + + + + if (unlikely(objc != 1)) { + return NsfArgumentError(interp, "too many arguments:", + method_definitions[NsfDefinitionNamespaceCmdIdx].paramDefs, + NULL, objv[0]); + } + + return NsfDefinitionNamespaceCmd(interp); + +} + +static int NsfDirectDispatchCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST* objv) { ParseContext pc; (void)clientData; @@ -3588,7 +3609,7 @@ } } -static Nsf_methodDefinition method_definitions[119] = { +static Nsf_methodDefinition method_definitions[120] = { {"::nsf::methods::class::alloc", NsfCAllocMethodStub, 1, { {"objectName", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, @@ -3740,6 +3761,9 @@ {"::nsf::__db_show_obj", NsfDebugShowObjStub, 1, { {"obj", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, +{"::nsf::definitionnamespace", NsfDefinitionNamespaceCmdStub, 0, { + {NULL, 0, 0, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, {"::nsf::directdispatch", NsfDirectDispatchCmdStub, 4, { {"object", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Object, NULL,NULL,"object",NULL,NULL,NULL,NULL,NULL}, {"-frame", NSF_ARG_IS_ENUMERATION, 1, ConvertToFrame, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, Index: tests/substdefault.test =================================================================== diff -u -r25212e40eb097eebcf48d54931bde2bc90e94e69 -r7f58a3a3dd12990de3dfc8096a85d2341cf02075 --- tests/substdefault.test (.../substdefault.test) (revision 25212e40eb097eebcf48d54931bde2bc90e94e69) +++ tests/substdefault.test (.../substdefault.test) (revision 7f58a3a3dd12990de3dfc8096a85d2341cf02075) @@ -50,7 +50,7 @@ #? {::d1 eval :__object_configureparameter} "" - ? {d1 show} {a $::X [set x 4] \t-a 123 4 -a 123 4 -a $::X [set x 4] -a 123 [set x 4] \t-a $::X 4 \t-a $::X [set x 4] \t} + ? {d1 show} {a $::X [set x 4] \t-a 123 4 -a 123 4 -a $::X [set x 4] -a 123 [set x 4] \t-a $::X 4 \t-a $::X [set x 4] \t} unset ::X } @@ -169,37 +169,120 @@ nx::Class create C { :object variable Y 1002 :object property -accessor public {Z 1003} + namespace eval [nsf::definitionnamespace] {set A 2000} :method file-scoped {x} { namespace eval ::my-module [list set $x ] } :method "object getvar" {x} { namespace eval [current class] [list set $x ] } + :method "definitionnamespace" {x} { + namespace eval [nsf::definitionnamespace] [list set $x ] + } + :public method "current_definitionnamespace" {} { + return [nsf::definitionnamespace] + } + :method "current" {x} { return [current $x] } :property {e:substdefault "[:file-scoped X]"} :property {f:substdefault "[:object getvar Y]"} :property {g:substdefault "[current class]"} :property {h:substdefault "[:current class]"} :property {i:substdefault "[[:current class] Z get]"} + :property {j:substdefault "[:definitionnamespace A]"} :create c1 :public method show {} { - return ${:e}-${:f}-${:g}-${:h}-${:i} + return ${:e}-${:f}-${:g}-${:h}-${:i}-${:j} } } # # One can use methods to access e.h. for method parameters. # UNEXPECTED: for "g" where i would expect "::C". # - ? {c1 show} {1001-1002-::nx::Class-::C-1003} - + ? {c1 show} {1001-1002-::nx::Class-::C-1003-2000} + ? {c1 current_definitionnamespace} {::} } +####################################################### +# subst default tests for object properties +####################################################### +nx::test case subst-default-object-parameters-in-extra-ns { + namespace eval ::my-module { + set X 1001 + + nx::Class create D { + :object variable Y 1002 + + :property {a "[current]"} + :property {b:substdefault "[current]"} + :property {c:substdefault "[info vars]"} + :property {d:substdefault "[:info vars]"} + + :create d1 + + :public method show {} { + return ${:a}-${:b}-${:c}-${:d} + } + } + + # + # The scope of "current" in the substdefault is "::d1", the same as + # for method parameters. + # + ? {d1 show} {[current]-::my-module::d1--} + + ? {nsf::definitionnamespace} ::my-module + + nx::Class create C { + :object variable Y 1002 + :object property -accessor public {Z 1003} + namespace eval [nsf::definitionnamespace] {set A 2000} + + :method file-scoped {x} { + namespace eval ::my-module [list set $x ] + } + :method "object getvar" {x} { + namespace eval [current class] [list set $x ] + } + :method "definitionnamespace" {x} { + namespace eval [nsf::definitionnamespace] [list set $x ] + } + :public method "current_definitionnamespace" {} { + return [nsf::definitionnamespace] + } + + :method "current" {x} { return [current $x] } + + :property {e:substdefault "[:file-scoped X]"} + :property {f:substdefault "[:object getvar Y]"} + :property {g:substdefault "[current class]"} + :property {h:substdefault "[:current class]"} + :property {i:substdefault "[[:current class] Z get]"} + :property {j:substdefault "[:definitionnamespace A]"} + + :create c1 + + :public method show {} { + return ${:e}-${:f}-${:g}-${:h}-${:i}-${:j} + } + } + + # + # One can use methods to access e.h. for method parameters. + # UNEXPECTED: for "g" where i would expect "::C". + # + ? {c1 show} {1001-1002-::nx::Class-::my-module::C-1003-2000} + ? {c1 current_definitionnamespace} {::my-module} + + } +} + # # Local variables: # mode: tcl