added consistent _main

This commit is contained in:
Luxferre
2026-07-04 09:23:54 +03:00
parent bee949ccbc
commit ce18aa76b5
4 changed files with 48 additions and 8 deletions
+24 -1
View File
@@ -82,13 +82,36 @@ func detectAndRunZip() bool {
return true
}
func runFiles(files []string) {
defer func() {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", r)
os.Exit(1)
}
}()
c := clyx.NewClyx("", defaultLibCode)
for _, filePath := range files {
content, err := os.ReadFile(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing %s: %v\n", filePath, err)
os.Exit(1)
}
c.Run(string(content))
}
if c.HasWord("_main") {
c.Run("_main")
}
}
func main() {
if detectAndRunZip() {
return
}
if len(os.Args) > 1 {
clyx.RunFile(os.Args[1], defaultLibCode)
runFiles(os.Args[1:])
} else {
defer func() {
if r := recover(); r != nil {