2026-04-10 23:27:55 +02:00
---
layout: page
published: true
2026-04-11 00:18:36 +02:00
noToc: false
2026-04-10 23:27:55 +02:00
noComments: false
noDate: false
title: Fun - Fun executable: full usage guide
subtitle: Full usage guide for the `fun` executable, invocation patterns, REPL, env vars, include paths, examples, and install locations.
description: Full usage guide for the `fun` executable, invocation patterns, REPL, env vars, include paths, examples, and install locations.
permalink: /documentation/fun/
lang: en
tags:
2026-04-11 00:18:36 +02:00
- env
- examples
- executable
- full
- include
- install
- invocation
- locations
- paths
- patterns
- vars
2026-04-10 23:27:55 +02:00
---
2026-03-18 21:39:15 +01:00
This document explains how to use the `fun` binary after building or installing it: invocation patterns, options, environment variables, include/search paths, REPL, and examples.
## Synopsis
2026-04-11 02:38:47 +02:00
<pre>fun [options] [<script.fun>] [-- args...]
</pre>
2026-03-18 21:39:15 +01:00
- If `<script.fun>` is provided, `fun` runs the script.
- If omitted and the build enables the REPL, `fun` starts an interactive session.
## Options
- `-i` , `--repl` — start the interactive REPL explicitly (if built with REPL support)
- `-v` , `--version` — print version and exit
- `-h` , `--help` — show usage info and exit
Notes:
- Available options may vary by build configuration. Always check `fun --help` for your binary.
## Exit codes
- `0` — success
- non‑ zero — error during parse, compile, or runtime
## Standard library and includes
`fun` searches for modules included from `.fun` code in these locations:
1. The path provided by the environment variable `FUN_LIB_DIR` (highest precedence)
2. The compiled‑ in default `DEFAULT_LIB_DIR` (configured during build/install)
Tips:
- When running from the repository without installing, set `FUN_LIB_DIR` to the local `./lib` directory so examples can find the stdlib.
2026-04-10 23:27:55 +02:00
- See also: `documentation/includes.md` for namespacing (`include ... as ...` ) and search order details.
2026-03-18 21:39:15 +01:00
## REPL
If interactive mode is enabled at build time, starting `fun` with `-i` (or without a script) opens the REPL.
Useful commands/patterns in REPL:
- Enter expressions and statements directly.
- Use arrow keys/history for editing (availability depends on build flags).
2026-04-10 23:27:55 +02:00
- See `documentation/repl.md` for details and tips.
2026-03-18 21:39:15 +01:00
## Running scripts
Basic run (installed system‑ wide):
2026-04-11 02:38:47 +02:00
<pre>fun /usr/share/fun/examples/hello.fun
</pre>
2026-03-18 21:39:15 +01:00
Running from a build tree (not installed):
2026-04-11 02:38:47 +02:00
<pre>FUN_LIB_DIR=./lib /path/to/build_dir/fun examples/hello.fun
</pre>
2026-03-18 21:39:15 +01:00
Passing arguments to scripts (arguments after `--` are forwarded to the script environment):
2026-04-11 02:38:47 +02:00
<pre>fun myscript.fun -- arg1 arg2
</pre>
2026-03-18 21:39:15 +01:00
## Build and install locations
- Build targets: `fun` is produced by the `fun` target. In CLion/CMake, typical build directories are `build_debug` or `build_release` .
- Install locations (by default):
- Binary: `/usr/bin/fun`
- Stdlib: `/usr/share/fun/lib`
- Examples (optional): `/usr/share/fun/examples`
To stage an install without touching the system:
2026-04-11 02:38:47 +02:00
<pre>DESTDIR=./tmp/stage cmake --build <build_dir> --target install
2026-03-18 21:39:15 +01:00
./tmp/stage/usr/bin/fun ./examples/hello.fun
2026-04-11 02:38:47 +02:00
</pre>
2026-03-18 21:39:15 +01:00
## See also
2026-04-10 23:27:55 +02:00
- `documentation/cli.md` — concise CLI reference (synopsis/options/exit codes)
- `documentation/funstx.md` — syntax checker for `.fun` files with optional `--fix`
- `documentation/examples.md` — how to run the bundled examples
- `documentation/includes.md` — include paths, namespacing, and `FUN_LIB_DIR`