-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcAccess.tcl
60 lines (56 loc) · 1.72 KB
/
ProcAccess.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
if { [namespace exists ::ProcAccess] } return
#puts "# [namespace current] / ProcAccess: [info script]"
# Implements public/private keywords for namespaces.
# If a namespaced proc is public, it is exported from the namespace.
# If a namespaced proc is private, it is not exported from the namespace.
# Ensembles will include all public procs as commands.
#
# for example:
#
# namespace eval TEST {
# public proc testPublic { a1 a2 a3 } {
# }
#
# private proc testPrivate { b1 b2 b3 } {
# }
#
# namespace ensemble create
# }
#
# TEST testPublic 1 2 3 ;# okay
# TEST testPrivate 4 5 6 ;# error
#
# Is the same as:
#
# namespace eval TEST {
# proc testPublic { a1 a2 a3 } {
# }
# namespace export testPublic
#
# proc testPrivate { b1 b2 b3 } {
# }
#
# namespace ensemble create
# }
#
# TEST testPublic 1 2 3 ;# okay
# TEST testPrivate 4 5 6 ;# error
#============================================================================
#============================================================================
#============================================================================
namespace eval ::ProcAccess {
proc access__ { access proc name args body } {
if { [set ns [uplevel 1 {namespace current}]] == "::" } {
set ns {}
}
uplevel 1 [list proc $name [list {*}$args] $body]
if { "" != $ns && "public" == $access} {
#puts ">> $access proc ${ns}::$name [list $args] {body}"
#puts ">> namespace export $name"
uplevel 1 [list namespace export $name]
}
}
}
# alias the public/private keywords to the appropriate namespaced proc
interp alias {} public {} ::ProcAccess::access__ public
interp alias {} private {} ::ProcAccess::access__ private