45 changed files with 22381 additions and 446 deletions
@ -0,0 +1,69 @@
|
||||
set arg1 [lindex $::argv 0] |
||||
|
||||
interp create code1 |
||||
interp create code2 |
||||
|
||||
|
||||
puts stderr "loading Thread package in all 3 interps" |
||||
package require Thread |
||||
code1 eval {package require Thread} |
||||
code2 eval {package require Thread} |
||||
|
||||
puts stderr "establishing ::testfunc proc in all 3 interps" |
||||
code1 eval {proc ::testfunc {args} {puts stderr "evaluated in code1 interp: $args"}} |
||||
code2 eval {proc ::testfunc {args} {puts stderr "evaluated in code2 interp: $args"}} |
||||
proc ::testfunc {args} {puts stderr "evaluated in parent interp: $args"} |
||||
|
||||
|
||||
puts stderr "Calling a thread function in nominated interp '$arg1' first" |
||||
#1st use of thread function makes that interp the one to receive all subsequent messages |
||||
switch -- $arg1 { |
||||
parent { |
||||
thread::id |
||||
} |
||||
code1 { |
||||
code1 eval {thread::id} |
||||
} |
||||
code2 { |
||||
code2 eval {thread::id} |
||||
} |
||||
default { |
||||
puts stderr "Usage thread_interp.tcl parent|code1|code2" |
||||
exit 1 |
||||
} |
||||
} |
||||
|
||||
|
||||
puts stderr "sending scripts" |
||||
thread::send -async [thread::id] { |
||||
::testfunc script sent from parent interp |
||||
} |
||||
code1 eval { |
||||
thread::send -async [thread::id] { |
||||
::testfunc script sent from code1 interp |
||||
} |
||||
} |
||||
code2 eval { |
||||
thread::send -async [thread::id] { |
||||
::testfunc script sent from code2 interp |
||||
} |
||||
} |
||||
#test |
||||
after 0 {::testfunc after script in parent interp} |
||||
code1 eval {after 0 {::testfunc after script in code1 interp}} |
||||
code2 eval {after 0 {::testfunc after script in code2 interp}} |
||||
|
||||
|
||||
code1 eval { |
||||
set workertid [thread::create] |
||||
thread::send $workertid {package require Thread} |
||||
thread::send $workertid [list thread::send -async [thread::id] { |
||||
::testfunc script sent from code1 interp via worker |
||||
}] |
||||
} |
||||
|
||||
after idle {set ::done 1} |
||||
vwait ::done |
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
# Adventure |
||||
[colors] |
||||
foreground = "#feffff" |
||||
background = "#040404" |
||||
cursor_bg = "#feffff" |
||||
cursor_border = "#feffff" |
||||
cursor_fg = "#000000" |
||||
selection_bg = "#606060" |
||||
selection_fg = "#ffffff" |
||||
|
||||
ansi = ["#040404","#d84a33","#5da602","#eebb6e","#417ab3","#e5c499","#bdcfe5","#dbded8"] |
||||
brights = ["#685656","#d76b42","#99b52c","#ffb670","#97d7ef","#aa7900","#bdcfe5","#e4d5c7"] |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
||||
0.1.0 |
||||
#First line must be a semantic version number |
||||
#all other lines are ignored. |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
||||
0.9 |
||||
#First line must be a semantic version number |
||||
#all other lines are ignored. |
@ -0,0 +1,44 @@
|
||||
|
||||
set a b |
||||
set x {a b} |
||||
set x [] |
||||
set x { |
||||
a |
||||
{b c} |
||||
} |
||||
|
||||
|
||||
|
||||
array set comm { |
||||
debug 0 |
||||
chans {} |
||||
localhost 1.2 |
||||
x {} |
||||
y jb |
||||
j aa |
||||
blah "xxxb" |
||||
defaulg 0 |
||||
} |
||||
|
||||
#test |
||||
|
||||
if {"x" eq max(2,3)} { |
||||
} |
||||
if {"x" eq min(1)} {} |
||||
|
||||
set x [dict create {a b c {x} e f }] |
||||
zlib adler32 "abc" |
||||
dict get $x "a" |
||||
#dict create {a b} |
||||
set x [] |
||||
#test |
||||
array set test1 {blah etc} |
||||
array set comm { |
||||
debug 0 chans {} localhost 127.0.0.1 |
||||
offerVers {3 2} |
||||
acceptVers {3 2} |
||||
defaultEncoding "utf-8" |
||||
defaultSilent 0 |
||||
} |
||||
#test |
||||
set x blah |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,3 @@
|
||||
0.1.1 |
||||
#First line must be a semantic version number |
||||
#all other lines are ignored. |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,195 +0,0 @@
|
||||
#JMN - api should be kept in sync with package patternlib where possible |
||||
# |
||||
package provide oolib [namespace eval oolib { |
||||
variable version |
||||
set version 0.1 |
||||
}] |
||||
|
||||
namespace eval oolib { |
||||
oo::class create collection { |
||||
variable o_data ;#dict |
||||
variable o_alias |
||||
constructor {} { |
||||
set o_data [dict create] |
||||
} |
||||
method info {} { |
||||
return [dict info $o_data] |
||||
} |
||||
method count {} { |
||||
return [dict size $o_data] |
||||
} |
||||
method isEmpty {} { |
||||
expr {[dict size $o_data] == 0} |
||||
} |
||||
method names {{globOrIdx {}}} { |
||||
if {[llength $globOrIdx]} { |
||||
if {[string is integer -strict $globOrIdx]} { |
||||
if {$idx < 0} { |
||||
set idx "end-[expr {abs($idx + 1)}]" |
||||
} |
||||
if {[catch {lindex [dict keys $o_data] $idx} result]} { |
||||
error "[self object] no such index : '$idx'" |
||||
} else { |
||||
return $result |
||||
} |
||||
} else { |
||||
#glob |
||||
return [lsearch -glob -all -inline [dict keys $o_data] $globOrIdx] |
||||
} |
||||
} else { |
||||
return [dict keys $o_data] |
||||
} |
||||
} |
||||
#like names but without globbing |
||||
method keys {} { |
||||
dict keys $o_data |
||||
} |
||||
method key {{posn 0}} { |
||||
if {$posn < 0} { |
||||
set posn "end-[expr {abs($posn + 1)}]" |
||||
} |
||||
if {[catch {lindex [dict keys $o_data] $posn} result]} { |
||||
error "[self object] no such index : '$posn'" |
||||
} else { |
||||
return $result |
||||
} |
||||
} |
||||
method hasKey {key} { |
||||
dict exists $o_data $key |
||||
} |
||||
method get {} { |
||||
return $o_data |
||||
} |
||||
method items {} { |
||||
return [dict values $o_data] |
||||
} |
||||
method item {key} { |
||||
if {[string is integer -strict $key]} { |
||||
if {$key > 0} { |
||||
set valposn [expr {(2*$key) +1}] |
||||
return [lindex $o_data $valposn] |
||||
} else { |
||||
set key "end-[expr {abs($key + 1)}]" |
||||
return [lindex [dict keys $o_data] $key] |
||||
} |
||||
} |
||||
if {[dict exists $o_data $key]} { |
||||
return [dict get $o_data $key] |
||||
} |
||||
} |
||||
#inverse lookup |
||||
method itemKeys {value} { |
||||
set value_indices [lsearch -all [dict values $o_data] $value] |
||||
set keylist [list] |
||||
foreach i $value_indices { |
||||
set idx [expr {(($i + 1) *2) -2}] |
||||
lappend keylist [lindex $o_data $idx] |
||||
} |
||||
return $keylist |
||||
} |
||||
method search {value args} { |
||||
set matches [lsearch {*}$args [dict values $o_data] $value] |
||||
if {"-inline" in $args} { |
||||
return $matches |
||||
} else { |
||||
set keylist [list] |
||||
foreach i $matches { |
||||
set idx [expr {(($i + 1) *2) -2}] |
||||
lappend keylist [lindex $o_data $idx] |
||||
} |
||||
return $keylist |
||||
} |
||||
} |
||||
#review - see patternlib. Is the intention for aliases to be configurable independent of whether the target exists? |
||||
method alias {newAlias existingKeyOrAlias} { |
||||
if {[string is integer -strict $newAlias]} { |
||||
error "[self object] collection key alias cannot be integer" |
||||
} |
||||
if {[string length $existingKeyOrAlias]} { |
||||
set o_alias($newAlias) $existingKeyOrAlias |
||||
} else { |
||||
unset o_alias($newAlias) |
||||
} |
||||
} |
||||
method aliases {{key ""}} { |
||||
if {[string length $key]} { |
||||
set result [list] |
||||
foreach {n v} [array get o_alias] { |
||||
if {$v eq $key} { |
||||
lappend result $n $v |
||||
} |
||||
} |
||||
return $result |
||||
} else { |
||||
return [array get o_alias] |
||||
} |
||||
} |
||||
#if the supplied index is an alias, return the underlying key; else return the index supplied. |
||||
method realKey {idx} { |
||||
if {[catch {set o_alias($idx)} key]} { |
||||
return $idx |
||||
} else { |
||||
return $key |
||||
} |
||||
} |
||||
method add {value key} { |
||||
if {[string is integer -strict $key]} { |
||||
error "[self object] collection key must not be an integer. Use another structure if integer keys required" |
||||
} |
||||
if {[dict exists $o_data $key]} { |
||||
error "[self object] col_processors object error: key '$key' already exists in collection" |
||||
} |
||||
dict set o_data $key $value |
||||
return [expr {[dict size $o_data] - 1}] ;#return index of item |
||||
} |
||||
method remove {idx {endRange ""}} { |
||||
if {[string length $endRange]} { |
||||
error "[self object] collection error: ranged removal not yet implemented.. remove one item at a time" |
||||
} |
||||
if {[string is integer -strict $idx]} { |
||||
if {$idx < 0} { |
||||
set idx "end-[expr {abs($idx+1)}]" |
||||
} |
||||
set key [lindex [dict keys $o_data] $idx] |
||||
set posn $idx |
||||
} else { |
||||
set key $idx |
||||
set posn [lsearch -exact [dict keys $o_data] $key] |
||||
if {$posn < 0} { |
||||
error "[self object] no such index: '$idx' in this collection" |
||||
} |
||||
} |
||||
dict unset o_data $key |
||||
return |
||||
} |
||||
method clear {} { |
||||
set o_data [dict create] |
||||
return |
||||
} |
||||
method reverse {} { |
||||
set dictnew [dict create] |
||||
foreach k [lreverse [dict keys $o_data]] { |
||||
dict set dictnew $k [dict get $o_data $k] |
||||
} |
||||
set o_data $dictnew |
||||
return |
||||
} |
||||
#review - cmd as list vs cmd as script? |
||||
method map {cmd} { |
||||
set seed [list] |
||||
dict for {k v} $o_data { |
||||
lappend seed [uplevel #0 [list {*}$cmd $v]] |
||||
} |
||||
return $seed |
||||
} |
||||
method objectmap {cmd} { |
||||
set seed [list] |
||||
dict for {k v} $o_data { |
||||
lappend seed [uplevel #0 [list $v {*}$cmd]] |
||||
} |
||||
return $seed |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,44 @@
|
||||
|
||||
set a b |
||||
set x {a b} |
||||
set x [] |
||||
set x { |
||||
a |
||||
{b c} |
||||
} |
||||
|
||||
|
||||
|
||||
array set comm { |
||||
debug 0 |
||||
chans {} |
||||
localhost 1.2 |
||||
x {} |
||||
y jb |
||||
j aa |
||||
blah "xxxb" |
||||
defaulg 0 |
||||
} |
||||
|
||||
#test |
||||
|
||||
if {"x" eq max(2,3)} { |
||||
} |
||||
if {"x" eq min(1)} {} |
||||
|
||||
set x [dict create {a b c {x} e f }] |
||||
zlib adler32 "abc" |
||||
dict get $x "a" |
||||
#dict create {a b} |
||||
set x [] |
||||
#test |
||||
array set test1 {blah etc} |
||||
array set comm { |
||||
debug 0 chans {} localhost 127.0.0.1 |
||||
offerVers {3 2} |
||||
acceptVers {3 2} |
||||
defaultEncoding "utf-8" |
||||
defaultSilent 0 |
||||
} |
||||
#test |
||||
set x blah |
Loading…
Reference in new issue