Posted to tcl by stu at Mon Jan 10 13:45:42 GMT 2022view raw
- $ cat nsy.tcl
- namespace eval main {
- namespace eval module_a {
- proc openModule {args} { return open:$args }
- proc closeModule {args} { return close:$args }
- proc module_a {args} {
- namespace path [namespace parent]
- set me [namespace tail [lindex [info level 0] 0]]
- namespace ensemble create -prefixes no -command $me \
- -map [dict create open openModule close closeModule]
- rename $me _$me
- # Module-specific initialization begin
- # put code here
- # Module-specific initialization end
- tailcall $me {*}$args
- }
- namespace export module_a
- }
- namespace import module_a::*
- }
- $ tclsh
- % source nsy.tcl
- % namespace eval main { list [module_a open a b c] [module_a close 1 2 3] [module_a open x y z] }
- {open:a b c} {close:1 2 3} {open:x y z}
- $ tclsh
- % source nsy.tcl
- % list [main::module_a open a b c] [main::module_a close 1 2 3] [main::module_a open x y z]
- {open:a b c} {close:1 2 3} {open:x y z}
- $ tclsh
- % source nsy.tcl
- % main::module_a z
- unknown subcommand "z": must be close, or open