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
2026-04-21 01:04:39 +02:00
title: Running the Examples
2026-04-10 23:27:55 +02:00
subtitle: How to run the examples and the interactive showcase script, with environment tips.
description: How to run the examples and the interactive showcase script, with environment tips.
permalink: /documentation/examples/
lang: en
tags:
2026-04-11 00:18:36 +02:00
- environment
- example
- examples
- interactive
- run
- running
- script
- showcase
- tips
2026-04-10 23:27:55 +02:00
---
2026-02-11 17:34:24 +01:00
This page shows how to run the example programs included with the repository and how to use the interactive showcase script.
All commands assume you are in the repository root.
## Prerequisites
2026-06-06 18:52:16 +02:00
- Build the interpreter (see [handbook ](/documentation/handbook/ ). You’ ll have `build/fun` (paths may vary by your setup/IDE).
2026-02-11 17:34:24 +01:00
- Set FUN_LIB_DIR to the repo’ s lib directory when running without installation so `#include <...>` can find the standard library.
2026-06-06 18:52:16 +02:00
### Linux/macOS/BSD:
2026-02-11 17:34:24 +01:00
2026-06-06 18:52:16 +02:00
<pre>FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/include_lib.fun</pre>
2026-04-21 01:04:39 +02:00
2026-06-06 18:52:16 +02:00
### Windows (PowerShell):
2026-02-11 17:34:24 +01:00
2026-04-11 02:38:47 +02:00
<pre>$env:FUN_LIB_DIR = "$PWD/lib"
2026-04-21 01:04:39 +02:00
./build/fun.exe .\examples\include_lib.fun</pre>
2026-02-11 17:34:24 +01:00
## Interactive showcase: play.fun
2026-06-06 18:52:16 +02:00
The script `./scripts/play.fun` discovers all `.fun` files in `./examples` and offers to run them one by one:
2026-04-21 01:04:39 +02:00
<pre>./scripts/play.fun</pre>
2026-02-11 17:34:24 +01:00
Notes:
2026-04-21 01:04:39 +02:00
2026-02-11 17:34:24 +01:00
- The script auto-picks your interpreter (FUN_BIN env or `fun` in PATH) and ensures `FUN_LIB_DIR=./lib` so examples resolve includes correctly.
- It shows the exit code for each run and summarizes failures at the end.
Tip: you can run specific examples directly too:
2026-06-06 18:52:16 +02:00
<pre>FUN_LIB_DIR="$(pwd)/lib" ./build/fun ./examples/extensions/openssl/openssl_md5.fun</pre>
2026-04-21 01:04:39 +02:00
2026-02-11 17:34:24 +01:00
## Example categories
Browse the `examples/` tree for areas of interest:
2026-02-19 14:05:14 +01:00
- crypto — crypto demonstrations (e.g., OpenSSL MD5/SHA-256/SHA-512 helpers; requires build with `-DFUN_WITH_OPENSSL=ON` )
2026-02-11 17:34:24 +01:00
- blocking / interactive — I/O or user-interactive patterns
- error / broken — negative tests and error showcases
- math — numeric operations
- sqlited / data — data access and HTTP/CGI-style samples (platform dependent)
## Creating your own examples
Place your `.fun` files anywhere under `examples/` to have them picked up by `play.fun` . Use quoted includes for project-local helpers and angle brackets for stdlib modules:
2026-04-11 02:38:47 +02:00
<pre>#include "examples/my_lib/common.fun"
2026-04-21 01:04:39 +02:00
#include <io/console.fun></pre>
2026-02-11 17:34:24 +01:00
If you add an example showcasing a new feature, also consider adding a brief note to the relevant doc (types.md, includes.md, opcodes.md, etc.).
2026-06-06 18:52:16 +02:00