updated hseval behavior

This commit is contained in:
Luxferre
2026-07-04 16:09:50 +03:00
parent 1a44245078
commit 257d40dc8d
3 changed files with 34 additions and 6 deletions
+27 -1
View File
@@ -11,6 +11,8 @@ import (
"math/rand"
"net"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"unicode/utf8"
@@ -474,7 +476,31 @@ func NewClyx(libfname string, libCode string) *Clyx {
}
c.stack = append(c.stack, sb.String())
}
c.words["hseval"] = func() { fmt.Fprintln(os.Stderr, "Error: unsupported word"); os.Exit(1) }
c.words["hseval"] = func() {
cmdStr := c.pop().(string)
var shell, flag string
if runtime.GOOS == "windows" {
shell = "cmd"
flag = "/c"
} else {
shell = "sh"
flag = "-c"
}
cmd := exec.Command(shell, flag, cmdStr)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err := cmd.Run()
var exitCode int64 = 0
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
exitCode = int64(exitError.ExitCode())
} else {
exitCode = -1
}
}
c.stack = append(c.stack, exitCode)
}
c.words["chr"] = func() { c.stack = append(c.stack, string(rune(toInt(c.pop())))) }
regMath := func(name string, f func(float64) float64) {