diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2025-08-22 17:15:48 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2025-08-22 17:15:48 (GMT) |
| commit | ff93032670a4b3e36a90eb3f6725e6dff64d4b6f (patch) | |
| tree | 166842954790f145b855b6c3550a36c64922a9ce /generic/tclOODefineCmds.c | |
| parent | 63e9714b2ebee7046c5a8506b54e836c3f567a86 (diff) | |
| download | tcl-ff93032670a4b3e36a90eb3f6725e6dff64d4b6f.zip tcl-ff93032670a4b3e36a90eb3f6725e6dff64d4b6f.tar.gz tcl-ff93032670a4b3e36a90eb3f6725e6dff64d4b6f.tar.bz2 | |
Accelerate definition of [oo::define initialise]. (backport)
Diffstat (limited to 'generic/tclOODefineCmds.c')
| -rw-r--r-- | generic/tclOODefineCmds.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/generic/tclOODefineCmds.c b/generic/tclOODefineCmds.c index e029649..5b6de0e 100644 --- a/generic/tclOODefineCmds.c +++ b/generic/tclOODefineCmds.c @@ -2032,6 +2032,53 @@ TclOODefineForwardObjCmd( /* * ---------------------------------------------------------------------- * + * TclOODefineInitialiseObjCmd -- + * + * Implementation of the "initialise" subcommand of the "oo::define" + * command. + * + * ---------------------------------------------------------------------- + */ + +int +TclOODefineInitialiseObjCmd( + TCL_UNUSED(void *), + Tcl_Interp *interp, + int objc, + Tcl_Obj *const *objv) +{ + Tcl_Object object; + Tcl_Obj *lambdaWords[3], *applyArgs[2]; + int result; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "body"); + return TCL_ERROR; + } + + // Build the lambda + object = TclOOGetDefineCmdContext(interp); + if (object == NULL) { + return TCL_ERROR; + } + lambdaWords[0] = Tcl_NewObj(); + lambdaWords[1] = objv[1]; + lambdaWords[2] = TclNewNamespaceObj(Tcl_GetObjectNamespace(object)); + + // Delegate to [apply] to run it + applyArgs[0] = Tcl_NewStringObj("apply", -1); + applyArgs[1] = Tcl_NewListObj(3, lambdaWords); + Tcl_IncrRefCount(applyArgs[0]); + Tcl_IncrRefCount(applyArgs[1]); + result = Tcl_ApplyObjCmd(NULL, interp, 2, applyArgs); + Tcl_DecrRefCount(applyArgs[0]); + Tcl_DecrRefCount(applyArgs[1]); + return result; +} + +/* + * ---------------------------------------------------------------------- + * * TclOODefineMethodObjCmd -- * * Implementation of the "method" subcommand of the "oo::define" and |
