1
0
Fork 0
forked from fun/fun

Intendation fixes in ./scripts/play.fun. No code changes. (0.40.6)

This commit is contained in:
Johannes Findeisen 2026-04-21 03:09:46 +02:00
commit 42d323a4a0

View file

@ -22,33 +22,33 @@
// We try to use existing environment or default to ./lib // We try to use existing environment or default to ./lib
lib_dir = env("FUN_LIB_DIR") lib_dir = env("FUN_LIB_DIR")
if (len(to_string(lib_dir)) == 0) if (len(to_string(lib_dir)) == 0)
lib_dir = "./lib" lib_dir = "./lib"
// Discovery logic for the interpreter // Discovery logic for the interpreter
fun find_interpreter() fun find_interpreter()
bin = env("FUN_BIN") bin = env("FUN_BIN")
if (len(to_string(bin)) > 0) if (len(to_string(bin)) > 0)
return bin return bin
// Check common build locations // Check common build locations
// We use 'system' with 'test -f' as we don't have a direct 'is_file' yet // We use 'system' with 'test -f' as we don't have a direct 'is_file' yet
if (system("test -f ./build/fun") == 0) if (system("test -f ./build/fun") == 0)
return "./build/fun" return "./build/fun"
if (system("test -f ./build_debug/fun") == 0) if (system("test -f ./build_debug/fun") == 0)
return "./build_debug/fun" return "./build_debug/fun"
if (system("test -f ./build_release/fun") == 0) if (system("test -f ./build_release/fun") == 0)
return "./build_release/fun" return "./build_release/fun"
// Check PATH // Check PATH
if (system("command -v fun >/dev/null 2>&1") == 0) if (system("command -v fun >/dev/null 2>&1") == 0)
return "fun" return "fun"
return "" return ""
interpreter = find_interpreter() interpreter = find_interpreter()
if (len(interpreter) == 0) if (len(interpreter) == 0)
print("Error: fun interpreter not found. Please build it or set FUN_BIN.") print("Error: fun interpreter not found. Please build it or set FUN_BIN.")
exit(1) exit(1)
print("Using interpreter: " + interpreter) print("Using interpreter: " + interpreter)
print("Searching for examples in ./examples...") print("Searching for examples in ./examples...")
@ -57,34 +57,34 @@ print("Searching for examples in ./examples...")
// Since we don't have a robust recursive os_list_dir yet, // Since we don't have a robust recursive os_list_dir yet,
// and the original used 'find', we'll use 'find' via system to get the list. // and the original used 'find', we'll use 'find' via system to get the list.
fun get_examples() fun get_examples()
// We use 'find' to get all .fun files and sort them. // We use 'find' to get all .fun files and sort them.
// We redirect to a temporary file as we don't have a 'proc_capture' that returns an array easily // We redirect to a temporary file as we don't have a 'proc_capture' that returns an array easily
// Actually, os_list_dir uses 'ls -1'. We can use a similar approach or just call find. // Actually, os_list_dir uses 'ls -1'. We can use a similar approach or just call find.
cmd = "find examples -name \"*.fun\" | sort > ./tmp/examples_list.txt" cmd = "find examples -name \"*.fun\" | sort > ./tmp/examples_list.txt"
system(cmd) system(cmd)
list_str = read_file("./tmp/examples_list.txt") list_str = read_file("./tmp/examples_list.txt")
// We don't have a built-in 'split' that handles newlines easily in all versions? // We don't have a built-in 'split' that handles newlines easily in all versions?
// Wait, lib/strings.fun might have it. // Wait, lib/strings.fun might have it.
lines = str_split(list_str, "\n") lines = str_split(list_str, "\n")
// Filter out empty lines // Filter out empty lines
examples = [] examples = []
i = 0 i = 0
n = len(lines) n = len(lines)
while (i < n) while (i < n)
line = str_trim(lines[i]) line = str_trim(lines[i])
if (len(line) > 0) if (len(line) > 0)
push(examples, line) push(examples, line)
i = i + 1 i = i + 1
return examples return examples
examples = get_examples() examples = get_examples()
if (len(examples) == 0) if (len(examples) == 0)
print("No examples found in ./examples") print("No examples found in ./examples")
exit(0) exit(0)
failed_examples = [] failed_examples = []
console = Console() console = Console()
@ -92,38 +92,38 @@ console = Console()
i = 0 i = 0
n = len(examples) n = len(examples)
while (i < n) while (i < n)
example = examples[i] example = examples[i]
print("--------------------------------------------------------------------------------") print("--------------------------------------------------------------------------------")
print("Example: " + example) print("Example: " + example)
// ask_yes_no returns 1 for yes, 0 for no // ask_yes_no returns 1 for yes, 0 for no
print("Do you want to run this example? [y/N]") print("Do you want to run this example? [y/N]")
ans = str_to_lower(str_trim(input(""))) ans = str_to_lower(str_trim(input("")))
if (ans == "y" || ans == "yes") if (ans == "y" || ans == "yes")
print("Running: " + interpreter + " " + example) print("Running: " + interpreter + " " + example)
// Prepare command with environment variable // Prepare command with environment variable
// FUN_LIB_DIR must be passed to the child process // FUN_LIB_DIR must be passed to the child process
cmd = "FUN_LIB_DIR=\"" + lib_dir + "\" " + interpreter + " " + example cmd = "FUN_LIB_DIR=\"" + lib_dir + "\" " + interpreter + " " + example
exit_code = system(cmd) exit_code = system(cmd)
print("Exit code: " + to_string(exit_code)) print("Exit code: " + to_string(exit_code))
if (exit_code != 0) if (exit_code != 0)
push(failed_examples, example + " (exit code: " + to_string(exit_code) + ")") push(failed_examples, example + " (exit code: " + to_string(exit_code) + ")")
else else
print("Skipping.") print("Skipping.")
i = i + 1 i = i + 1
print("--------------------------------------------------------------------------------") print("--------------------------------------------------------------------------------")
print("Done.") print("Done.")
if (len(failed_examples) > 0) if (len(failed_examples) > 0)
print("The following examples failed:") print("The following examples failed:")
i = 0 i = 0
while (i < len(failed_examples)) while (i < len(failed_examples))
print(" - " + failed_examples[i]) print(" - " + failed_examples[i])
i = i + 1 i = i + 1
exit(1) exit(1)
exit(0) exit(0)