Added basic local includes relative to $PWD and includes for files located at /usr/lib/fun.
This commit is contained in:
parent
d25c4b616d
commit
5b7b063086
8 changed files with 356 additions and 6 deletions
24
examples/include_lib.fun
Normal file
24
examples/include_lib.fun
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://hanez.org/project/fun/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the ISC license.
|
||||
* https://opensource.org/license/isc-license-txt
|
||||
*/
|
||||
|
||||
// Demonstrates system library includes after installation to /usr/lib/fun
|
||||
|
||||
include <hello.fun>
|
||||
include <utils/math.fun>
|
||||
|
||||
print("== include lib demo ==")
|
||||
hello_lib()
|
||||
|
||||
number x = 10
|
||||
number y = 32
|
||||
|
||||
print("add(" + to_string(x) + ", " + to_string(y) + ") = " + to_string(add(x, y)))
|
||||
print("times(" + to_string(x) + ", " + to_string(y) + ") = " + to_string(times(x, y)))
|
||||
29
examples/include_local.fun
Normal file
29
examples/include_local.fun
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://hanez.org/project/fun/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the ISC license.
|
||||
* https://opensource.org/license/isc-license-txt
|
||||
*/
|
||||
|
||||
// To test this you need to go to ./examples/ and test includes running ../build/fun include_local.fun
|
||||
// Local includes are always relative from the $PWD.
|
||||
|
||||
// Demonstrates local include:
|
||||
// This resolves relative to the current working directory where 'fun' is executed.
|
||||
#include "include_local_util.fun"
|
||||
|
||||
print("== include local demo ==")
|
||||
greet("Fun")
|
||||
|
||||
number a = 2
|
||||
number b = 3
|
||||
print("sum(" + to_string(a) + ", " + to_string(b) + ") = " + to_string(sum(a, b)))
|
||||
|
||||
// Tip:
|
||||
// To include from the system library directory (/usr/lib/fun), use angle brackets:
|
||||
// #include <some_lib.fun>
|
||||
|
||||
16
examples/include_local_util.fun
Normal file
16
examples/include_local_util.fun
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://hanez.org/project/fun/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the ISC license.
|
||||
* https://opensource.org/license/isc-license-txt
|
||||
*/
|
||||
|
||||
// Simple utility module to be included locally with: #include "include_local_util.fun"
|
||||
|
||||
fun greet(name)
|
||||
print("Hello, " + name)
|
||||
|
||||
fun sum(a, b)
|
||||
return a + b
|
||||
Loading…
Add table
Add a link
Reference in a new issue