1
0
Fork 0
forked from fun/fun

Tons of INI parser fixes to realy make it work. (0.37.40)

This commit is contained in:
Johannes Findeisen 2026-01-02 23:20:09 +01:00
commit d9372ce874
15 changed files with 264 additions and 66 deletions

View file

@ -1,32 +1,29 @@
[auth]
user = "hanez"
token = "abcd1234"
[app]
name = "FunApp"
version = "1.2.3"
debug = "1"
name = "FunApp"
version = "1.2.3"
debug = "1"
[database]
host = "localhost"
port = "5432"
user = "fun"
pass = "secret"
pool_size = "8"
timeout = "2.5"
host = "localhost"
port = "5432"
user = "fun"
pass = "secret"
pool_size = "8"
timeout = "2.5"
[network]
ssl = "yes"
retries = "3"
base_url = "https://api.example.com"
ssl = "yes"
retries = "3"
base_url = "https://api.example.com"
[features]
feature_x = "on"
feature_y = "off"
feature_x = "on"
feature_y = "off"
[paths]
data_dir = "./data"
log_file = "./logs/app.log"
data_dir = "./data"
log_file = "./logs/app.log"

View file

@ -91,7 +91,7 @@ else
retries=3
base_url=https://api.example.com
[features]
feature_x=0
feature_x=1
feature_y=0
[paths]
data_dir=./data

View file

@ -19,7 +19,7 @@ if h == 0
print("Failed to load " + path)
else
u = ini_get_string(h, "auth", "user", "guest")
r = ini_get_int(h, "network", "retries", 3)
r = ini_get_int(h, "network", "retries", 5)
s = ini_get_bool(h, "network", "ssl", 0)
print("user=" + u)
print("retries=" + to_string(r))
@ -33,4 +33,11 @@ else
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
*/

50
examples/ini_diag.fun Normal file
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
*/