Finch/tests/shared.sh
Nexoniarz 68637a35a7 export fn and finch build --shared: libraries a C program loads (game scripts)
export fn name(...) is a C function by that name (numbers, bool, char, pointers in and out).
--shared builds lib<name>.so / <name>.dll with no main. finch_module_on_fatal(handler) lets the
host take runtime errors over (longjmp out) instead of the process exiting.
tests/shared.sh: a C host loads one, calls it and survives an index error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 02:14:09 +02:00

17 lines
656 B
Shell
Executable file

#!/bin/sh
# finch build --shared: a library a C program loads, calls by name, and that hands runtime
# errors to the host instead of exiting.
set -e
cd "$(dirname "$0")/shared"
FINCH=${FINCH:-../../build/finch}
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
"$FINCH" build mod.fch --shared -o "$tmp/libmod.so"
${CC:-cc} host.c -rdynamic -o "$tmp/host" -ldl
out=$("$tmp/host" "$tmp/libmod.so")
expected='add 42
even 1 0
host_print: hello Rakya
caught: mod.fch:17: runtime error: index 7 is out of range (the length is 3)
still alive'
if [ "$out" = "$expected" ]; then echo "shared library: passed"; else printf 'shared library: FAILED\n%s\n' "$out"; exit 1; fi