From ea976e6b48ee0b6dccf36245acdf306b92cbef72 Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Wed, 26 Apr 2023 14:47:45 +1000 Subject: [PATCH] fix punk::exitcode function arguments and make runx compatible with it --- src/modules/punk-0.1.tm | 3 ++- src/modules/shellrun-0.1.tm | 3 ++- src/punk86.vfs/lib/app-punk/repl.tcl | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/punk-0.1.tm b/src/modules/punk-0.1.tm index f90395c..9ff9a11 100644 --- a/src/modules/punk-0.1.tm +++ b/src/modules/punk-0.1.tm @@ -311,7 +311,8 @@ namespace eval punk { #sh style true/false for process exitcode. 0 is true - everything else false - proc exitcode {c} { + proc exitcode {args} { + set c [lindex $args 0] if {[string is integer -strict $c]} { #return [expr {$c == 0}] #return true/false to make it clearer we are outputting tcl-boolean inverse mapping from the shell style 0=true diff --git a/src/modules/shellrun-0.1.tm b/src/modules/shellrun-0.1.tm index 4db521b..0fe58a7 100644 --- a/src/modules/shellrun-0.1.tm +++ b/src/modules/shellrun-0.1.tm @@ -372,6 +372,7 @@ namespace eval shellrun { if {$nonewline} { return [list stdout [string trimright $::shellrun::runout \r\n] stderr [string trimright $::shellrun::runerr \r\n] {*}$exitinfo] } - return [list stdout $::shellrun::runout stderr $::shellrun::runerr {*}$exitinfo] + #always return exitinfo $code at beginning of dict (so that punk unknown can interpret the exit code as a unix-style bool if double evaluated) + return [list {*}$exitinfo stdout $::shellrun::runout stderr $::shellrun::runerr] } } diff --git a/src/punk86.vfs/lib/app-punk/repl.tcl b/src/punk86.vfs/lib/app-punk/repl.tcl index 8219c80..81c03b1 100644 --- a/src/punk86.vfs/lib/app-punk/repl.tcl +++ b/src/punk86.vfs/lib/app-punk/repl.tcl @@ -420,10 +420,11 @@ know {[regexp {^([0-9]+)\.\.([0-9]+)$} [lindex $args 0] -> from to]} { } #handle process return dict of form {exitcode num etc blah} +#ie when the return result as a whole is treated as a command #exitcode must be the first key know {[lindex $args 0 0] eq "exitcode"} { - set c [lindex $args 0 1] - uplevel 1 [list exitcode $c] + #set c [lindex $args 0 1] + uplevel 1 [list exitcode {*}[lrange [lindex $args 0] 1 end]] }