fix(runtime): Random.* in any program; value_* called directly brings the value tree

The seeded random numbers lived in the ECS runtime, so a tool or a
program of test blocks got "unknown function rng_range". They are
runtime/native/rng.ludic now, spliced on Random.* or a bare rng_*/seed
call nobody defines, and imported by core.ludic for a game. A bare
value_*/json_* call nothing in the program defines splices the value
tree the way Value.* does. Reseed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 04:59:48 +03:00
parent bf73f7edaf
commit f5e7fe4245
13 changed files with 52262 additions and 51500 deletions

View file

@ -0,0 +1,19 @@
# random_plain.ludic — Random.* in a program with no properties or handlers: the seeded random
# numbers are spliced on their own, and a helper may call rng_range directly. The same seed gives
# the same draws.
#
# Running it prints: 1 1 1
program RandomPlain {
function roll() -> int {
return rng_range(1, 6)
}
entry {
Random.seed(7)
let a = Random.range(1, 6)
let b = roll()
Random.seed(7)
let c = Random.range(1, 6)
let d = roll()
print(`{a == c} {b == d} {a >= 1 and a <= 6}`)
}
}

View file

@ -0,0 +1,12 @@
# testing_random.ludic — a program made only of test blocks has the runtime's namespaces too:
# Random.range through a helper. Its runner prints:
# == 1 passed, 0 failed ==
program TestingRandom {
function roll() -> int {
return Random.range(1, 6)
}
test "a roll is a die's" {
let r = roll()
expect(r >= 1 and r <= 6)
}
}

View file

@ -0,0 +1,11 @@
# value_direct.ludic — the value tree is spliced when a program calls value_* / json_* itself,
# as a package does, not only when it writes Value.* or Json.*.
#
# Running it prints: {"fish":3} 3
program ValueDirect {
entry {
let o = value_object()
value_put(o, "fish", value_int(3))
print(`{json_encode(o)} {value_as_int(value_get(o, "fish"))}`)
}
}