Documentation content fixes. No code changes. (0.40.5)
This commit is contained in:
parent
b598521704
commit
0b6c0e9a61
1 changed files with 17 additions and 14 deletions
|
|
@ -4,7 +4,7 @@ published: true
|
||||||
noToc: false
|
noToc: false
|
||||||
noComments: false
|
noComments: false
|
||||||
noDate: false
|
noDate: false
|
||||||
title: Fun - Includes in Fun, local vs. system and the FUN_LIB_DIR environment variable
|
title: Includes, local vs. system and the FUN_LIB_DIR environment variable
|
||||||
subtitle: Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`.
|
subtitle: Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`.
|
||||||
description: Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`.
|
description: Using local vs. system includes, FUN_LIB_DIR, DEFAULT_LIB_DIR, and namespaced includes with `as`.
|
||||||
permalink: /documentation/includes/
|
permalink: /documentation/includes/
|
||||||
|
|
@ -18,6 +18,7 @@ tags:
|
||||||
- namespaced
|
- namespaced
|
||||||
- system
|
- system
|
||||||
- variable
|
- variable
|
||||||
|
- stdlib
|
||||||
---
|
---
|
||||||
|
|
||||||
This document explains how to use local and system includes in Fun source files and how `FUN_LIB_DIR` controls where system includes are resolved from. It also covers namespaced includes with `as`.
|
This document explains how to use local and system includes in Fun source files and how `FUN_LIB_DIR` controls where system includes are resolved from. It also covers namespaced includes with `as`.
|
||||||
|
|
@ -26,11 +27,11 @@ This document explains how to use local and system includes in Fun source files
|
||||||
|
|
||||||
- Local includes: `#include "relative/path/to/file.fun"`
|
- Local includes: `#include "relative/path/to/file.fun"`
|
||||||
- Resolved relative to the current working directory (`$PWD`) where you run `fun`.
|
- Resolved relative to the current working directory (`$PWD`) where you run `fun`.
|
||||||
- System includes: `#include <path/inside/stdlib.fun>`
|
- System includes: `#include <path/inside/stdlib.fun>;`
|
||||||
- Resolved using:
|
- Resolved using:
|
||||||
1) `FUN_LIB_DIR` (if set)
|
-`FUN_LIB_DIR` (if set)
|
||||||
2) `DEFAULT_LIB_DIR` (compile-time default; typically `/usr/share/fun/lib/` after install)
|
- `DEFAULT_LIB_DIR` (compile-time default; typically `/usr/share/fun/lib/` after install)
|
||||||
3) Fallback to `lib/` under the current working directory (developer convenience)
|
- Fallback to `lib/` under the current working directory (developer convenience)
|
||||||
- Optional namespacing: `#include <...> as ns` or `#include "..." as ns`
|
- Optional namespacing: `#include <...> as ns` or `#include "..." as ns`
|
||||||
|
|
||||||
## Local includes (quoted)
|
## Local includes (quoted)
|
||||||
|
|
@ -38,6 +39,7 @@ This document explains how to use local and system includes in Fun source files
|
||||||
Use double quotes to include files relative to the directory you execute `fun` from.
|
Use double quotes to include files relative to the directory you execute `fun` from.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
<pre>#include "examples/include_local_util.fun"
|
<pre>#include "examples/include_local_util.fun"
|
||||||
|
|
||||||
print("== include local demo ==")
|
print("== include local demo ==")
|
||||||
|
|
@ -55,8 +57,9 @@ print("sum(" + to_string(a) + ", " + to_string(b) + ") = " + to_string(sum(a, b)
|
||||||
Use angle brackets to include modules from the Fun standard library or any library directory you point `FUN_LIB_DIR` to.
|
Use angle brackets to include modules from the Fun standard library or any library directory you point `FUN_LIB_DIR` to.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
<pre>#include <hello.fun>
|
|
||||||
#include <utils/math.fun>
|
<pre>#include <hello.fun>
|
||||||
|
#include <utils/math.fun>
|
||||||
|
|
||||||
print("== include lib demo ==")
|
print("== include lib demo ==")
|
||||||
hello_lib()
|
hello_lib()
|
||||||
|
|
@ -68,9 +71,9 @@ print("times(" + to_string(x) + ", " + to_string(y) + ") = " + to_string(times(x
|
||||||
|
|
||||||
Resolution order for `#include <...>`:
|
Resolution order for `#include <...>`:
|
||||||
|
|
||||||
1) `FUN_LIB_DIR` (environment variable), with automatic handling of trailing `/` or `\`
|
- `FUN_LIB_DIR` (environment variable), with automatic handling of trailing `/` or `\`
|
||||||
2) `DEFAULT_LIB_DIR` (compile-time define)
|
- `DEFAULT_LIB_DIR` (compile-time define)
|
||||||
3) `lib/` under the current working directory (developer fallback)
|
- `lib/` under the current working directory (developer fallback)
|
||||||
|
|
||||||
If the file cannot be read from any location, an "Include error" is printed with the last attempted path.
|
If the file cannot be read from any location, an "Include error" is printed with the last attempted path.
|
||||||
|
|
||||||
|
|
@ -79,8 +82,9 @@ If the file cannot be read from any location, an "Include error" is printed with
|
||||||
You can import a module into a namespace to avoid symbol collisions or to make intent explicit.
|
You can import a module into a namespace to avoid symbol collisions or to make intent explicit.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
<pre>// Import stdlib helpers under alias 'm'
|
<pre>// Import stdlib helpers under alias 'm'
|
||||||
#include <utils/math.fun> as m
|
#include <utils/math.fun> as m
|
||||||
print("m.add(2, 3) = " + to_string(m.add(2, 3)))
|
print("m.add(2, 3) = " + to_string(m.add(2, 3)))
|
||||||
print("m.times(4, 5) = " + to_string(m.times(4, 5)))
|
print("m.times(4, 5) = " + to_string(m.times(4, 5)))
|
||||||
|
|
||||||
|
|
@ -139,7 +143,7 @@ Tips:
|
||||||
- Error: `Include error: cannot read '...'`
|
- Error: `Include error: cannot read '...'`
|
||||||
- Check if the path exists in the intended location:
|
- Check if the path exists in the intended location:
|
||||||
- For `"..."`: is the path correct relative to your current working directory?
|
- For `"..."`: is the path correct relative to your current working directory?
|
||||||
- For `<...>`: does the file exist under `FUN_LIB_DIR/<...>` or `DEFAULT_LIB_DIR/<...>` or `./lib/<...>`?
|
- For `<...>`: does the file exist under `FUN_LIB_DIR/<...>;` or `DEFAULT_LIB_DIR/<...>` or `./lib/<...>`?
|
||||||
- Ensure `FUN_LIB_DIR` is exported in the same shell session where you run `fun`.
|
- Ensure `FUN_LIB_DIR` is exported in the same shell session where you run `fun`.
|
||||||
- On Windows, verify you used the correct syntax for setting environment variables in CMD vs. PowerShell.
|
- On Windows, verify you used the correct syntax for setting environment variables in CMD vs. PowerShell.
|
||||||
|
|
||||||
|
|
@ -148,5 +152,4 @@ Tips:
|
||||||
- Examples in this repository:
|
- Examples in this repository:
|
||||||
- `examples/include_local.fun`
|
- `examples/include_local.fun`
|
||||||
- `examples/include_lib.fun`
|
- `examples/include_lib.fun`
|
||||||
- `examples/include_namespace.fun`
|
- [REPL Guide](../repl/) (explains completion that also scans `FUN_LIB_DIR`)
|
||||||
- REPL notes: `documentation/repl.md` (explains completion that also scans `FUN_LIB_DIR`)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue