From 63545ed9182e6429d7a0ed09fd5d782fed336e0d Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 15 Apr 2026 01:25:17 +0200 Subject: [PATCH] Documentation refactoring. No code changes. (0.40.5) --- lib/ui/tk.fun | 60 ----- web/documentation/{ => arrays}/arrays.md | 46 ++-- web/documentation/{ => asyncio}/asyncio.md | 8 +- web/documentation/{ => build}/build.md | 6 +- .../{ => bytecode-format}/bytecode-format.md | 2 +- web/documentation/{ => cli}/cli.md | 24 +- .../{ => contributing}/contributing.md | 12 +- web/documentation/documentation.md | 77 +++--- .../{ => embedding}/embedding.md | 10 +- .../errors-and-diagnostics.md | 2 +- web/documentation/examples/README.md | 246 ------------------ .../examples/builtins_extended.md | 28 -- .../examples/builtins_maps_and_more.md | 27 -- web/documentation/examples/byte_for_demo.md | 24 -- .../examples/byte_overflow_try_catch.md | 24 -- web/documentation/examples/cast_demo.md | 24 -- .../examples/class_constructor.md | 24 -- web/documentation/examples/class_test.md | 27 -- .../examples/class_without_object.md | 24 -- web/documentation/examples/classes_demo.md | 24 -- web/documentation/examples/cli_argv_dump.md | 24 -- .../examples/conversions_showcase.md | 24 -- web/documentation/examples/cpp_add.md | 27 -- .../examples/data/htdocs/counter.md | 33 --- .../examples/data/htdocs/form_post.md | 33 --- .../examples/data/htdocs/hello.md | 33 --- .../examples/data/htdocs/info.md | 33 --- .../examples/data/htdocs/json_like_api.md | 33 --- .../examples/data/htdocs/redirect.md | 33 --- web/documentation/examples/datetime_basic.md | 24 -- .../examples/datetime_extended.md | 24 -- web/documentation/examples/datetime_timer.md | 24 -- web/documentation/examples/echo_example.md | 24 -- web/documentation/examples/env_all.md | 24 -- web/documentation/examples/error_handling.md | 24 -- web/documentation/{ => examples}/examples.md | 2 +- .../examples/expressions_test.md | 24 -- web/documentation/examples/features.md | 24 -- .../file_print_for_file_line_by_line.md | 24 -- web/documentation/examples/floats.md | 24 -- web/documentation/examples/for_range_test.md | 24 -- web/documentation/examples/functions_test.md | 24 -- web/documentation/examples/have_fun.md | 24 -- .../examples/have_fun_function.md | 24 -- web/documentation/examples/hex_example.md | 24 -- web/documentation/examples/if_else_test.md | 24 -- web/documentation/examples/include_lib.md | 24 -- web/documentation/examples/include_local.md | 24 -- .../examples/include_local_util.md | 24 -- .../examples/inheritance_demo.md | 24 -- .../examples/loops_break_continue.md | 24 -- web/documentation/examples/maps.md | 31 --- web/documentation/examples/match.md | 24 -- web/documentation/examples/namespaced_mod.md | 24 -- web/documentation/examples/nested_loops.md | 24 -- .../examples/net/http_mt_server.md | 36 --- .../examples/net/http_mt_server_cgi.md | 38 --- web/documentation/examples/net/http_server.md | 40 --- .../examples/net/http_server_cgi.md | 38 --- .../examples/net/http_server_cgi_lib.md | 38 --- .../examples/net/http_static_server.md | 36 --- web/documentation/examples/net/httpserver.md | 155 ----------- web/documentation/examples/objects_basic.md | 24 -- web/documentation/examples/objects_more.md | 24 -- web/documentation/examples/os_env.md | 24 -- web/documentation/examples/process_example.md | 24 -- web/documentation/examples/progress.md | 24 -- web/documentation/examples/progress_inline.md | 24 -- web/documentation/examples/random_demo.md | 24 -- .../examples/random_number_example.md | 24 -- web/documentation/examples/regex_demo.md | 27 -- .../examples/regex_procedural.md | 27 -- web/documentation/examples/rust_hello.md | 27 -- web/documentation/examples/rust_hello_args.md | 27 -- .../examples/rust_hello_args_return.md | 27 -- web/documentation/examples/serial_demo.md | 27 -- .../examples/short_circuit_test.md | 24 -- web/documentation/examples/signed_ints.md | 24 -- web/documentation/examples/stdlib_showcase.md | 24 -- web/documentation/examples/strings_test.md | 24 -- web/documentation/examples/tcp_http_get.md | 27 -- .../examples/tcp_http_get_class.md | 27 -- web/documentation/examples/test_bits.md | 24 -- web/documentation/examples/test_dec_to_hex.md | 24 -- web/documentation/examples/test_hex_to_dec.md | 24 -- web/documentation/examples/test_include.md | 24 -- web/documentation/examples/test_rol.md | 24 -- web/documentation/examples/test_serial.md | 27 -- web/documentation/examples/test_shl.md | 24 -- web/documentation/examples/test_types.md | 24 -- web/documentation/examples/test_xor.md | 24 -- .../examples/thread_class_example.md | 24 -- web/documentation/examples/threads_demo.md | 24 -- .../examples/try_catch_finally.md | 24 -- web/documentation/examples/type_safety.md | 24 -- .../examples/type_safety_fails.md | 24 -- web/documentation/examples/typeof.md | 24 -- web/documentation/examples/typeof_features.md | 24 -- web/documentation/examples/types_integers.md | 24 -- web/documentation/examples/types_overview.md | 24 -- web/documentation/examples/uint_types.md | 24 -- .../examples/unix_socket_echo.md | 27 -- web/documentation/examples/version.md | 24 -- web/documentation/examples/while_test.md | 24 -- web/documentation/external/{ => curl}/curl.md | 3 +- .../external/{ => external}/external.md | 2 +- web/documentation/external/{ => ini}/ini.md | 2 +- web/documentation/external/{ => json}/json.md | 2 +- .../external/{ => openssl}/openssl.md | 2 +- .../external/{ => pcre2}/pcre2.md | 2 +- web/documentation/external/{ => pcsc}/pcsc.md | 2 +- .../external/{ => sqlite}/sqlite.md | 2 +- web/documentation/external/{ => xml2}/xml2.md | 2 +- web/documentation/{ => faq}/faq.md | 10 +- web/documentation/{ => fun}/fun.md | 39 +-- web/documentation/{ => funstx}/funstx.md | 19 +- web/documentation/{ => handbook}/handbook.md | 1 - web/documentation/{ => includes}/includes.md | 14 +- .../{ => internals}/internals.md | 41 ++- web/documentation/{ => maps}/maps.md | 46 ++-- web/documentation/{ => numbers}/numbers.md | 55 ++-- web/documentation/{ => opcodes}/opcodes.md | 1 - .../{ => performance}/performance.md | 5 +- web/documentation/{ => repl}/repl.md | 36 +-- web/documentation/{ => roadmap}/roadmap.md | 12 +- web/documentation/{ => rust}/rust.md | 45 ++-- .../security-and-sandboxing.md | 4 +- web/documentation/{ => stdlib}/stdlib.md | 34 ++- web/documentation/{ => strings}/strings.md | 36 +-- .../{ => style-guide}/style-guide.md | 1 - web/documentation/{ => testing}/testing.md | 17 +- .../{ => troubleshooting}/troubleshooting.md | 19 +- web/documentation/{ => types}/types.md | 35 +-- web/documentation/{ => vm}/vm.md | 14 +- web/documentation/{ => website}/website.md | 9 +- .../{ => writing-tests}/writing-tests.md | 5 +- 136 files changed, 374 insertions(+), 3163 deletions(-) delete mode 100644 lib/ui/tk.fun rename web/documentation/{ => arrays}/arrays.md (88%) rename web/documentation/{ => asyncio}/asyncio.md (96%) rename web/documentation/{ => build}/build.md (96%) rename web/documentation/{ => bytecode-format}/bytecode-format.md (97%) rename web/documentation/{ => cli}/cli.md (82%) rename web/documentation/{ => contributing}/contributing.md (83%) rename web/documentation/{ => embedding}/embedding.md (69%) rename web/documentation/{ => errors-and-diagnostics}/errors-and-diagnostics.md (96%) delete mode 100644 web/documentation/examples/README.md delete mode 100644 web/documentation/examples/builtins_extended.md delete mode 100644 web/documentation/examples/builtins_maps_and_more.md delete mode 100644 web/documentation/examples/byte_for_demo.md delete mode 100644 web/documentation/examples/byte_overflow_try_catch.md delete mode 100644 web/documentation/examples/cast_demo.md delete mode 100644 web/documentation/examples/class_constructor.md delete mode 100644 web/documentation/examples/class_test.md delete mode 100644 web/documentation/examples/class_without_object.md delete mode 100644 web/documentation/examples/classes_demo.md delete mode 100644 web/documentation/examples/cli_argv_dump.md delete mode 100644 web/documentation/examples/conversions_showcase.md delete mode 100644 web/documentation/examples/cpp_add.md delete mode 100644 web/documentation/examples/data/htdocs/counter.md delete mode 100644 web/documentation/examples/data/htdocs/form_post.md delete mode 100644 web/documentation/examples/data/htdocs/hello.md delete mode 100644 web/documentation/examples/data/htdocs/info.md delete mode 100644 web/documentation/examples/data/htdocs/json_like_api.md delete mode 100644 web/documentation/examples/data/htdocs/redirect.md delete mode 100644 web/documentation/examples/datetime_basic.md delete mode 100644 web/documentation/examples/datetime_extended.md delete mode 100644 web/documentation/examples/datetime_timer.md delete mode 100644 web/documentation/examples/echo_example.md delete mode 100644 web/documentation/examples/env_all.md delete mode 100644 web/documentation/examples/error_handling.md rename web/documentation/{ => examples}/examples.md (95%) delete mode 100644 web/documentation/examples/expressions_test.md delete mode 100644 web/documentation/examples/features.md delete mode 100644 web/documentation/examples/file_print_for_file_line_by_line.md delete mode 100644 web/documentation/examples/floats.md delete mode 100644 web/documentation/examples/for_range_test.md delete mode 100644 web/documentation/examples/functions_test.md delete mode 100644 web/documentation/examples/have_fun.md delete mode 100644 web/documentation/examples/have_fun_function.md delete mode 100644 web/documentation/examples/hex_example.md delete mode 100644 web/documentation/examples/if_else_test.md delete mode 100644 web/documentation/examples/include_lib.md delete mode 100644 web/documentation/examples/include_local.md delete mode 100644 web/documentation/examples/include_local_util.md delete mode 100644 web/documentation/examples/inheritance_demo.md delete mode 100644 web/documentation/examples/loops_break_continue.md delete mode 100644 web/documentation/examples/maps.md delete mode 100644 web/documentation/examples/match.md delete mode 100644 web/documentation/examples/namespaced_mod.md delete mode 100644 web/documentation/examples/nested_loops.md delete mode 100644 web/documentation/examples/net/http_mt_server.md delete mode 100644 web/documentation/examples/net/http_mt_server_cgi.md delete mode 100644 web/documentation/examples/net/http_server.md delete mode 100644 web/documentation/examples/net/http_server_cgi.md delete mode 100644 web/documentation/examples/net/http_server_cgi_lib.md delete mode 100644 web/documentation/examples/net/http_static_server.md delete mode 100644 web/documentation/examples/net/httpserver.md delete mode 100644 web/documentation/examples/objects_basic.md delete mode 100644 web/documentation/examples/objects_more.md delete mode 100644 web/documentation/examples/os_env.md delete mode 100644 web/documentation/examples/process_example.md delete mode 100644 web/documentation/examples/progress.md delete mode 100644 web/documentation/examples/progress_inline.md delete mode 100644 web/documentation/examples/random_demo.md delete mode 100644 web/documentation/examples/random_number_example.md delete mode 100644 web/documentation/examples/regex_demo.md delete mode 100644 web/documentation/examples/regex_procedural.md delete mode 100644 web/documentation/examples/rust_hello.md delete mode 100644 web/documentation/examples/rust_hello_args.md delete mode 100644 web/documentation/examples/rust_hello_args_return.md delete mode 100644 web/documentation/examples/serial_demo.md delete mode 100644 web/documentation/examples/short_circuit_test.md delete mode 100644 web/documentation/examples/signed_ints.md delete mode 100644 web/documentation/examples/stdlib_showcase.md delete mode 100644 web/documentation/examples/strings_test.md delete mode 100644 web/documentation/examples/tcp_http_get.md delete mode 100644 web/documentation/examples/tcp_http_get_class.md delete mode 100644 web/documentation/examples/test_bits.md delete mode 100644 web/documentation/examples/test_dec_to_hex.md delete mode 100644 web/documentation/examples/test_hex_to_dec.md delete mode 100644 web/documentation/examples/test_include.md delete mode 100644 web/documentation/examples/test_rol.md delete mode 100644 web/documentation/examples/test_serial.md delete mode 100644 web/documentation/examples/test_shl.md delete mode 100644 web/documentation/examples/test_types.md delete mode 100644 web/documentation/examples/test_xor.md delete mode 100644 web/documentation/examples/thread_class_example.md delete mode 100644 web/documentation/examples/threads_demo.md delete mode 100644 web/documentation/examples/try_catch_finally.md delete mode 100644 web/documentation/examples/type_safety.md delete mode 100644 web/documentation/examples/type_safety_fails.md delete mode 100644 web/documentation/examples/typeof.md delete mode 100644 web/documentation/examples/typeof_features.md delete mode 100644 web/documentation/examples/types_integers.md delete mode 100644 web/documentation/examples/types_overview.md delete mode 100644 web/documentation/examples/uint_types.md delete mode 100644 web/documentation/examples/unix_socket_echo.md delete mode 100644 web/documentation/examples/version.md delete mode 100644 web/documentation/examples/while_test.md rename web/documentation/external/{ => curl}/curl.md (91%) rename web/documentation/external/{ => external}/external.md (100%) rename web/documentation/external/{ => ini}/ini.md (91%) rename web/documentation/external/{ => json}/json.md (89%) rename web/documentation/external/{ => openssl}/openssl.md (96%) rename web/documentation/external/{ => pcre2}/pcre2.md (92%) rename web/documentation/external/{ => pcsc}/pcsc.md (92%) rename web/documentation/external/{ => sqlite}/sqlite.md (90%) rename web/documentation/external/{ => xml2}/xml2.md (92%) rename web/documentation/{ => faq}/faq.md (74%) rename web/documentation/{ => fun}/fun.md (80%) rename web/documentation/{ => funstx}/funstx.md (97%) rename web/documentation/{ => handbook}/handbook.md (99%) rename web/documentation/{ => includes}/includes.md (98%) rename web/documentation/{ => internals}/internals.md (99%) rename web/documentation/{ => maps}/maps.md (90%) rename web/documentation/{ => numbers}/numbers.md (87%) rename web/documentation/{ => opcodes}/opcodes.md (99%) rename web/documentation/{ => performance}/performance.md (99%) rename web/documentation/{ => repl}/repl.md (93%) rename web/documentation/{ => roadmap}/roadmap.md (58%) rename web/documentation/{ => rust}/rust.md (84%) rename web/documentation/{ => security-and-sandboxing}/security-and-sandboxing.md (99%) rename web/documentation/{ => stdlib}/stdlib.md (59%) rename web/documentation/{ => strings}/strings.md (87%) rename web/documentation/{ => style-guide}/style-guide.md (99%) rename web/documentation/{ => testing}/testing.md (94%) rename web/documentation/{ => troubleshooting}/troubleshooting.md (93%) rename web/documentation/{ => types}/types.md (89%) rename web/documentation/{ => vm}/vm.md (93%) rename web/documentation/{ => website}/website.md (93%) rename web/documentation/{ => writing-tests}/writing-tests.md (99%) diff --git a/lib/ui/tk.fun b/lib/ui/tk.fun deleted file mode 100644 index ca062b5..0000000 --- a/lib/ui/tk.fun +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env fun - -/* - * This file is part of the Fun programming language. - * https://fun-lang.xyz/ - * - * Copyright 2025 Johannes Findeisen - * Licensed under the terms of the Apache-2.0 license. - * https://opensource.org/license/apache-2-0 - * - * Added: 2025-12-09 - */ - -// Tk stdlib helper wrapping the Tk VM builtins. -// No raw Tcl is exposed; this class provides a tiny, safe GUI surface. - -class TK() - // Set the window title - fun title(this, title) - return tk_title(to_string(title)) - - // Create or update a label widget with id and text - fun label(this, id, text) - return tk_label(to_string(id), to_string(text)) - - // Create or update a button widget with id and text - fun button(this, id, text) - return tk_button(to_string(id), to_string(text)) - - // Pack a widget by id - fun pack(this, id) - return tk_pack(to_string(id)) - - // Create a listbox widget - fun listbox(this, id) - return tk_eval("listbox ." + to_string(id)) - - // Insert text into a widget (like listbox) at index - fun insert(this, id, index, text) - return tk_eval("." + to_string(id) + " insert " + to_string(index) + " {" + to_string(text) + "}") - - // Clear a widget (like listbox) - fun clear(this, id) - return tk_eval("." + to_string(id) + " delete 0 end") - - // Bind an event to a command - fun bind(this, id, event, cmd) - return tk_bind(to_string(id), to_string(event), to_string(cmd)) - - // Evaluate raw Tcl script - fun eval(this, script) - return tk_eval(to_string(script)) - - // Get last Tcl result - fun result(this) - return tk_result() - - // Enter the Tk event loop (blocks until windows are closed) - fun loop(this) - return tk_loop() diff --git a/web/documentation/arrays.md b/web/documentation/arrays/arrays.md similarity index 88% rename from web/documentation/arrays.md rename to web/documentation/arrays/arrays.md index c1b54f7..2342dd3 100644 --- a/web/documentation/arrays.md +++ b/web/documentation/arrays/arrays.md @@ -20,7 +20,6 @@ tags: - slicing --- - This guide focuses on arrays: creation, indexing, mutation, iteration, slicing, and common gotchas. It complements the quick overview in types.md with a deeper, example‑driven treatment. ## What is an array? @@ -40,8 +39,7 @@ empty = [] grid = [[1,2], [3,4]] print(typeof(a)) // "array" -print(len(a)) // 3 - +print(len(a)) // 3 Tip: Prefer square‑bracket literals for clarity and performance versus building via repeated push in a hot loop. @@ -53,9 +51,10 @@ print(a[2]) // 30 // update in place a[1] = 42 -print(a) // [10, 42, 30] - +print(a) // [10, 42, 30] + Notes: + - Valid indices are 0..len(a)-1. Using an invalid index raises a runtime error. - Assignment updates the existing array; references pointing to it observe the change. @@ -74,8 +73,8 @@ a = [1, 2, 3] insert(a, 1, 99) // a => [1, 99, 2, 3] // remove at index (shifts left) -remove(a, 2) // a => [1, 99, 3] - +remove(a, 2) // a => [1, 99, 3] + ## Slicing and concatenation
a = [0,1,2,3,4]
@@ -86,8 +85,8 @@ mid  = slice(a, 1, 4)   // [1,2,3]
 
 // concat: join two arrays
 b = ["x", "y"]
-ab = concat(a, b)       // [0,1,2,3,4,"x","y"]
-
+ab = concat(a, b) // [0,1,2,3,4,"x","y"] + Slicing returns a new array. The original is unchanged. ## Iteration patterns @@ -105,8 +104,8 @@ for pair in it.enumerate(a) { idx = pair[0] val = pair[1] print(to_string(idx) + ":" + val) -} - +} + ## Copying vs. referencing Arrays are reference types. Assigning just copies the reference, not the contents: @@ -120,15 +119,15 @@ print(orig) // [9, 2] copy = slice(orig, 0, len(orig)) copy[1] = 7 print(orig) // [9, 2] -print(copy) // [9, 7] - +print(copy) // [9, 7] + Shallow copies duplicate the top‑level array but not nested structures. ## Equality
print([1,2] == [1,2])   // true
-print([1,2] == [2,1])   // false
-
+print([1,2] == [2,1]) // false + Array equality compares length and element‑wise equality recursively. ## Common utilities @@ -148,9 +147,10 @@ Check your lib directory (e.g., lib/utils) for additional helpers. ## Error handling and bounds
a = [0]
-// a[1] is out of range → runtime error
-
+// a[1] is out of range → runtime error + Tips: + - Guard indices: if i < 0 or i >= len(a) { /* handle */ } - Use remove/insert carefully inside loops; indices of following items change. @@ -163,8 +163,8 @@ print(users[1]["name"]) // Lin // split/join patterns depend on your stdlib #include as su // adjust if present in your tree parts = su.split("a,b,c", ",") // ["a","b","c"] -csv = su.join(parts, ",") // "a,b,c" - +csv = su.join(parts, ",") // "a,b,c" + ## Performance tips - Preallocate by building from literals or chunked appends rather than one‑by‑one in very tight loops. @@ -191,9 +191,9 @@ for i = 0; i < len(nested); i = i + 1 { push(flat, row[j]) } } -print(flat) // [1,2,3,4,5] - +print(flat) // [1,2,3,4,5] + ## See also -- types.md — broader overview of core types with quick array examples. -- examples/ — many scripts operate on arrays; try play.fun to explore. +- [../types/](../types/) — broader overview of core types with quick array examples. +- [../examples/](../examples/) — many scripts operate on arrays; try play.fun to explore. diff --git a/web/documentation/asyncio.md b/web/documentation/asyncio/asyncio.md similarity index 96% rename from web/documentation/asyncio.md rename to web/documentation/asyncio/asyncio.md index 6dcfc06..64b5385 100644 --- a/web/documentation/asyncio.md +++ b/web/documentation/asyncio/asyncio.md @@ -214,7 +214,7 @@ A: You can prototype small non-blocking fragments in the REPL, but full networki ## See also -- [examples.md](./examples/) — Running bundled examples -- [includes.md](./includes/) — Include paths and library discovery -- [opcodes.md](./opcodes/) — VM opcodes overview -- [troubleshooting.md](./troubleshooting/) — Common issues and quick fixes +- [../examples/](../examples/) — Running bundled examples +- [../includes/](../includes/) — Include paths and library discovery +- [../opcodes/](../opcodes/) — VM opcodes overview +- [../troubleshooting/](../troubleshooting/) — Common issues and quick fixes diff --git a/web/documentation/build.md b/web/documentation/build/build.md similarity index 96% rename from web/documentation/build.md rename to web/documentation/build/build.md index 5b7e0e3..6c7bb5a 100644 --- a/web/documentation/build.md +++ b/web/documentation/build/build.md @@ -61,6 +61,8 @@ These are defined as `CACHE` variables, so they will persist in your `CMakeCache When configuring, the build prints a summary like: +See [../vm/](../vm/) for more information. +
==== Fun build options ====
   FUN_DEBUG: ENABLED|DISABLED
   FUN_USE_MUSL: ENABLED|DISABLED
@@ -97,7 +99,7 @@ If `FUN_WITH_OPENSSL` is enabled, CMake must detect your system OpenSSL (libcryp
 
 ## Running
 - CLI: run the `fun` executable from your build directory.
-- REPL: `fun -i` or just run `fun` without a script, depending on your CLI version (see [cli.md](./cli/)).
-- Examples: see [examples.md](./examples/).
+- REPL: `fun -i` or just run `fun` without a script, depending on your CLI version (see [../cli/](../cli/)).
+- Examples: see [../examples/](../examples/).
 
 Tip: When running from the repository without installation, set `FUN_LIB_DIR` to the local `./lib` so includes can find the stdlib.
diff --git a/web/documentation/bytecode-format.md b/web/documentation/bytecode-format/bytecode-format.md
similarity index 97%
rename from web/documentation/bytecode-format.md
rename to web/documentation/bytecode-format/bytecode-format.md
index 1011692..b28dcff 100644
--- a/web/documentation/bytecode-format.md
+++ b/web/documentation/bytecode-format/bytecode-format.md
@@ -20,7 +20,7 @@ tags:
 ---
 
 
-This document summarizes the Fun bytecode format. For deep VM details, see [internals.md](./internals/).
+This document summarizes the Fun bytecode format. For deep VM details, see [internals](./internals/).
 
 ## Goals
 - Compact representation for fast loading and dispatch
diff --git a/web/documentation/cli.md b/web/documentation/cli/cli.md
similarity index 82%
rename from web/documentation/cli.md
rename to web/documentation/cli/cli.md
index 8b8fcb8..ac63ec4 100644
--- a/web/documentation/cli.md
+++ b/web/documentation/cli/cli.md
@@ -23,17 +23,18 @@ tags:
 - synopsis
 ---
 
-
 Reference for the `fun` command-line interface.
 
-For a complete usage guide (including REPL details, environment variables, include paths, examples, and install locations), see [fun.md](./fun/).
+For a complete usage guide (including REPL details, environment variables, include paths, examples, and install locations), see [fun](./fun/).
 
 ## Synopsis
-
fun [options]  [-- args...]
-
-If no script is supplied and interactive mode is available, `fun` starts a REPL (see [repl.md](./repl/)). + +
fun [options] [script.fun] [-- args...]
+ +If no script is supplied and interactive mode is available, `fun` starts a REPL (see [../repl/](../repl/)). ## Common options + - `-i`, `--repl` - start an interactive REPL - `-v`, `--version` - print version and exit - `-h`, `--help` - show help and exit @@ -41,19 +42,22 @@ If no script is supplied and interactive mode is available, `fun` starts a REPL Options may vary between versions; run `fun --help` to see what your build supports. ## Exit codes + - `0` - success - non-zero - error during parse, compile, or runtime ## Includes and library paths + - `FUN_LIB_DIR` - environment variable that points to the stdlib location; when running from the repo, set this to `./lib`. - `DEFAULT_LIB_DIR` - compiled-in fallback path determined at build/install time. -See also: [includes.md](./includes/) for namespaced includes and search order. +See also: [../includes/](../includes/) for namespaced includes and search order. ## Examples + Run a script: -
FUN_LIB_DIR=./lib ./build/fun examples/hello.fun
-
+
FUN_LIB_DIR=./lib ./build/fun examples/hello.fun
+ Start the REPL: -
./build/fun -i
-
\ No newline at end of file + +
./build/fun -i
diff --git a/web/documentation/contributing.md b/web/documentation/contributing/contributing.md similarity index 83% rename from web/documentation/contributing.md rename to web/documentation/contributing/contributing.md index 957f988..caa638f 100644 --- a/web/documentation/contributing.md +++ b/web/documentation/contributing/contributing.md @@ -25,9 +25,9 @@ tags: Thanks for your interest in contributing! This guide covers the basics to get you productive quickly. ## Getting started -- Clone the repo and build (see [build/](../build/)). -- Run tests locally (see [testing/](../testing/)). -- Explore examples (see [examples/](../examples/)). +- Clone the repo and build (see [../build/](../build/)). +- Run tests locally (see [../testing/](../testing/)). +- Explore examples (see [../examples/](../examples/)). ## Project structure - `src/` - C core, VM, and opcode implementations ([https://git.xw3.org/fun/fun/src/branch/main/src/](https://git.xw3.org/fun/fun/src/branch/main/src/){:class="git"}). @@ -42,11 +42,11 @@ Thanks for your interest in contributing! This guide covers the basics to get yo ## Code style - C: C99, two-space indent, no tabs. Keep functions short and focused. - Fun: two-space indent, snake_case for functions, PascalCase for classes/constructors. -- Prefer clear names over abbreviations. See [style-guide/](../style-guide/). +- Prefer clear names over abbreviations. See [../style-guide/](../style-guide/). ## Development workflow 1. Create a small, focused branch. -2. Add/adjust tests for behavior changes (see [writing-tests](../writing-tests/)). +2. Add/adjust tests for behavior changes (see [../writing-tests](../writing-tests/)). 3. Update docs if user-visible behavior changes. 4. Submit a PR with a clear description and rationale. @@ -62,4 +62,4 @@ Please include: - `fun --version` output ## Code of Conduct -Be respectful and inclusive. See [https://git.xw3.org/fun/fun/src/branch/main/CODE_OF_CONDUCT.md](https://git.xw3.org/fun/fun/src/branch/main/CODE_OF_CONDUCT.md){:class="git"} in the repository root. +Be respectful and inclusive. See [https://git.xw3.org/fun/fun/src/branch/main/CODE_OF_CONDUCT.md](https://git.xw3.org/fun/fun/src/branch/main/CODE_OF_CONDUCT/){:class="git"} in the repository root. diff --git a/web/documentation/documentation.md b/web/documentation/documentation.md index 3c73cac..d7638e7 100644 --- a/web/documentation/documentation.md +++ b/web/documentation/documentation.md @@ -15,17 +15,16 @@ tags: - programming --- - This file serves as an index of the documents in this directory. Links are relative and can be opened directly on Git hosting or locally. ## Basics -- [handbook/](./handbook/) - Comprehensive handbook for the Fun language and VM: install/build, configuration flags, usage, and full feature overview. -- [Fun REPL Guide](./repl/) - REPL guide: how to build/launch, editing and history, completions, REPL-on-error, and tips. -- [Specification v0.4](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.4.md){:class="git"} -- [Specification v0.3](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.3.md){:class="git"} -- [Specification v0.2](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.2.md){:class="git"} -- [Specification v0.1](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.1.md){:class="git"} +- [./handbook/](./handbook/) - Comprehensive handbook for the Fun language and VM: install/build, configuration flags, usage, and full feature overview. +- [./repl/](./repl/) - REPL user guide: how to build/launch, editing and history, completions, REPL-on-error, and tips. +- [Specification v0.4](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.4/){:class="git"} +- [Specification v0.3](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.3/){:class="git"} +- [Specification v0.2](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.2/){:class="git"} +- [Specification v0.1](https://git.xw3.org/fun/fun/src/branch/main/spec/v0.1/){:class="git"} - [Examples](https://git.xw3.org/fun/fun/src/branch/main/examples){:class="git"} - [Standard Library](https://git.xw3.org/fun/fun/src/branch/main/lib){:class="git"} @@ -33,43 +32,43 @@ The examples directory contains demonstrations of most Fun features, from basic ## Overview -- [types/](./types/) - Core types (numbers, strings, arrays, maps, nil/bool), common operations, patterns, and interop notes. -- [numbers/](./numbers/) - Working with integers and floats: arithmetic, conversions, clamping, bitwise ops, and patterns. -- [strings/](./strings/) - Working with strings: literals/escaping, concatenation, substr/find, split, and conversions. -- [arrays/](./arrays/) - Working with arrays: creation, indexing/slicing, iteration patterns, helpers, and idioms. -- [maps/](./maps/) - Working with maps: construction, lookup/update, merging, iteration, and common patterns. -- [includes/](./includes/) - Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`. -- [opcodes/](./opcodes/) - VM opcodes overview grouped by domain with brief behavior/stack notes. -- [internals/](./internals/) - Implementation details: bytecode format, VM architecture, stacks/frames, parser, and dispatch. -- [vm/](./vm/) - VM configuration constants: maximum stack depth, local/global variable limits, and output buffer size. -- [rust/](./rust/) - Writing Rust-backed opcodes and wiring them into the C VM; build/setup notes. -- [examples/](./examples/) - How to run the examples and the interactive showcase script, with environment tips. -- [testing/](./testing/) - How to build and run tests/targets with CMake/CTest, and where to add new tests. -- [troubleshooting/](./troubleshooting/) - Common issues and quick fixes for build, includes, and REPL usage. +- [./types/](./types/) - Core types (numbers, strings, arrays, maps, nil/bool), common operations, patterns, and interop notes. +- [./numbers/](./numbers/) - Working with integers and floats: arithmetic, conversions, clamping, bitwise ops, and patterns. +- [./strings/](./strings/) - Working with strings: literals/escaping, concatenation, substr/find, split, and conversions. +- [./arrays/](./arrays/) - Working with arrays: creation, indexing/slicing, iteration patterns, helpers, and idioms. +- [./maps/](./maps/) - Working with maps: construction, lookup/update, merging, iteration, and common patterns. +- [./includes/](./includes/) - Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`. +- [./opcodes/](./opcodes/) - VM opcodes overview grouped by domain with brief behavior/stack notes. +- [./internals/](./internals/) - Implementation details: bytecode format, VM architecture, stacks/frames, parser, and dispatch. +- [./vm/](./vm/) - VM configuration constants: maximum stack depth, local/global variable limits, and output buffer size. +- [./rust/](./rust/) - Writing Rust-backed opcodes and wiring them into the C VM; build/setup notes. +- [./examples/](./examples/) - How to run the examples and the interactive showcase script, with environment tips. +- [./testing/](./testing/) - How to build and run tests/targets with CMake/CTest, and where to add new tests. +- [./troubleshooting/](./troubleshooting/) - Common issues and quick fixes for build, includes, and REPL usage. ## New and supplemental guides -- [build/](./build/) - How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL). -- [cli/](./cli/) - Command-line usage of the `fun` executable: synopsis, options, exit codes, includes and library paths. -- [fun/](./fun/) - Full usage guide for the `fun` executable: invocation patterns, REPL, env vars, include paths, examples, and install locations. -- [asyncio/](./asyncio/) - Async I/O primitives and patterns: non-blocking sockets, fd polling, examples, and best practices. -- [funstx/](./funstx/) - Syntax checker for .fun files with optional --fix auto-corrections; usage, exit codes, and limitations. -- [contributing/](./contributing/) - How to contribute: project structure, coding style, running tests, and PR guidelines. -- [style-guide/](./style-guide/) - Coding conventions for C and Fun (indentation, naming, idioms). -- [stdlib/](./stdlib/) - Overview of the standard library modules under ./lib with one-line summaries. -- [embedding/](./embedding/) - Embedding the VM from C/Rust, lifecycle, and host integration tips. -- [errors-and-diagnostics/](./errors-and-diagnostics/) - Understanding parser/runtime errors and enabling diagnostics. -- [performance/](./performance/) - Build/runtime tuning tips and patterns for better performance. -- [security-and-sandboxing/](./security-and-sandboxing/) - Trust boundaries, I/O expectations, and capability restrictions. -- [faq/](./faq/) - Frequently asked questions and quick answers. -- [website/](./website/) - Documentation for the [fun-lang.xyz](https://fun-lang.xyz) website in the `./web/` directory. -- [writing-tests/](./writing-tests/) - How to author new tests for Fun and opcode components. -- [bytecode-format/](./bytecode-format/) - Reference for the bytecode format (split out from internals for convenience). -- [roadmap/](./roadmap/) - High-level direction, planned features, and pointers to issues. +- [./build/](./build/) - How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL). +- [./cli/](./cli/) - Command-line usage of the `fun` executable: synopsis, options, exit codes, includes and library paths. +- [./fun/](./fun/) - Full usage guide for the `fun` executable: invocation patterns, REPL, env vars, include paths, examples, and install locations. +- [./asyncio/](./asyncio/) - Async I/O primitives and patterns: non-blocking sockets, fd polling, examples, and best practices. +- [./funstx/](./funstx/) - Syntax checker for .fun files with optional --fix auto-corrections; usage, exit codes, and limitations. +- [./contributing/](./contributing/) - How to contribute: project structure, coding style, running tests, and PR guidelines. +- [./style-guide/](./style-guide/) - Coding conventions for C and Fun (indentation, naming, idioms). +- [./stdlib/](./stdlib/) - Overview of the standard library modules under ./lib with one-line summaries. +- [./embedding/](./embedding/) - Embedding the VM from C/Rust, lifecycle, and host integration tips. +- [./errors-and-diagnostics/](./errors-and-diagnostics/) - Understanding parser/runtime errors and enabling diagnostics. +- [./performance/](./performance/) - Build/runtime tuning tips and patterns for better performance. +- [./security-and-sandboxing/](./security-and-sandboxing/) - Trust boundaries, I/O expectations, and capability restrictions. +- [,/faq/](./faq/) - Frequently asked questions and quick answers. +- [./website/](./website/) - Documentation for the [fun-lang.xyz](https://fun-lang.xyz) website in the `./web/` directory. +- [./writing-tests/](./writing-tests/) - How to author new tests for Fun and opcode components. +- [./bytecode-format/](./bytecode-format/) - Reference for the bytecode format (split out from internals for convenience). +- [./roadmap/](./roadmap/) - High-level direction, planned features, and pointers to issues. ## Examples - - [examples/](./examples/) - Catalog of all example scripts under [https://git.xw3.org/fun/fun/src/branch/main/examples](https://git.xw3.org/fun/fun/src/branch/main/examples){:class="git"}: what each area contains, how to run them, required env vars, and extension requirements. + - [./examples/](./examples/) - Catalog of all example scripts under [https://git.xw3.org/fun/fun/src/branch/main/examples](https://git.xw3.org/fun/fun/src/branch/main/examples){:class="git"}: what each area contains, how to run them, required env vars, and extension requirements. ## External extensions @@ -81,6 +80,6 @@ Documentation for optional, build-time selectable integrations lives in [externa ## Tips - When building from the repo without installing, set `FUN_LIB_DIR` to the local `./lib` directory so examples and the REPL can locate the stdlib. -- For a broader project overview and quickstart, see the repository root [README/](../../README/). +- For a broader project overview and quickstart, see the repository root [README/](./../README/). - Crypto examples: - If built with `-DFUN_WITH_OPENSSL=ON`, try `examples/crypto/openssl_md5.fun`. diff --git a/web/documentation/embedding.md b/web/documentation/embedding/embedding.md similarity index 69% rename from web/documentation/embedding.md rename to web/documentation/embedding/embedding.md index 095e866..2d39d00 100644 --- a/web/documentation/embedding.md +++ b/web/documentation/embedding/embedding.md @@ -22,8 +22,8 @@ tags: This guide outlines how to embed the Fun VM in a host application and extend it from C/Rust. ## Overview -- The VM is implemented in C (see [src/vm](../src/vm/)). -- Optional Rust-based opcodes can be enabled via `FUN_WITH_RUST` (see [rust.md](./rust/)). +- The VM is implemented in C (see [../internals/](../internals/)). +- Optional Rust-based opcodes can be enabled via `FUN_WITH_RUST` (see [../rust/](../rust/)). ## Embedding from C While the exact API surface may evolve, a typical embedding flow looks like: @@ -33,7 +33,7 @@ While the exact API surface may evolve, a typical embedding flow looks like: 4. Execute entry function or script body. 5. Retrieve results and clean up. -See [src/vm/core](../src/vm/core/) and related headers for public entry points and value types. +See [https://git.xw3.org/fun/fun/src/branch/main/src/](https://git.xw3.org/fun/fun/src/branch/main/src/){:class="git"} and related headers for public entry points and value types. ### Hosting considerations - Threading: share VM state cautiously or create one VM per thread. @@ -41,8 +41,8 @@ See [src/vm/core](../src/vm/core/) and related headers for public entry points a - Errors: propagate parse/runtime errors back to the host with useful messages. ## Extending with Rust -When `FUN_WITH_RUST=ON`, a Rust static library from [`src/rust/`](../src/rust/) is built and linked. You can: +When `FUN_WITH_RUST=ON`, a Rust static library from [https://git.xw3.org/fun/fun/src/branch/main/src/rust](https://git.xw3.org/fun/fun/src/branch/main/src/rust){:class="git"} is built and linked. You can: - Implement new opcodes/functions in Rust. - Expose a C ABI for the VM to call into. -See [rust.md](./rust/) for details and example code. +See [../rust/](../rust/) for details and example code. diff --git a/web/documentation/errors-and-diagnostics.md b/web/documentation/errors-and-diagnostics/errors-and-diagnostics.md similarity index 96% rename from web/documentation/errors-and-diagnostics.md rename to web/documentation/errors-and-diagnostics/errors-and-diagnostics.md index ea2708e..c1306d1 100644 --- a/web/documentation/errors-and-diagnostics.md +++ b/web/documentation/errors-and-diagnostics/errors-and-diagnostics.md @@ -27,7 +27,7 @@ This guide helps you understand common error messages and how to collect useful - Runtime errors: type mismatches, out-of-range access, invalid operations. ## Enabling diagnostics -- Build with `-DFUN_DEBUG=ON` to enable additional assertions and debug messages (see [build.md](./build/)). +- Build with `-DFUN_DEBUG=ON` to enable additional assertions and debug messages (see [build](./build/)). - Run with smaller, focused scripts to isolate issues. ## Getting useful reports diff --git a/web/documentation/examples/README.md b/web/documentation/examples/README.md deleted file mode 100644 index 0500946..0000000 --- a/web/documentation/examples/README.md +++ /dev/null @@ -1,246 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - Examples catalog and how to run them -subtitle: Catalog of all example scripts under ./examples/, what each area contains, how to run them, required env vars, and extension requirements. -description: Catalog of all example scripts under ./examples/, what each area contains, how to run them, required env vars, and extension requirements. -permalink: /documentation/examples/ -lang: en -tags: -- area -- catalog -- contains -- env -- example -- examples -- extension -- required -- requirements -- run -- scripts -- them -- under -- vars -- what ---- - - -This page is a practical catalog of the example areas that ship with the Fun language. It explains what you’ll find in each folder under ./examples/, how to run the scripts, and where deeper walkthroughs live. - -If you’re building/running from the repository without installing, set FUN_LIB_DIR to the local ./lib directory so examples can locate the stdlib: - -- export FUN_LIB_DIR="./lib" -- Then run an example: ./build_debug/fun examples/basics/hello_world.fun - - Or, if installed: fun examples/basics/hello_world.fun - -Notes -- Most scripts are self‑documented with a short header comment at the top. Open them to see exact behavior and expected output. -- Some examples depend on optional extensions (cURL, PCRE2, SQLite, Notcurses, Tk, PC/SC, OpenSSL/LibreSSL). See documentation/external/ for enablement and availability. -- Networking examples often bind to 127.0.0.1 on high ports; read the file header for the exact port. - -Deep‑dives - -## Top‑level examples (./examples) - -Quick micro demos covering language features and tiny utilities. - -Run pattern: -- fun examples/.fun - -Highlights (selection): - -- [builtins_extended.fun](./builtins_extended/) — tour of core built‑ins beyond the basics -- [byte_for_demo.fun](./byte_for_demo/) — iterating bytes with for -- [byte_overflow_try_catch.fun](./byte_overflow_try_catch/) — error handling on overflow -- [cast_demo.fun](./cast_demo/) — conversions and casting helpers -- [class_constructor.fun](./class_constructor/) — basic constructor usage and init patterns -- [class_test.fun](./class_test/) — small class feature checks -- [classes_demo.fun](classes_demo/) — class basics and usage -- [class_without_object.fun](./class_without_object/) — class features without an instance helper -- [cli_argv_dump.fun](./cli_argv_dump/) — prints argv/argc handling -- [conversions_showcase.fun](./conversions_showcase/) — numbers, strings, bytes conversions -- [cpp_add.fun](./cpp_add/) — calling into the optional C++ extension (if enabled) -- [datetime_basic.fun](./datetime_basic/) — minimal date/time helpers -- [datetime_extended.fun](./datetime_extended/) — richer date/time operations -- [datetime_timer.fun](datetime_timer/) — time/date helpers -- [echo_example.fun](./echo_example/) — simple echo of input/args -- [env_all.fun](./env_all/) — enumerate environment variables -- [os_env.fun](./os_env/) — reading environment variables -- [error_handling.fun](./error_handling/) — try/catch and error objects -- [try_catch_finally.fun](try_catch_finally/) — error patterns -- [expressions_test.fun](./expressions_test/) — precedence and grouping -- [features.fun](./features/) — grab bag of language features -- [file_print_for_file_line_by_line.fun](./file_print_for_file_line_by_line/) — iterate file content -- [floats.fun](./floats/) — float ops and formatting -- [for_range_test.fun](./for_range_test/) — ranges and loops -- [functions_test.fun](./functions_test/) — functions, closures, returns -- [have_fun.fun](./have_fun/) — playful starter demo -- [have_fun_function.fun](have_fun_function/) — playful demos -- [hex_example.fun](./hex_example/) — hex encode/decode -- [if_else_test.fun](./if_else_test/) — conditional branching examples -- [nested_loops.fun](./nested_loops/) — loops inside loops -- [loops_break_continue.fun](loops_break_continue/) — control flow -- [include_local.fun](./include_local/) — include a local file/module -- [include_lib.fun](./include_lib/) — include from the stdlib path -- [include_local_util.fun](include_local_util/) — include mechanics -- [inheritance_demo.fun](./inheritance_demo/) — simple class inheritance -- [maps.fun](./maps/), [match.fun](match/) — data structures and pattern matching -- [namespaced_mod.fun](./namespaced_mod/) — namespaced includes with as -- [objects_basic.fun](./objects_basic/) — simple objects and methods -- [objects_more.fun](./objects_more/) — OO basics -- [process_example.fun](./process_example/) — spawn and capture subprocess output -- [progress.fun](./progress/) — progress bar helper -- [progress_inline.fun](./progress_inline/) — simple progress displays -- [random_demo.fun](./random_demo/) — random helpers overview -- [random_number_example.fun](random_number_example/) — RNG usage -- [regex_demo.fun](./regex_demo/) — regex basics (PCRE2 when enabled) -- [regex_procedural.fun](./regex_procedural/) — regex helpers (PCRE2 when enabled) -- [rust_hello.fun](./rust_hello/), rust_hello_args*.fun — Rust opcodes (if FUN_WITH_RUST) -- [serial_demo.fun](./serial_demo/) — serial port usage -- [test_serial.fun](./test_serial/) — serial port (when available) -- [short_circuit_test.fun](./short_circuit_test/) — boolean evaluation order -- [signed_ints.fun](./signed_ints/) — signed integers overview -- [uint_types.fun](./uint_types/) — unsigned integers overview -- [types_integers.fun](./types_integers/) — integer families -- [stdlib_showcase.fun](./stdlib_showcase/) — sampler of common stdlib modules -- [strings_test.fun](./strings_test/) — string helpers and edge cases -- [tcp_http_get.fun](./tcp_http_get/) — simple HTTP GET over raw TCP -- [tcp_http_get_class.fun](./tcp_http_get_class/) — manual HTTP client over sockets -- [test_bits.fun](./test_bits/) — /rol/shl/xor/dec_to_hex/hex_to_dec bitwise utilities -- [thread_class_example.fun](./thread_class_example/) — define and run a thread class -- [threads_demo.fun](./threads_demo/) — threading building blocks -- [typeof.fun](./typeof/) — type inspection -- [typeof_features.fun](./typeof_features/) — type inspection of declared integer subtypes and runtime categories -- [type_safety.fun](./type_safety/) — static/dynamic type checks -- [type_safety_fails.fun](./type_safety_fails/) — static/dynamic type checks -- [types_overview.fun](./types_overview/) — language types tour -- [unix_socket_echo.fun](./unix_socket_echo/) — local domain socket echo demo -- [version.fun](./version/) — print VM/version info -- [while_test.fun](./while_test/) — simple while loop example - -Tip: If a file name is listed above but not present on your build, it may depend on an extension you did not enable. - - -## Algorithms (./examples/algos) -- deduplicate.fun — removing duplicates from arrays/maps -- sort_and_search.fun — sorting and lookup patterns -- stack_queue.fun — basic stack and queue implementation - -## Arrays (./examples/arrays) -- arrays.fun — create, index, slice; typical idioms -- arrays_iter.fun — iteration and enumeration -- arrays_advanced.fun — copying, filtering, transformations - -## Basics (./examples/basics) -- boolean_decl.fun, booleans.fun — boolean values and operators -- builtins_conversions.fun — core built‑ins, type conversions -- collections.fun — arrays, maps, nested structures -- fibonacci.fun, fizzbuzz.fun — classic exercises -- hello_world.fun — the canonical first program - -## CLI (./examples/cli) -- args_parse.fun — arguments parsing patterns for small CLIs - -## Compose (./examples/compose) -Compositional patterns, small abstractions to combine behavior. - -## Crypto (./examples/crypto) -Hashing and cryptographic helpers. Availability depends on whether OpenSSL/LibreSSL is enabled. -- openssl_md5.fun — MD5 via OpenSSL (if -DFUN_WITH_OPENSSL) -- libressl_md5.fun — MD5 via LibreSSL (if -DFUN_WITH_LIBRESSL) -- aes256.fun and hash samples if present on your build - -## Data (./examples/data) -Static assets for example servers; not meant to be run directly. -- htdocumentation/ — files used by HTTP server examples (index.html, hello.fun, info.fun, form_post.fun, counter.fun, redirect.fun, json_like_api.fun) - -## Error handling and diagnostics (./examples/error) -- debug_reporting.fun — enabling debug output and reading traces -- exit_example.fun — exit codes -- fail.fun — triggering and observing failures -- repl_on_error.fun — dropping into REPL on error -- rust_vm_access.fun — Rust opcode errors (if enabled) -- test_indent.fun — parser/indentation corner cases -- try_catch_with_error.fun — capturing error objects - -## Extra integrations (./examples/extra) -These require optional external libraries. See documentation/external/. -- curl_* — cURL HTTP client examples (download, GET JSON, POST) -- ini_* — parsing INI files (simple to complex) -- json_showcase.fun — JSON helpers -- libsql_example.fun — libSQL client usage -- notcurses_* — rich TUI demos (if Notcurses enabled) -- pcre2_* — PCRE2 regex engine demos -- pcsc*.fun — smart card access via PC/SC -- sqlite_example.fun — SQLite usage -- tcp_echo_server*.fun — basic TCP echo server -- tk_* — Tcl/Tk GUI examples -- xml_* — XML parsing with libxml2 - -## Interactive (./examples/interactive) -- console_prompt.fun — simple prompt loop -- input_example.fun — reading user input -- input_hidden_example.fun, input_hidden_pam_auth.fun — hidden input/passwords - -## IO (./examples/io) -- async_http_client.fun — non‑blocking HTTP client -- await_http_client.fun — non‑blocking HTTP client using lib/async/scheduler.fun (await-style helpers) -- csv_reader.fun — parse CSV files -- file_io.fun, read_write_file.fun — file operations -- word_count.fun — classic WC example - -## Math (./examples/math) -Small, focused math helpers and demonstrations: -- math_ceil, math_floor, math_round, math_trunc, math_sign -- math_cos, math_sin, math_tan -- math_sqrt, math_isqrt -- math_exp_log -- math_fmin_fmax -- math_gcd_lcm - -## Networking (./examples/net) -Servers and socket utilities. See documentation/examples/net/httpserver.md for the HTTP family. -- HTTP servers: [httpserver.md](./net/httpserver/) — end‑to‑end walkthrough of all HTTP server variants in examples/net/ -- http_static_server.fun — minimal static server over sockets -- http_server.fun — blocking static/CGI dispatcher using lib/net/http_server.fun -- http_server_cgi.fun — blocking server with CGI via lib/net/http_cgi_server.fun -- http_server_cgi_lib.fun — blocking server leveraging net/cgi.fun helpers -- http_mt_server.fun — thread‑per‑connection static server -- http_mt_server_cgi.fun — thread‑per‑connection with CGI support - -## Patterns (./examples/patterns) -Small idioms and reusable patterns. -- assert_like.fun — assert‑style checks via language constructs - -## Snippets (./examples/snippets) -Miscellaneous one‑off code snippets demonstrating particular opcodes or tricks. - -## SQLite daemon (./examples/sqlited) -- Files related to running a small SQLite‑backed service (see source for details) - -## Strings (./examples/strings) -- base64_demo.fun — base64 encode/decode using encoding/base64 -- split_join_trim.fun — string splitting and trimming -- templating_min.fun — bare‑bones templating -- urlencode_decode.fun — percent‑encoding helpers - -## Broken (./examples/broken) -Historical or intentionally broken examples kept for reference/regression. -- notcurses_* — experiments around Notcurses -- ripemd160* — legacy or experimental hash routines - -### Running examples reliably - -Prefer the local build when running from the repository root: -- ./build_debug/fun -- or: ./build_release/fun - -Set up env if needed: -- export FUN_LIB_DIR="./lib" # to find stdlib -- export FUN_EXEC="./build_debug/fun" # used by CGI examples -- export FUN_HTDOCS="./examples/data/htdocs" # override docroot - -When optional extensions are not enabled, their examples will not run; reconfigure the build with the required -D flags shown in documentation/external/. diff --git a/web/documentation/examples/builtins_extended.md b/web/documentation/examples/builtins_extended.md deleted file mode 100644 index 36982ac..0000000 --- a/web/documentation/examples/builtins_extended.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - builtins_extended.fun — overview -subtitle: Documentation for builtins_extended.fun — overview -description: Documentation for builtins_extended.fun — overview -permalink: /documentation/examples/builtins_extended/ -lang: en -tags: -- builtins_extended -- example ---- - - -What it shows -- A tour of core built‑ins beyond the basics: printing, typing, math helpers, conversions, and utility functions commonly used in small scripts. - -How to run -- From repo root with local build: - - export FUN_LIB_DIR="./lib" - - ./build_debug/fun examples/builtins_extended.fun -- Or, if installed: fun examples/builtins_extended.fun - -Notes -- Exact behavior and outputs are documented inline at the top of the script; open the .fun file for details. diff --git a/web/documentation/examples/builtins_maps_and_more.md b/web/documentation/examples/builtins_maps_and_more.md deleted file mode 100644 index daa1c72..0000000 --- a/web/documentation/examples/builtins_maps_and_more.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - builtins_maps_and_more.fun — overview -subtitle: Documentation for builtins_maps_and_more.fun — overview -description: Documentation for builtins_maps_and_more.fun — overview -permalink: /documentation/examples/builtins_maps_and_more/ -lang: en -tags: -- builtins_maps_and_more -- example ---- - - -What it shows -- Exploring built‑ins while working with maps and related data structures. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/builtins_maps_and_more.fun -- Or: fun examples/builtins_maps_and_more.fun - -Notes -- Open the .fun file to see the exact behaviors and printed output. diff --git a/web/documentation/examples/byte_for_demo.md b/web/documentation/examples/byte_for_demo.md deleted file mode 100644 index 455ba48..0000000 --- a/web/documentation/examples/byte_for_demo.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - byte_for_demo.fun — overview -subtitle: Documentation for byte_for_demo.fun — overview -description: Documentation for byte_for_demo.fun — overview -permalink: /documentation/examples/byte_for_demo/ -lang: en -tags: -- byte_for_demo -- example ---- - - -What it shows -- Iterating bytes with a for-loop; indexing and printing byte values. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/byte_for_demo.fun -- Or: fun examples/byte_for_demo.fun diff --git a/web/documentation/examples/byte_overflow_try_catch.md b/web/documentation/examples/byte_overflow_try_catch.md deleted file mode 100644 index 6b72711..0000000 --- a/web/documentation/examples/byte_overflow_try_catch.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - byte_overflow_try_catch.fun — overview -subtitle: Documentation for byte_overflow_try_catch.fun — overview -description: Documentation for byte_overflow_try_catch.fun — overview -permalink: /documentation/examples/byte_overflow_try_catch/ -lang: en -tags: -- byte_overflow_try_catch -- example ---- - - -What it shows -- Error handling around byte/integer overflow using try/catch. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/byte_overflow_try_catch.fun -- Or: fun examples/byte_overflow_try_catch.fun diff --git a/web/documentation/examples/cast_demo.md b/web/documentation/examples/cast_demo.md deleted file mode 100644 index 9583624..0000000 --- a/web/documentation/examples/cast_demo.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - cast_demo.fun — overview -subtitle: Documentation for cast_demo.fun — overview -description: Documentation for cast_demo.fun — overview -permalink: /documentation/examples/cast_demo/ -lang: en -tags: -- cast_demo -- example ---- - - -What it shows -- Conversions and casting helpers; demonstrates changing between numeric and string types safely. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/cast_demo.fun -- Or: fun examples/cast_demo.fun diff --git a/web/documentation/examples/class_constructor.md b/web/documentation/examples/class_constructor.md deleted file mode 100644 index c6e4e9f..0000000 --- a/web/documentation/examples/class_constructor.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - class_constructor.fun — overview -subtitle: Documentation for class_constructor.fun — overview -description: Documentation for class_constructor.fun — overview -permalink: /documentation/examples/class_constructor/ -lang: en -tags: -- class_constructor -- example ---- - - -What it shows -- Class basics and constructor behavior; initializing fields and using methods. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/class_constructor.fun -- Or: fun examples/class_constructor.fun diff --git a/web/documentation/examples/class_test.md b/web/documentation/examples/class_test.md deleted file mode 100644 index 1b01d26..0000000 --- a/web/documentation/examples/class_test.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - class_test.fun — overview -subtitle: Documentation for class_test.fun — overview -description: Documentation for class_test.fun — overview -permalink: /documentation/examples/class_test/ -lang: en -tags: -- class_test -- example ---- - - -What it shows -- Simple class usage and method invocation; small sanity checks around classes. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/class_test.fun -- Or: fun examples/class_test.fun - -Notes -- Open the script to see the exact behavior and outputs. diff --git a/web/documentation/examples/class_without_object.md b/web/documentation/examples/class_without_object.md deleted file mode 100644 index 1ffffbc..0000000 --- a/web/documentation/examples/class_without_object.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - class_without_object.fun — overview -subtitle: Documentation for class_without_object.fun — overview -description: Documentation for class_without_object.fun — overview -permalink: /documentation/examples/class_without_object/ -lang: en -tags: -- class_without_object -- example ---- - - -What it shows -- Class features that can be used without creating an instance (static-like usage patterns). - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/class_without_object.fun -- Or: fun examples/class_without_object.fun diff --git a/web/documentation/examples/classes_demo.md b/web/documentation/examples/classes_demo.md deleted file mode 100644 index 5e8ec05..0000000 --- a/web/documentation/examples/classes_demo.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - classes_demo.fun — overview -subtitle: Documentation for classes_demo.fun — overview -description: Documentation for classes_demo.fun — overview -permalink: /documentation/examples/classes_demo/ -lang: en -tags: -- classes_demo -- example ---- - - -What it shows -- Class basics and usage: defining classes, instantiating objects, calling methods. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/classes_demo.fun -- Or: fun examples/classes_demo.fun diff --git a/web/documentation/examples/cli_argv_dump.md b/web/documentation/examples/cli_argv_dump.md deleted file mode 100644 index 1fb48f4..0000000 --- a/web/documentation/examples/cli_argv_dump.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - cli_argv_dump.fun — overview -subtitle: Documentation for cli_argv_dump.fun — overview -description: Documentation for cli_argv_dump.fun — overview -permalink: /documentation/examples/cli_argv_dump/ -lang: en -tags: -- cli_argv_dump -- example ---- - - -What it shows -- Prints argv/argc handling to demonstrate CLI arguments parsing at a low level. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/cli_argv_dump.fun --foo bar 123 -- Or: fun examples/cli_argv_dump.fun --foo bar 123 diff --git a/web/documentation/examples/conversions_showcase.md b/web/documentation/examples/conversions_showcase.md deleted file mode 100644 index 435741a..0000000 --- a/web/documentation/examples/conversions_showcase.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - conversions_showcase.fun — overview -subtitle: Documentation for conversions_showcase.fun — overview -description: Documentation for conversions_showcase.fun — overview -permalink: /documentation/examples/conversions_showcase/ -lang: en -tags: -- conversions_showcase -- example ---- - - -What it shows -- Numbers, strings, and bytes conversions; typical idioms and edge cases. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/conversions_showcase.fun -- Or: fun examples/conversions_showcase.fun diff --git a/web/documentation/examples/cpp_add.md b/web/documentation/examples/cpp_add.md deleted file mode 100644 index e05f641..0000000 --- a/web/documentation/examples/cpp_add.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - cpp_add.fun — overview -subtitle: Documentation for cpp_add.fun — overview -description: Documentation for cpp_add.fun — overview -permalink: /documentation/examples/cpp_add/ -lang: en -tags: -- cpp_add -- example ---- - - -What it shows -- Calling into the optional C++ extension from Fun. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/cpp_add.fun -- Or: fun examples/cpp_add.fun - -Notes -- Requires the optional C++ extension to be enabled in your build; otherwise this example may be unavailable. diff --git a/web/documentation/examples/data/htdocs/counter.md b/web/documentation/examples/data/htdocs/counter.md deleted file mode 100644 index 3b460a0..0000000 --- a/web/documentation/examples/data/htdocs/counter.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - counter.fun (CGI) -subtitle: Documentation for counter.fun (CGI) -description: Documentation for counter.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/counter/ -lang: en -tags: -- cgi -- counter -- example ---- - - -- Location: examples/data/htdocumentation/counter.fun -- Category: CGI script used by HTTP server examples - -Description -- Simple stateful counter example for CGI; demonstrates reading and updating a value across requests (implementation details in script). - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Open: http://127.0.0.1:8080/counter.fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/data/htdocs/form_post.md b/web/documentation/examples/data/htdocs/form_post.md deleted file mode 100644 index 7efe6c2..0000000 --- a/web/documentation/examples/data/htdocs/form_post.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - form_post.fun (CGI) -subtitle: Documentation for form_post.fun (CGI) -description: Documentation for form_post.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/form_post/ -lang: en -tags: -- cgi -- example -- form_post ---- - - -- Location: examples/data/htdocumentation/form_post.fun -- Category: CGI script used by HTTP server examples - -Description -- Demonstrates handling of POST form data via the CGI interface. - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Submit a form to: http://127.0.0.1:8080/form_post.fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/data/htdocs/hello.md b/web/documentation/examples/data/htdocs/hello.md deleted file mode 100644 index dee58fb..0000000 --- a/web/documentation/examples/data/htdocs/hello.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - hello.fun (CGI) -subtitle: Documentation for hello.fun (CGI) -description: Documentation for hello.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/hello/ -lang: en -tags: -- cgi -- example -- hello ---- - - -- Location: examples/data/htdocumentation/hello.fun -- Category: CGI script used by HTTP server examples - -Description -- Simple CGI .fun script that prints a greeting, optionally using query parameters (e.g., ?name=Fun). - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Open: http://127.0.0.1:8080/hello.fun?name=Fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/data/htdocs/info.md b/web/documentation/examples/data/htdocs/info.md deleted file mode 100644 index 0529342..0000000 --- a/web/documentation/examples/data/htdocs/info.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - info.fun (CGI) -subtitle: Documentation for info.fun (CGI) -description: Documentation for info.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/info/ -lang: en -tags: -- cgi -- example -- info ---- - - -- Location: examples/data/htdocumentation/info.fun -- Category: CGI script used by HTTP server examples - -Description -- CGI script that prints request/environment information, useful for debugging CGI variables. - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Open: http://127.0.0.1:8080/info.fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/data/htdocs/json_like_api.md b/web/documentation/examples/data/htdocs/json_like_api.md deleted file mode 100644 index 601766c..0000000 --- a/web/documentation/examples/data/htdocs/json_like_api.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - json_like_api.fun (CGI) -subtitle: Documentation for json_like_api.fun (CGI) -description: Documentation for json_like_api.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/json_like_api/ -lang: en -tags: -- cgi -- example -- json_like_api ---- - - -- Location: examples/data/htdocumentation/json_like_api.fun -- Category: CGI script used by HTTP server examples - -Description -- Demonstrates returning JSON-like output from a CGI endpoint. - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Open: http://127.0.0.1:8080/json_like_api.fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/data/htdocs/redirect.md b/web/documentation/examples/data/htdocs/redirect.md deleted file mode 100644 index 5390697..0000000 --- a/web/documentation/examples/data/htdocs/redirect.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - redirect.fun (CGI) -subtitle: Documentation for redirect.fun (CGI) -description: Documentation for redirect.fun (CGI) -permalink: /documentation/examples/data/htdocumentation/redirect/ -lang: en -tags: -- cgi -- example -- redirect ---- - - -- Location: examples/data/htdocumentation/redirect.fun -- Category: CGI script used by HTTP server examples - -Description -- Demonstrates issuing HTTP redirects from a CGI script (setting Status and Location headers). - -How to run -- Through one of the HTTP server examples, e.g.: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" - - ./build_debug/fun examples/net/http_server_cgi.fun - - Open: http://127.0.0.1:8080/redirect.fun - -See also -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/datetime_basic.md b/web/documentation/examples/datetime_basic.md deleted file mode 100644 index 0c49979..0000000 --- a/web/documentation/examples/datetime_basic.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - datetime_basic.fun — overview -subtitle: Documentation for datetime_basic.fun — overview -description: Documentation for datetime_basic.fun — overview -permalink: /documentation/examples/datetime_basic/ -lang: en -tags: -- datetime_basic -- example ---- - - -What it shows -- Basic time/date helpers and formatting. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/datetime_basic.fun -- Or: fun examples/datetime_basic.fun diff --git a/web/documentation/examples/datetime_extended.md b/web/documentation/examples/datetime_extended.md deleted file mode 100644 index 7b38a0b..0000000 --- a/web/documentation/examples/datetime_extended.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - datetime_extended.fun — overview -subtitle: Documentation for datetime_extended.fun — overview -description: Documentation for datetime_extended.fun — overview -permalink: /documentation/examples/datetime_extended/ -lang: en -tags: -- datetime_extended -- example ---- - - -What it shows -- Extended datetime helpers: parsing, arithmetic, timers, and formatting variants. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/datetime_extended.fun -- Or: fun examples/datetime_extended.fun diff --git a/web/documentation/examples/datetime_timer.md b/web/documentation/examples/datetime_timer.md deleted file mode 100644 index d104724..0000000 --- a/web/documentation/examples/datetime_timer.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - datetime_timer.fun — overview -subtitle: Documentation for datetime_timer.fun — overview -description: Documentation for datetime_timer.fun — overview -permalink: /documentation/examples/datetime_timer/ -lang: en -tags: -- datetime_timer -- example ---- - - -What it shows -- Measuring elapsed time and simple timers using datetime helpers. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/datetime_timer.fun -- Or: fun examples/datetime_timer.fun diff --git a/web/documentation/examples/echo_example.md b/web/documentation/examples/echo_example.md deleted file mode 100644 index 5a23c7b..0000000 --- a/web/documentation/examples/echo_example.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - echo_example.fun — overview -subtitle: Documentation for echo_example.fun — overview -description: Documentation for echo_example.fun — overview -permalink: /documentation/examples/echo_example/ -lang: en -tags: -- echo_example -- example ---- - - -What it shows -- Simple echo of input/args; prints back what you type or pass as arguments. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/echo_example.fun hello world -- Or: fun examples/echo_example.fun hello world diff --git a/web/documentation/examples/env_all.md b/web/documentation/examples/env_all.md deleted file mode 100644 index c62a3f3..0000000 --- a/web/documentation/examples/env_all.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - env_all.fun — overview -subtitle: Documentation for env_all.fun — overview -description: Documentation for env_all.fun — overview -permalink: /documentation/examples/env_all/ -lang: en -tags: -- env_all -- example ---- - - -What it shows -- Reading and listing environment variables. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/env_all.fun -- Or: fun examples/env_all.fun diff --git a/web/documentation/examples/error_handling.md b/web/documentation/examples/error_handling.md deleted file mode 100644 index f96d482..0000000 --- a/web/documentation/examples/error_handling.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - error_handling.fun — overview -subtitle: Documentation for error_handling.fun — overview -description: Documentation for error_handling.fun — overview -permalink: /documentation/examples/error_handling/ -lang: en -tags: -- error_handling -- example ---- - - -What it shows -- Error patterns and handling strategies using try/catch/finally. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/error_handling.fun -- Or: fun examples/error_handling.fun diff --git a/web/documentation/examples.md b/web/documentation/examples/examples.md similarity index 95% rename from web/documentation/examples.md rename to web/documentation/examples/examples.md index e689517..41f4a44 100644 --- a/web/documentation/examples.md +++ b/web/documentation/examples/examples.md @@ -28,7 +28,7 @@ All commands assume you are in the repository root. ## Prerequisites -- Build the interpreter (see handbook.md). You’ll have `build/fun` (paths may vary by your setup/IDE). +- Build the interpreter (see handbook/). You’ll have `build/fun` (paths may vary by your setup/IDE). - Set FUN_LIB_DIR to the repo’s lib directory when running without installation so `#include <...>` can find the standard library. Example (Linux/macOS/BSD): diff --git a/web/documentation/examples/expressions_test.md b/web/documentation/examples/expressions_test.md deleted file mode 100644 index 340e105..0000000 --- a/web/documentation/examples/expressions_test.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - expressions_test.fun — overview -subtitle: Documentation for expressions_test.fun — overview -description: Documentation for expressions_test.fun — overview -permalink: /documentation/examples/expressions_test/ -lang: en -tags: -- example -- expressions_test ---- - - -What it shows -- Operator precedence and expression grouping tests/demonstrations. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/expressions_test.fun -- Or: fun examples/expressions_test.fun diff --git a/web/documentation/examples/features.md b/web/documentation/examples/features.md deleted file mode 100644 index a126b93..0000000 --- a/web/documentation/examples/features.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - features.fun — overview -subtitle: Documentation for features.fun — overview -description: Documentation for features.fun — overview -permalink: /documentation/examples/features/ -lang: en -tags: -- example -- features ---- - - -What it shows -- Grab bag of language features in a single script. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/features.fun -- Or: fun examples/features.fun diff --git a/web/documentation/examples/file_print_for_file_line_by_line.md b/web/documentation/examples/file_print_for_file_line_by_line.md deleted file mode 100644 index bf9ab00..0000000 --- a/web/documentation/examples/file_print_for_file_line_by_line.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - file_print_for_file_line_by_line.fun — overview -subtitle: Documentation for file_print_for_file_line_by_line.fun — overview -description: Documentation for file_print_for_file_line_by_line.fun — overview -permalink: /documentation/examples/file_print_for_file_line_by_line/ -lang: en -tags: -- example -- file_print_for_file_line_by_line ---- - - -What it shows -- Iterate a file line-by-line and print each line; basic file IO idioms. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/file_print_for_file_line_by_line.fun path/to/file.txt -- Or: fun examples/file_print_for_file_line_by_line.fun path/to/file.txt diff --git a/web/documentation/examples/floats.md b/web/documentation/examples/floats.md deleted file mode 100644 index 50c1449..0000000 --- a/web/documentation/examples/floats.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - floats.fun — overview -subtitle: Documentation for floats.fun — overview -description: Documentation for floats.fun — overview -permalink: /documentation/examples/floats/ -lang: en -tags: -- example -- floats ---- - - -What it shows -- Floating point operations and formatting details. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/floats.fun -- Or: fun examples/floats.fun diff --git a/web/documentation/examples/for_range_test.md b/web/documentation/examples/for_range_test.md deleted file mode 100644 index 34a9429..0000000 --- a/web/documentation/examples/for_range_test.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - for_range_test.fun — overview -subtitle: Documentation for for_range_test.fun — overview -description: Documentation for for_range_test.fun — overview -permalink: /documentation/examples/for_range_test/ -lang: en -tags: -- example -- for_range_test ---- - - -What it shows -- Ranges and loops; iterating numeric ranges and verifying bounds. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/for_range_test.fun -- Or: fun examples/for_range_test.fun diff --git a/web/documentation/examples/functions_test.md b/web/documentation/examples/functions_test.md deleted file mode 100644 index 4b39c7f..0000000 --- a/web/documentation/examples/functions_test.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - functions_test.fun — overview -subtitle: Documentation for functions_test.fun — overview -description: Documentation for functions_test.fun — overview -permalink: /documentation/examples/functions_test/ -lang: en -tags: -- example -- functions_test ---- - - -What it shows -- Functions, closures, and return behavior; call semantics basics. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/functions_test.fun -- Or: fun examples/functions_test.fun diff --git a/web/documentation/examples/have_fun.md b/web/documentation/examples/have_fun.md deleted file mode 100644 index 0026131..0000000 --- a/web/documentation/examples/have_fun.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - have_fun.fun — overview -subtitle: Documentation for have_fun.fun — overview -description: Documentation for have_fun.fun — overview -permalink: /documentation/examples/have_fun/ -lang: en -tags: -- example -- have_fun ---- - - -What it shows -- Playful demo showing off small language tricks. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/have_fun.fun -- Or: fun examples/have_fun.fun diff --git a/web/documentation/examples/have_fun_function.md b/web/documentation/examples/have_fun_function.md deleted file mode 100644 index 5f65a98..0000000 --- a/web/documentation/examples/have_fun_function.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - have_fun_function.fun — overview -subtitle: Documentation for have_fun_function.fun — overview -description: Documentation for have_fun_function.fun — overview -permalink: /documentation/examples/have_fun_function/ -lang: en -tags: -- example -- have_fun_function ---- - - -What it shows -- A playful function-centric demo; small utility behaviors. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/have_fun_function.fun -- Or: fun examples/have_fun_function.fun diff --git a/web/documentation/examples/hex_example.md b/web/documentation/examples/hex_example.md deleted file mode 100644 index d2e380a..0000000 --- a/web/documentation/examples/hex_example.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - hex_example.fun — overview -subtitle: Documentation for hex_example.fun — overview -description: Documentation for hex_example.fun — overview -permalink: /documentation/examples/hex_example/ -lang: en -tags: -- example -- hex_example ---- - - -What it shows -- Hex encode/decode helpers; working with hexadecimal representations. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/hex_example.fun -- Or: fun examples/hex_example.fun diff --git a/web/documentation/examples/if_else_test.md b/web/documentation/examples/if_else_test.md deleted file mode 100644 index 5316e3c..0000000 --- a/web/documentation/examples/if_else_test.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - if_else_test.fun — overview -subtitle: Documentation for if_else_test.fun — overview -description: Documentation for if_else_test.fun — overview -permalink: /documentation/examples/if_else_test/ -lang: en -tags: -- example -- if_else_test ---- - - -What it shows -- Control flow with if/else; branching and comparisons. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/if_else_test.fun -- Or: fun examples/if_else_test.fun diff --git a/web/documentation/examples/include_lib.md b/web/documentation/examples/include_lib.md deleted file mode 100644 index b76f031..0000000 --- a/web/documentation/examples/include_lib.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - include_lib.fun — overview -subtitle: Documentation for include_lib.fun — overview -description: Documentation for include_lib.fun — overview -permalink: /documentation/examples/include_lib/ -lang: en -tags: -- example -- include_lib ---- - - -What it shows -- Including modules from the standard library path using #include <...>. - -How to run -- export FUN_LIB_DIR="./lib" # ensure stdlib is discoverable -- ./build_debug/fun examples/include_lib.fun -- Or: fun examples/include_lib.fun diff --git a/web/documentation/examples/include_local.md b/web/documentation/examples/include_local.md deleted file mode 100644 index 413e0da..0000000 --- a/web/documentation/examples/include_local.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - include_local.fun — overview -subtitle: Documentation for include_local.fun — overview -description: Documentation for include_local.fun — overview -permalink: /documentation/examples/include_local/ -lang: en -tags: -- example -- include_local ---- - - -What it shows -- Including local files relative to the script and reusing helpers. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/include_local.fun -- Or: fun examples/include_local.fun diff --git a/web/documentation/examples/include_local_util.md b/web/documentation/examples/include_local_util.md deleted file mode 100644 index b359340..0000000 --- a/web/documentation/examples/include_local_util.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - include_local_util.fun — overview -subtitle: Documentation for include_local_util.fun — overview -description: Documentation for include_local_util.fun — overview -permalink: /documentation/examples/include_local_util/ -lang: en -tags: -- example -- include_local_util ---- - - -What it shows -- Local include mechanics with a small utility module. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/include_local_util.fun -- Or: fun examples/include_local_util.fun diff --git a/web/documentation/examples/inheritance_demo.md b/web/documentation/examples/inheritance_demo.md deleted file mode 100644 index 3304bda..0000000 --- a/web/documentation/examples/inheritance_demo.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - inheritance_demo.fun — overview -subtitle: Documentation for inheritance_demo.fun — overview -description: Documentation for inheritance_demo.fun — overview -permalink: /documentation/examples/inheritance_demo/ -lang: en -tags: -- example -- inheritance_demo ---- - - -What it shows -- Simple class inheritance and method overriding examples. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/inheritance_demo.fun -- Or: fun examples/inheritance_demo.fun diff --git a/web/documentation/examples/loops_break_continue.md b/web/documentation/examples/loops_break_continue.md deleted file mode 100644 index 5fb5017..0000000 --- a/web/documentation/examples/loops_break_continue.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - loops_break_continue.fun — overview -subtitle: Documentation for loops_break_continue.fun — overview -description: Documentation for loops_break_continue.fun — overview -permalink: /documentation/examples/loops_break_continue/ -lang: en -tags: -- example -- loops_break_continue ---- - - -What it shows -- Loop control: break and continue; demonstrating control flow within loops. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/loops_break_continue.fun -- Or: fun examples/loops_break_continue.fun diff --git a/web/documentation/examples/maps.md b/web/documentation/examples/maps.md deleted file mode 100644 index e49b60d..0000000 --- a/web/documentation/examples/maps.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - maps.fun — overview -subtitle: Working with maps, construction, lookup/update, merging, iteration, and common patterns. -description: Working with maps, construction, lookup/update, merging, iteration, and common patterns. -permalink: /documentation/examples/maps/ -lang: en -tags: -- common -- construction -- example -- iteration -- lookup -- maps -- merging -- patterns -- update ---- - - -What it shows -- Working with maps: creation, indexing, iteration, and typical idioms. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/maps.fun -- Or: fun examples/maps.fun diff --git a/web/documentation/examples/match.md b/web/documentation/examples/match.md deleted file mode 100644 index fc186a5..0000000 --- a/web/documentation/examples/match.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - match.fun — overview -subtitle: Documentation for match.fun — overview -description: Documentation for match.fun — overview -permalink: /documentation/examples/match/ -lang: en -tags: -- example -- match ---- - - -What it shows -- Pattern matching constructs and examples of branching by value/shape. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/match.fun -- Or: fun examples/match.fun diff --git a/web/documentation/examples/namespaced_mod.md b/web/documentation/examples/namespaced_mod.md deleted file mode 100644 index 33c447c..0000000 --- a/web/documentation/examples/namespaced_mod.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - namespaced_mod.fun — overview -subtitle: Documentation for namespaced_mod.fun — overview -description: Documentation for namespaced_mod.fun — overview -permalink: /documentation/examples/namespaced_mod/ -lang: en -tags: -- example -- namespaced_mod ---- - - -What it shows -- Namespaced includes and using the "as" aliasing pattern for modules. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/namespaced_mod.fun -- Or: fun examples/namespaced_mod.fun diff --git a/web/documentation/examples/nested_loops.md b/web/documentation/examples/nested_loops.md deleted file mode 100644 index c8c2314..0000000 --- a/web/documentation/examples/nested_loops.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - nested_loops.fun — overview -subtitle: Documentation for nested_loops.fun — overview -description: Documentation for nested_loops.fun — overview -permalink: /documentation/examples/nested_loops/ -lang: en -tags: -- example -- nested_loops ---- - - -What it shows -- Control flow with nested loops; inner/outer loop coordination. - -How to run -- export FUN_LIB_DIR="./lib" -- ./build_debug/fun examples/nested_loops.fun -- Or: fun examples/nested_loops.fun diff --git a/web/documentation/examples/net/http_mt_server.md b/web/documentation/examples/net/http_mt_server.md deleted file mode 100644 index a2537d2..0000000 --- a/web/documentation/examples/net/http_mt_server.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_mt_server.fun -subtitle: Documentation for http_mt_server.fun -description: Documentation for http_mt_server.fun -permalink: /documentation/examples/net/http_mt_server/ -lang: en -tags: -- example -- http_mt_server -- network ---- - - -- Location: examples/net/http_mt_server.fun -- Category: Networking / HTTP (multi-threaded) - -Description -- Thread-per-connection HTTP server built on io/socket.fun and io/thread.fun. For each accepted client, spawns a thread and returns a small HTML page. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - ./build_debug/fun examples/net/http_mt_server.fun - - Then open http://127.0.0.1:8080/ (or the port printed on start) - -Requirements -- Uses stdlib io/socket.fun and io/thread.fun. No external extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/net/http_mt_server_cgi.md b/web/documentation/examples/net/http_mt_server_cgi.md deleted file mode 100644 index ac0123b..0000000 --- a/web/documentation/examples/net/http_mt_server_cgi.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_mt_server_cgi.fun -subtitle: Documentation for http_mt_server_cgi.fun -description: Documentation for http_mt_server_cgi.fun -permalink: /documentation/examples/net/http_mt_server_cgi/ -lang: en -tags: -- example -- http_mt_server_cgi -- network ---- - - -- Location: examples/net/http_mt_server_cgi.fun -- Category: Networking / HTTP with CGI (multi-threaded) - -Description -- Multi-threaded HTTP server (thread-per-connection) with CGI support. Serves static files from htdocs and executes .fun scripts as CGI using net/cgi.fun helpers. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted - - export FUN_HTDOCS="./examples/data/htdocs" # optional - - ./build_debug/fun examples/net/http_mt_server_cgi.fun - - Try: http://127.0.0.1:8080/ and /hello.fun?name=Fun, /info.fun - -Requirements -- Uses stdlib io/socket.fun, io/thread.fun, and net/cgi.fun. No external extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/net/http_server.md b/web/documentation/examples/net/http_server.md deleted file mode 100644 index cf51420..0000000 --- a/web/documentation/examples/net/http_server.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_server.fun -subtitle: Documentation for http_server.fun -description: Documentation for http_server.fun -permalink: /documentation/examples/net/http_server/ -lang: en -tags: -- example -- http_server -- network ---- - - -- Location: examples/net/http_server.fun -- Category: Networking / HTTP (blocking) - -Description -- Blocking HTTP server that serves static files and executes .fun CGI scripts via lib/net/http_server.fun. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - ./build_debug/fun examples/net/http_server.fun - - Default docroot: ./examples/data/htdocs - - Visit: http://127.0.0.1:8080/ - -Notes -- For CGI .fun under htdocs, the server uses the Fun interpreter to execute them and forwards output as HTTP. - -Requirements -- Uses io/socket.fun and strings.fun; no external extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/net/http_server_cgi.md b/web/documentation/examples/net/http_server_cgi.md deleted file mode 100644 index aad5159..0000000 --- a/web/documentation/examples/net/http_server_cgi.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_server_cgi.fun -subtitle: Documentation for http_server_cgi.fun -description: Documentation for http_server_cgi.fun -permalink: /documentation/examples/net/http_server_cgi/ -lang: en -tags: -- example -- http_server_cgi -- network ---- - - -- Location: examples/net/http_server_cgi.fun -- Category: Networking / HTTP with CGI (blocking) - -Description -- Minimal CGI-capable HTTP server (blocking) using lib/net/http_cgi_server.fun. Serves static files and executes .fun scripts as CGI. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted - - export FUN_HTDOCS="./examples/data/htdocs" # optional - - ./build_debug/fun examples/net/http_server_cgi.fun - - Try: http://127.0.0.1:8080/ and /hello.fun, /info.fun - -Requirements -- Uses stdlib io/socket.fun, strings.fun, and net/cgi.fun. No external extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/net/http_server_cgi_lib.md b/web/documentation/examples/net/http_server_cgi_lib.md deleted file mode 100644 index 63926f5..0000000 --- a/web/documentation/examples/net/http_server_cgi_lib.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_server_cgi_lib.fun -subtitle: Documentation for http_server_cgi_lib.fun -description: Documentation for http_server_cgi_lib.fun -permalink: /documentation/examples/net/http_server_cgi_lib/ -lang: en -tags: -- example -- http_server_cgi_lib -- network ---- - - -- Location: examples/net/http_server_cgi_lib.fun -- Category: Networking / HTTP with CGI (blocking, stdlib helpers) - -Description -- Blocking HTTP server that serves static files and runs .fun as CGI using helpers from lib/net/http_cgi_lib_server.fun and net/cgi.fun. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - export FUN_EXEC="./build_debug/fun" # optional; auto-detected if omitted - - export FUN_HTDOCS="./examples/data/htdocs" # optional - - ./build_debug/fun examples/net/http_server_cgi_lib.fun - - Try: http://127.0.0.1:8080/ and /hello.fun, /info.fun - -Requirements -- Uses stdlib io/socket.fun, strings.fun, net/cgi.fun. No external extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive) diff --git a/web/documentation/examples/net/http_static_server.md b/web/documentation/examples/net/http_static_server.md deleted file mode 100644 index c5e311d..0000000 --- a/web/documentation/examples/net/http_static_server.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - http_static_server.fun -subtitle: Documentation for http_static_server.fun -description: Documentation for http_static_server.fun -permalink: /documentation/examples/net/http_static_server/ -lang: en -tags: -- example -- http_static_server -- network ---- - - -- Location: examples/net/http_static_server.fun -- Category: Networking / Sockets - -Description -- Minimal static HTTP server implemented directly on sockets. Accepts connections and always returns a small HTML page. - -How to run -- From the repository root: - - export FUN_LIB_DIR="./lib" - - ./build_debug/fun examples/net/http_static_server.fun - - Then open http://127.0.0.1:8088/ - -Requirements -- Uses core IO/socket stdlib (io/socket.fun). No optional extensions required. - -See also -- documentation/examples/README.md -- documentation/examples/httpserver.md (deep-dive over HTTP servers) diff --git a/web/documentation/examples/net/httpserver.md b/web/documentation/examples/net/httpserver.md deleted file mode 100644 index 5b3ed6d..0000000 --- a/web/documentation/examples/net/httpserver.md +++ /dev/null @@ -1,155 +0,0 @@ ---- -layout: page -published: true -noToc: false -noComments: false -noDate: false -title: Fun - HTTP server examples: architecture and how they work -subtitle: Documentation for HTTP server examples, architecture and how they work -description: Documentation for HTTP server examples, architecture and how they work -permalink: /documentation/examples/net/httpserver/ -lang: en -tags: -- architecture -- example -- examples -- http -- network -- server -- they -- work ---- - - -This guide explains the HTTP server examples under `./examples/net/http_*` and the supporting standard library modules under `./lib/net/`. - -It covers what each example does, how to run it, and how the request handling/CGI pieces are implemented. - -## Prerequisites -- Build the project so you have a `fun` executable, or ensure `fun` is on your PATH. - - Typical local builds: `./build_debug/fun` or `./build_release/fun`. -- For examples that serve files/CGI scripts, content is read from `./examples/data/htdocs` by default. -- Helpful env vars used by some examples: - - `FUN_LIB_DIR` — path to the stdlib (`./lib` when running from the repo). - - `FUN_EXEC` — override path to the `fun` interpreter used to run CGI children. - - `FUN_HTDOCS` — override htdocs directory for some examples (not all). - - `FUN_PORT` — override port for some examples (mainly the MT CGI one). - -## Supporting stdlib modules (lib/net) - -- `net/http_server.fun` — Simple blocking HTTP server class serving static files, with a very small built-in “CGI for .fun files” (spawns `fun` with `QUERY_STRING`/`POST_DATA`). -- `net/http_cgi_server.fun` — Blocking server with fuller CGI support using `net/cgi.fun` to translate CGI output into proper HTTP responses and richer request/header parsing. -- `net/http_cgi_lib_server.fun` — Variant of the CGI server with the same core behavior, explicitly wiring the Fun interpreter path and using `CGI().cgi_to_http_response()` from `net/cgi.fun`. -- `net/cgi.fun` — Helpers to work with CGI-style programs and to translate CGI output (headers + body) into full HTTP/1.1 responses. - -See documentation/stdlib.md → net/ for a quick index of these modules. - -## Example: http_static_server.fun -- File: `examples/net/http_static_server.fun` -- Purpose: Minimal, hand-written HTTP server that ignores the request path and always responds with a fixed HTML page. -- Key includes: `io/socket.fun` -- Port/backlog: hard-coded `8088`, backlog 10. -- Flow: - - Creates `TcpServer(port, backlog)` → `listen()` → loop on `accept()` - - `sock_recv()` reads and discards request - - Constructs a literal HTTP/1.1 200 response with `Content-Length` and `Connection: close` - - Sends the response with `sock_send()` and closes the client -- Run: - - `./examples/net/http_static_server.fun` - - Open http://127.0.0.1:8080/ - -## Example: http_server.fun (static + simple .fun CGI) -- File: `examples/net/http_server.fun` -- Uses: `#include ` (class `HTTPServer`) -- Purpose: Blocking server that serves static files from an htdocs directory; if the requested path ends with `.fun`, it spawns `fun` to run the script and returns its output. -- Defaults in example: - - Port: `8080` - - Htdocs: `./examples/data/htdocs` -- Implementation highlights (see `lib/net/http_server.fun`): - - Parses request line to get `method` and `path`; `/` maps to `/index.html`. - - When path ends with `.fun`, builds a small environment: - - `QUERY_STRING` (for `?a=b`), `POST_DATA` (raw body when `POST`). - - Runs `proc_run(" fun