1
0
Fork 0
forked from fun/fun

Renamed ./examples/external to ./examples/extensions. No code changes. (0.40.6)

This commit is contained in:
Johannes Findeisen 2026-04-27 01:20:38 +02:00
commit c68244d6f6
32 changed files with 40 additions and 41 deletions

View file

@ -0,0 +1,58 @@
#!/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-11-30
*/
// Demonstration of the Ini stdlib class from lib/io/ini.fun
include <io/ini.fun>
ini = INI()
path = "./examples/data/complex.ini"
if (ini.load(path) == 0)
print("Failed to load " + path)
exit(1)
// Read a few values
app_name = ini.get_string("app", "name", "FunApp")
app_version = ini.get_string("app", "version", "0.0.0")
app_debug = ini.get_bool("app", "debug", 0)
db_host = ini.get_string("database", "host", "localhost")
db_port = ini.get_int("database", "port", 5432)
print("[app]")
print(" name=" + app_name)
print(" version=" + app_version)
print(" debug=" + to_string(app_debug))
print("[database]")
print(" host=" + db_host)
print(" port=" + to_string(db_port))
// Update a value and save back to the same file
ini.set("app", "debug", 1)
ok = ini.save(nil)
print("saved=" + to_string(ok))
ini.close()
/* Expected output:
[app]
name=FunApp
version=1.2.3
debug=1
[database]
host=localhost
port=5432
saved=1
*/

View file

@ -0,0 +1,99 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-11-30
*/
// Complex INI parsing example using iniparser 4.2.6 opcodes.
path = "./examples/data/complex.ini"
h = ini_load(path)
if h == 0
print("Failed to load "+path)
else
// app
app_name = ini_get_string(h, "app", "name", "FunApp")
app_version = ini_get_string(h, "app", "version", "0.0.0")
app_debug = ini_get_bool(h, "app", "debug", 0)
// database
db_host = ini_get_string(h, "database", "host", "localhost")
db_port = ini_get_int(h, "database", "port", 5432)
db_user = ini_get_string(h, "database", "user", "user")
db_pass = ini_get_string(h, "database", "pass", "")
db_pool = ini_get_int(h, "database", "pool_size", 4)
db_timeout = ini_get_double(h, "database", "timeout", 2.0)
// network
net_ssl = ini_get_bool(h, "network", "ssl", 0)
net_retries = ini_get_int(h, "network", "retries", 3)
base_url = ini_get_string(h, "network", "base_url", "")
// features
feature_x = ini_get_bool(h, "features", "feature_x", 0)
feature_y = ini_get_bool(h, "features", "feature_y", 0)
// paths
data_dir = ini_get_string(h, "paths", "data_dir", "./data")
log_file = ini_get_string(h, "paths", "log_file", "./logs/app.log")
// Print a structured summary
print("[app]")
print(" name=" + app_name)
print(" version=" + app_version)
print(" debug=" + to_string(app_debug))
print("[database]")
print(" host=" + db_host)
print(" port=" + to_string(db_port))
print(" user=" + db_user)
print(" pass=" + db_pass)
print(" pool_size=" + to_string(db_pool))
print(" timeout=" + to_string(db_timeout))
print("[network]")
print(" ssl=" + to_string(net_ssl))
print(" retries=" + to_string(net_retries))
print(" base_url=" + base_url)
print("[features]")
print(" feature_x=" + to_string(feature_x))
print(" feature_y=" + to_string(feature_y))
print("[paths]")
print(" data_dir=" + data_dir)
print(" log_file=" + log_file)
// Clean up
ini_free(h)
/* Expected output:
[app]
name=FunApp
version=1.2.3
debug=1
[database]
host=localhost
port=5432
user=fun
pass=secret
pool_size=8
timeout=2.5
[network]
ssl=1
retries=3
base_url=https://api.example.com
[features]
feature_x=1
feature_y=0
[paths]
data_dir=./data
log_file=./logs/app.log
*/

View file

@ -0,0 +1,43 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-11-30
*/
// Minimal demo for INI opcodes using iniparser 4.2.6
path = "./examples/data/complex.ini"
h = ini_load(path)
if h == 0
print("Failed to load " + path)
else
u = ini_get_string(h, "auth", "user", "guest")
r = ini_get_int(h, "network", "retries", 5)
s = ini_get_bool(h, "network", "ssl", 0)
print("user=" + u)
print("retries=" + to_string(r))
print("ssl=" + to_string(s))
ok = ini_set(h, "auth", "token", "abcd1234")
if ok
ini_save(h, path)
ini_free(h)
/* Expected output:
user=<EFBFBD><EFBFBD><EFBFBD><EFBFBD>U
retries=3
ssl=1
I wonder about the user= value when the default value is used!
It should look like:
user=guest
retries=3
ssl=1
*/

View file

@ -0,0 +1,50 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-02
*/
// Minimal diagnostic for INI lookups
path = "./examples/data/complex.ini"
h = ini_load(path)
print("h=" + to_string(h))
if h == 0
print("Failed to load: " + path)
else
print("[try app:name]")
v1 = ini_get_string(h, "app", "name", "<def>")
print("app:name => " + v1)
print("[try app:version]")
v2 = ini_get_string(h, "app", "version", "<def>")
print("app:version => " + v2)
print("[try database:port]")
v3 = ini_get_int(h, "database", "port", -1)
print("database:port => " + to_string(v3))
print("[try network:ssl]")
v4 = ini_get_bool(h, "network", "ssl", -9)
print("network:ssl => " + to_string(v4))
ini_free(h)
/* Expected output:
h=1
[try app:name]
app:name => FunApp
[try app:version]
app:version => 1.2.3
[try database:port]
database:port => 5432
[try network:ssl]
network:ssl => 1
*/

View file

@ -0,0 +1,93 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-11-30
*/
// Demonstration of INI subsections like [section.subsection]
// Uses iniparser 4.2.6 via Fun's ini_* opcodes
path = "./examples/data/subsections.ini"
h = ini_load(path)
if h == 0
print("Failed to load "+path)
else
// Top-level server
srv_host = ini_get_string(h, "server", "host", "localhost")
srv_port = ini_get_int(h, "server", "port", 80)
// Subsection: server.tls
tls_enabled = ini_get_bool(h, "server.tls", "enabled", 0)
tls_version = ini_get_double(h, "server.tls", "version", 1.2)
tls_ciphers = ini_get_string(h, "server.tls", "ciphers", "")
// Subsections: users.*
admin_name = ini_get_string(h, "users.admin", "name", "admin")
admin_active = ini_get_bool(h, "users.admin", "active", 1)
admin_quota = ini_get_int(h, "users.admin", "quota_gb", 10)
guest_name = ini_get_string(h, "users.guest", "name", "guest")
guest_active = ini_get_bool(h, "users.guest", "active", 0)
guest_quota = ini_get_int(h, "users.guest", "quota_gb", 1)
// Subsection: paths.logs
logs_dir = ini_get_string(h, "paths.logs", "dir", "./logs")
logs_rotate = ini_get_bool(h, "paths.logs", "rotate", 0)
logs_max_files = ini_get_int(h, "paths.logs", "max_files", 5)
// Print
print("[server]")
print(" host=" + srv_host)
print(" port=" + to_string(srv_port))
print("[server.tls]")
print(" enabled=" + to_string(tls_enabled))
print(" version=" + to_string(tls_version))
print(" ciphers=" + tls_ciphers)
print("[users.admin]")
print(" name=" + admin_name)
print(" active=" + to_string(admin_active))
print(" quota_gb=" + to_string(admin_quota))
print("[users.guest]")
print(" name=" + guest_name)
print(" active=" + to_string(guest_active))
print(" quota_gb=" + to_string(guest_quota))
print("[paths.logs]")
print(" dir=" + logs_dir)
print(" rotate=" + to_string(logs_rotate))
print(" max_files=" + to_string(logs_max_files))
ini_free(h)
/* Expected output:
[server]
host=example.org
port=8080
[server.tls]
enabled=1
version=1.3
ciphers=TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256
[users.admin]
name=alice
active=1
quota_gb=100
[users.guest]
name=bob
active=0
quota_gb=5
[paths.logs]
dir=./var/log/fun
rotate=1
max_files=7
*/