Index: generic/nsf.c =================================================================== diff -u -rced9ad76621829c8f4e8a232335d494ab462252e -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- generic/nsf.c (.../nsf.c) (revision ced9ad76621829c8f4e8a232335d494ab462252e) +++ generic/nsf.c (.../nsf.c) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -5747,21 +5747,6 @@ return listObj; } -/* append a string of pre and post assertions to a method body */ -static void -AssertionAppendPrePost(Tcl_Interp *interp, Tcl_DString *dsPtr, NsfProcAssertion *procs) { - if (procs) { - Tcl_Obj *preCondition = AssertionList(interp, procs->pre); - Tcl_Obj *postCondition = AssertionList(interp, procs->post); - INCR_REF_COUNT(preCondition); INCR_REF_COUNT(postCondition); - Tcl_DStringAppendElement(dsPtr, "-precondition"); - Tcl_DStringAppendElement(dsPtr, ObjStr(preCondition)); - Tcl_DStringAppendElement(dsPtr, "-postcondition"); - Tcl_DStringAppendElement(dsPtr, ObjStr(postCondition)); - DECR_REF_COUNT(preCondition); DECR_REF_COUNT(postCondition); - } -} - static int AssertionListCheckOption(Tcl_Interp *interp, NsfObject *object) { NsfObjectOpt *opt = object->opt; @@ -20712,237 +20697,6 @@ } /* -cmd nscopycmds NsfNSCopyCmdsCmd { - {-argName "fromNs" -required 1 -type tclobj} - {-argName "toNs" -required 1 -type tclobj} -} -*/ -static int -NsfNSCopyCmdsCmd(Tcl_Interp *interp, Tcl_Obj *fromNs, Tcl_Obj *toNs) { - Tcl_Command cmd; - Tcl_Obj *newFullCmdName, *oldFullCmdName; - CONST char *newName, *oldName, *name; - Tcl_Namespace *fromNsPtr, *toNsPtr; - Tcl_HashTable *cmdTablePtr; - Tcl_HashSearch hSrch; - Tcl_HashEntry *hPtr; - NsfObject *object; - NsfClass *cl; - int fromClassNS; - - if (TclGetNamespaceFromObj(interp, fromNs, &fromNsPtr) != TCL_OK) { - return TCL_OK; - } - - name = ObjStr(fromNs); - - /* check, if we work on an object or class namespace */ - object = GetObjectFromNsName(interp, name, &fromClassNS); - - if (unlikely(object == NULL)) { - return NsfPrintError(interp, "argument 1 '%s' is not an object", ObjStr(fromNs)); - } - - cl = fromClassNS ? (NsfClass *)object : NULL; - - if (TclGetNamespaceFromObj(interp, toNs, &toNsPtr) != TCL_OK) { - return NsfPrintError(interp, "CopyCmds: Destination namespace %s does not exist", - ObjStr(toNs)); - } - /* - * Copy all procs & commands in the namespace. - */ - cmdTablePtr = Tcl_Namespace_cmdTablePtr(fromNsPtr); - hPtr = Tcl_FirstHashEntry(cmdTablePtr, &hSrch); - while (hPtr) { - /*fprintf(stderr, "copy cmdTablePtr = %p, first=%p\n", cmdTablePtr, hPtr);*/ - name = Tcl_GetHashKey(cmdTablePtr, hPtr); - - /* - * Construct full cmd names. - */ - newFullCmdName = Tcl_NewStringObj(toNsPtr->fullName, -1); - oldFullCmdName = Tcl_NewStringObj(fromNsPtr->fullName, -1); - - INCR_REF_COUNT(newFullCmdName); INCR_REF_COUNT(oldFullCmdName); - Tcl_AppendStringsToObj(newFullCmdName, "::", name, (char *) NULL); - Tcl_AppendStringsToObj(oldFullCmdName, "::", name, (char *) NULL); - newName = ObjStr(newFullCmdName); - oldName = ObjStr(oldFullCmdName); - - /*fprintf(stderr, "try to copy command from '%s' to '%s'\n", oldName, newName);*/ - /* - * Make sure that the destination command does not already exist. - * Otherwise: do not copy. - */ - cmd = Tcl_FindCommand(interp, newName, NULL, TCL_GLOBAL_ONLY); - - fprintf(stderr, "wanna copy %s to %p (new cmd %p)\n", oldName, newName, cmd); - - if (cmd) { - /*fprintf(stderr, "%s already exists\n", newName);*/ - if (!GetObjectFromString(interp, newName)) { - /* command or scripted method will be deleted & then copied */ - Tcl_DeleteCommandFromToken(interp, cmd); - } else { - /* don't overwrite objects -> will be recreated */ - hPtr = Tcl_NextHashEntry(&hSrch); - DECR_REF_COUNT(newFullCmdName); - DECR_REF_COUNT(oldFullCmdName); - continue; - } - } - - /* - * Find the existing command. An error is returned if simpleName can't - * be found. - */ - cmd = Tcl_FindCommand(interp, oldName, NULL, TCL_GLOBAL_ONLY); - if (cmd == NULL) { - NsfPrintError(interp, "can't copy \"%s\": command doesn't exist", oldName); - DECR_REF_COUNT(newFullCmdName); - DECR_REF_COUNT(oldFullCmdName); - return TCL_ERROR; - } - /* - * Do not copy Objects or Classes. - */ - if (!GetObjectFromString(interp, oldName)) { - - if (CmdIsProc(cmd)) { -#if 0 - Proc *procPtr = (Proc *)Tcl_Command_objClientData(cmd); - Tcl_Obj *arglistObj; - int result; - - /* - * Build a list containing the arguments of the proc. - */ - result = ListCmdParams(interp, cmd, oldName, NSF_PARAMS_PARAMETER); - if (result != TCL_OK) { - return result; - } - - arglistObj = Tcl_GetObjResult(interp); - INCR_REF_COUNT(arglistObj); - - if (Tcl_Command_objProc(cmd) == RUNTIME_STATE(interp)->objInterpProc) { - Tcl_DString ds, *dsPtr = &ds; - - if (cl) { - /* Next Scripting class-methods */ -#if defined(NSF_WITH_ASSERTIONS) - NsfProcAssertion *procs; - procs = cl->opt ? AssertionFindProcs(cl->opt->assertions, name) : NULL; -#endif - - DSTRING_INIT(dsPtr); - Tcl_DStringAppendElement(dsPtr, "::nsf::method::create"); - Tcl_DStringAppendElement(dsPtr, NSCutNsfClasses(toNsPtr->fullName)); - Tcl_DStringAppendElement(dsPtr, name); - Tcl_DStringAppendElement(dsPtr, ObjStr(arglistObj)); - Tcl_DStringAppendElement(dsPtr, StripBodyPrefix(ObjStr(procPtr->bodyPtr))); -#if defined(NSF_WITH_ASSERTIONS) - if (procs) { - NsfRequireClassOpt(cl); - AssertionAppendPrePost(interp, dsPtr, procs); - } -#endif - result = Tcl_EvalEx(interp, Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), 0); - DSTRING_FREE(dsPtr); - - } else { - /* Next Scripting object-methods */ - NsfObject *object = GetObjectFromString(interp, fromNsPtr->fullName); -#if defined(NSF_WITH_ASSERTIONS) - NsfProcAssertion *procs; -#endif - - if (object) { -#if defined(NSF_WITH_ASSERTIONS) - procs = object->opt ? AssertionFindProcs(object->opt->assertions, name) : NULL; -#endif - } else { - DECR_REF_COUNT(newFullCmdName); - DECR_REF_COUNT(oldFullCmdName); - DECR_REF_COUNT(arglistObj); - return NsfPrintError(interp, "no object for assertions"); - } - - DSTRING_INIT(dsPtr); - Tcl_DStringAppendElement(dsPtr, "::nsf::method::create"); - Tcl_DStringAppendElement(dsPtr, toNsPtr->fullName); - Tcl_DStringAppendElement(dsPtr, "-per-object"); - Tcl_DStringAppendElement(dsPtr, name); - Tcl_DStringAppendElement(dsPtr, ObjStr(arglistObj)); - Tcl_DStringAppendElement(dsPtr, StripBodyPrefix(ObjStr(procPtr->bodyPtr))); -#if defined(NSF_WITH_ASSERTIONS) - if (procs) { - NsfRequireObjectOpt(object); - AssertionAppendPrePost(interp, dsPtr, procs); - } -#endif - result = Tcl_EvalEx(interp, Tcl_DStringValue(dsPtr), Tcl_DStringLength(dsPtr), 0); - DSTRING_FREE(dsPtr); - } - if (result == TCL_OK) { - NsfParamDefs *paramDefs; - paramDefs = ParamDefsGet(cmd); - - if (paramDefs && paramDefs->returns) { - Tcl_DString ds2, *dsPtr2 = &ds2; - DSTRING_INIT(dsPtr2); - Tcl_DStringAppendElement(dsPtr2, "::nsf::method::property"); - Tcl_DStringAppendElement(dsPtr2, cl ? NSCutNsfClasses(toNsPtr->fullName) : toNsPtr->fullName); - Tcl_DStringAppendElement(dsPtr2, ObjStr(Tcl_GetObjResult(interp))); - Tcl_DStringAppendElement(dsPtr2, "returns"); - Tcl_DStringAppendElement(dsPtr2, ObjStr(paramDefs->returns)); - Tcl_EvalEx(interp, Tcl_DStringValue(dsPtr2), Tcl_DStringLength(dsPtr2), 0); - DSTRING_FREE(dsPtr2); - } - } - DECR_REF_COUNT(arglistObj); - } else { - /* Tcl Proc */ - Tcl_VarEval(interp, "proc ", newName, " {", ObjStr(arglistObj), "} {\n", - ObjStr(procPtr->bodyPtr), "}", (char *) NULL); - } -#endif - } else { - /* - * Otherwise copy command. - */ - Tcl_ObjCmdProc *objProc = Tcl_Command_objProc(cmd); - Tcl_CmdDeleteProc *deleteProc = Tcl_Command_deleteProc(cmd); - ClientData clientData; - - fprintf(stderr, "copy CMD %s objproc %p\n", newName, objProc); - - if (objProc) { - clientData = Tcl_Command_objClientData(cmd); - if (clientData == NULL || clientData == (ClientData)NSF_CMD_NONLEAF_METHOD) { - /* if client data is not null, we would have to copy - the client data; we don't know its size...., so rely - on introspection for copying */ - Tcl_CreateObjCommand(interp, newName, objProc, - Tcl_Command_objClientData(cmd), deleteProc); - } - } else { - clientData = Tcl_Command_clientData(cmd); - if (clientData == NULL || clientData == (ClientData)NSF_CMD_NONLEAF_METHOD) { - Tcl_CreateCommand(interp, newName, Tcl_Command_proc(cmd), - Tcl_Command_clientData(cmd), deleteProc); - } - } - } - } - hPtr = Tcl_NextHashEntry(&hSrch); - DECR_REF_COUNT(newFullCmdName); DECR_REF_COUNT(oldFullCmdName); - } - return TCL_OK; -} - -/* cmd nscopyvars NsfNSCopyVars { {-argName "fromNs" -required 1 -type tclobj} {-argName "toNs" -required 1 -type tclobj} Index: generic/nsfAPI.decls =================================================================== diff -u -r2f6bcca3537584c8ef1f9fc71b230e79d1560504 -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- generic/nsfAPI.decls (.../nsfAPI.decls) (revision 2f6bcca3537584c8ef1f9fc71b230e79d1560504) +++ generic/nsfAPI.decls (.../nsfAPI.decls) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -200,10 +200,6 @@ cmd next NsfNextCmd { {-argName "arguments" -required 0 -type tclobj} } {-nxdoc 1} -cmd nscopycmds NsfNSCopyCmdsCmd { - {-argName "fromNs" -required 1 -type tclobj} - {-argName "toNs" -required 1 -type tclobj} -} cmd nscopyvars NsfNSCopyVarsCmd { {-argName "fromNs" -required 1 -type tclobj} {-argName "toNs" -required 1 -type tclobj} Index: generic/nsfAPI.h =================================================================== diff -u -r2f6bcca3537584c8ef1f9fc71b230e79d1560504 -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- generic/nsfAPI.h (.../nsfAPI.h) (revision 2f6bcca3537584c8ef1f9fc71b230e79d1560504) +++ generic/nsfAPI.h (.../nsfAPI.h) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -236,7 +236,7 @@ /* just to define the symbol */ -static Nsf_methodDefinition method_definitions[106]; +static Nsf_methodDefinition method_definitions[105]; static CONST char *method_command_namespace_names[] = { "::nsf::methods::object::info", @@ -288,7 +288,6 @@ static int NsfMethodRegisteredCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfMethodSetterCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfMyCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); -static int NsfNSCopyCmdsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfNSCopyVarsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfNextCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int NsfObjectExistsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); @@ -394,7 +393,6 @@ static int NsfMethodRegisteredCmd(Tcl_Interp *interp, Tcl_Obj *handle); static int NsfMethodSetterCmd(Tcl_Interp *interp, NsfObject *object, int withPer_object, Tcl_Obj *parameter); static int NsfMyCmd(Tcl_Interp *interp, int withIntrinsic, int withLocal, int withSystem, Tcl_Obj *methodName, int nobjc, Tcl_Obj *CONST nobjv[]); -static int NsfNSCopyCmdsCmd(Tcl_Interp *interp, Tcl_Obj *fromNs, Tcl_Obj *toNs); static int NsfNSCopyVarsCmd(Tcl_Interp *interp, Tcl_Obj *fromNs, Tcl_Obj *toNs); static int NsfNextCmd(Tcl_Interp *interp, Tcl_Obj *arguments); static int NsfObjectExistsCmd(Tcl_Interp *interp, Tcl_Obj *value); @@ -501,7 +499,6 @@ NsfMethodRegisteredCmdIdx, NsfMethodSetterCmdIdx, NsfMyCmdIdx, - NsfNSCopyCmdsCmdIdx, NsfNSCopyVarsCmdIdx, NsfNextCmdIdx, NsfObjectExistsCmdIdx, @@ -1521,26 +1518,6 @@ } static int -NsfNSCopyCmdsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - ParseContext pc; - (void)clientData; - - if (likely(ArgumentParse(interp, objc, objv, NULL, objv[0], - method_definitions[NsfNSCopyCmdsCmdIdx].paramDefs, - method_definitions[NsfNSCopyCmdsCmdIdx].nrParameters, 0, NSF_ARGPARSE_BUILTIN, - &pc) == TCL_OK)) { - Tcl_Obj *fromNs = (Tcl_Obj *)pc.clientData[0]; - Tcl_Obj *toNs = (Tcl_Obj *)pc.clientData[1]; - - assert(pc.status == 0); - return NsfNSCopyCmdsCmd(interp, fromNs, toNs); - - } else { - return TCL_ERROR; - } -} - -static int NsfNSCopyVarsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { ParseContext pc; (void)clientData; @@ -2674,7 +2651,7 @@ } } -static Nsf_methodDefinition method_definitions[106] = { +static Nsf_methodDefinition method_definitions[105] = { {"::nsf::methods::class::alloc", NsfCAllocMethodStub, 1, { {"objectName", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, @@ -2889,10 +2866,6 @@ {"methodName", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"args", 0, 1, ConvertToNothing, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} }, -{"::nsf::nscopycmds", NsfNSCopyCmdsCmdStub, 2, { - {"fromNs", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, - {"toNs", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} -}, {"::nsf::nscopyvars", NsfNSCopyVarsCmdStub, 2, { {"fromNs", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"toNs", NSF_ARG_REQUIRED, 1, Nsf_ConvertToTclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} Index: generic/nsfAPI.nxdocindex =================================================================== diff -u -rfc77eaadabdd690239694a6f1cf155a7d16b5cd4 -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- generic/nsfAPI.nxdocindex (.../nsfAPI.nxdocindex) (revision fc77eaadabdd690239694a6f1cf155a7d16b5cd4) +++ generic/nsfAPI.nxdocindex (.../nsfAPI.nxdocindex) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -32,7 +32,6 @@ set ::nxdoc::include(::nsf::objectsystem::create) 1 set ::nxdoc::include(::nsf::my) 1 set ::nxdoc::include(::nsf::next) 1 -set ::nxdoc::include(::nsf::nscopycmds) 0 set ::nxdoc::include(::nsf::nscopyvars) 0 set ::nxdoc::include(::nsf::proc) 1 set ::nxdoc::include(::nsf::relation) 1 Index: library/nx/nx.tcl =================================================================== diff -u -r496f49d15463c79323454495e356de52137b46bd -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- library/nx/nx.tcl (.../nx.tcl) (revision 496f49d15463c79323454495e356de52137b46bd) +++ library/nx/nx.tcl (.../nx.tcl) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -541,9 +541,6 @@ return $r } - ### TODO needed? - #:alias "object filterguard" ::nsf::methods::object::filterguard - #:alias "object mixinguard" ::nsf::methods::object::mixinguard } # @@ -2303,11 +2300,6 @@ } } - :method copyNSVarsAndCmds {orig dest} { - ::nsf::nscopyvars $orig $dest - #::nsf::nscopycmd $orig $dest - } - # construct destination obj name from old qualified ns name :method getDest {origin} { if {${:dest} eq ""} { @@ -2322,24 +2314,29 @@ #puts stderr "COPY will copy targetList = [set :targetList]" set objs {} array set cmdMap {alias alias forward forward method create setter setter} + foreach origin [set :targetList] { set dest [:getDest $origin] if {[::nsf::object::exists $origin]} { if {$dest eq ""} { set obj [[$origin info class] new -noinit] set dest [set :dest $obj] } else { - if {[::nsf::object::property $origin slotcontainer] && [nsf::is object $dest]} { + # + # Slot container are handled separately, since + # ::nx::slotObj does already the right thing. We have just + # to copy the variables (XOTcl keeps the parameter + # definitions there). + # + if {[::nsf::object::property $origin slotcontainer]} { + ::nx::slotObj -container [namespace tail $origin] \ + [namespace qualifiers $dest] + ::nsf::nscopyvars $origin $dest + continue + } else { # - # We do not want to clean slotcontainer. Assume a target - # list of the form "::C ::C::slot". First ::C is - # created (with e.g. ensemble objects, therefore - # creating itself ::C::slot). If a later creation of - # ::C::slot would clean the slot container it would - # damage ::C. If we would drop ::C::slot from the target - # list, properties and variables would no be copied. + # create an object without calling init # - } else { set obj [[$origin info class] create $dest -noinit] } } @@ -2351,25 +2348,21 @@ ::nsf::method::assertion $obj class-invar [::nsf::method::assertion $origin class-invar] ::nsf::relation $obj class-filter [::nsf::relation $origin class-filter] ::nsf::relation $obj class-mixin [::nsf::relation $origin class-mixin] - :copyNSVarsAndCmds ::nsf::classes$origin ::nsf::classes$dest + ::nsf::nscopyvars ::nsf::classes$origin ::nsf::classes$dest - #puts stderr "XXX === class methods: [lsort [$origin ::nsf::methods::class::info::methods -path -callprotection all]]" foreach m [$origin ::nsf::methods::class::info::methods -path -callprotection all] { - #puts stderr "XXX class [$origin ::nsf::methods::class::info::method definition $m]" set rest [lassign [$origin ::nsf::methods::class::info::method definition $m] . protection what .] - #puts stderr "XXX class m $m rest <$rest>" # remove -returns from reported definitions set p [lsearch -exact $rest -returns]; if {$p > -1} {set rest [lreplace $rest $p $p+1]} array set "" [$obj eval [list :__resolve_method_path $m]] set r [::nsf::method::$cmdMap($what) $(object) $(methodName) {*}$rest] - #puts stderr "XXX class created $r" + ::nsf::method::property $(object) $r returns [$origin ::nsf::methods::class::info::method returns $m] ::nsf::method::property $(object) $r call-protected [::nsf::method::property $origin $m call-protected] ::nsf::method::property $(object) $r call-private [::nsf::method::property $origin $m call-private] } - #puts stderr "XXX === class target: [lsort [$obj ::nsf::methods::class::info::methods -path -callprotection all]]" } # copy object -> might be a class obj @@ -2388,18 +2381,15 @@ namespace eval $dest {} } lappend objs $obj - :copyNSVarsAndCmds $origin $dest + ::nsf::nscopyvars $origin $dest - #puts stderr "XXX ??? object methods: [$origin ::nsf::methods::object::info::methods -path -callprotection all]" foreach m [$origin ::nsf::methods::object::info::methods -path -callprotection all] { set rest [lassign [$origin ::nsf::methods::object::info::method definition $m] . protection . what .] - #puts "XXX $m what $what rest $rest" # remove -returns from reported definitions set p [lsearch -exact $rest -returns]; if {$p > -1} {set rest [lreplace $rest $p $p+1]} array set "" [$obj eval [list :__resolve_method_path -per-object $m]] - #puts "XXX $m create ::nsf::method::$cmdMap($what) $(object) -per-object $(methodName) $rest" set r [::nsf::method::$cmdMap($what) $(object) -per-object $(methodName) {*}$rest] ::nsf::method::property $(object) -per-object $r \ returns \ @@ -2411,18 +2401,8 @@ call-private \ [::nsf::method::property $origin -per-object $m call-private] } - #puts stderr "XXX === object target: [$obj ::nsf::methods::object::info::methods -path -callprotection all]" # - # Check, if $origin is a slot container. If yes, set the slot - # container properties on $dest - # - if {[::nsf::object::property $origin slotcontainer]} { - ::nx::internal::setSlotContainerProperties \ - [$dest ::nsf::methods::object::info::parent] [namespace tail $origin] - } - - # # transfer the traces # foreach var [$origin info vars] { Index: tests/methods.test =================================================================== diff -u -r496f49d15463c79323454495e356de52137b46bd -r6b5a68878186b49871d420ee8e8d5c0f2c073222 --- tests/methods.test (.../methods.test) (revision 496f49d15463c79323454495e356de52137b46bd) +++ tests/methods.test (.../methods.test) (revision 6b5a68878186b49871d420ee8e8d5c0f2c073222) @@ -971,4 +971,78 @@ ? {::d1 a c} "a c" ? {::d1 set x 2} 2 +} + + + +nx::Test parameter count 10 +# +# class copy with class object methods +# +nx::Test case object+class+property-copy { + nsf::method::provide set {::nsf::method::alias set -frame object ::set} + nsf::method::provide exists {::nsf::method::alias exists ::nsf::methods::object::exists} + + package require nx::serializer + + nx::Class create C { + :public method foo {} {return foo} + :public method "a b" {} {return "a b"} + :public method "a c" {} {return "a c"} + :protected method bar {} {return bar} + :private method baz {} {return baz} + :public forward fwd %self xxx + :require public method set + :property p + :variable v 0 + + :public object method ofoo {} {return foo} + :public object method "oa b" {} {return "oa b"} + :public object method "oa c" {} {return "oa c"} + :protected object method obar {} {return bar} + :private object method obaz {} {return baz} + :public object forward ofwd %self xxx + :require public object method exists + :require public object method set + + :object property op + :object variable ov 0 + + :create c1 + } + + ? {lsort [::C info methods -path]} "{a b} {a c} foo fwd set" + ? {lsort [::C info object methods -path]} "exists {oa b} {oa c} ofoo ofwd set" + + ? {::c1 a b} "a b" + ? {::c1 a c} "a c" + ? {::c1 set x 1} 1 + + ? {::C oa b} "oa b" + ? {::C oa c} "oa c" + ? {::C set y 100} "100" + + ::nx::Object public method COPY {target} { + set code [::Serializer deepSerialize -objmap [list [self] $target] [self]] + #puts CODE=$code + eval $code + return $target + } + + #? {::C COPY ::E} ::E + ? {::C copy ::D} ::D + + ? {lsort [::D info methods -path]} "{a b} {a c} foo fwd set" + ? {lsort [::D info object methods -path]} "exists {oa b} {oa c} ofoo ofwd set" + + ? {::D oa b} "oa b" + ? {::D oa c} "oa c" + ? {::D set y} "100" + + ::D create d1 + + ? {::d1 a b} "a b" + ? {::d1 a c} "a c" + + ? {::d1 set x 2} 2 } \ No newline at end of file