Skip to content

Commit 5df6095

Browse files
committed
Add libraries docs
1 parent 2b82141 commit 5df6095

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/godot_docs/cppapi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 11
2+
sidebar_position: 12
33
---
44

55
# C++ API Reference

docs/godot_docs/libraries.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
sidebar_position: 11
3+
---
4+
5+
# Program Libraries
6+
7+
Libraries make it easy to use pre-made programs in the sandbox.
8+
9+
```py
10+
if !FileAccess.file_exists("res://luajit.elf"):
11+
var buffer = Sandbox.download_program("luajit")
12+
fa = FileAccess.open("res://luajit.elf", FileAccess.WRITE)
13+
fa.store_buffer(buffer)
14+
fa.close()
15+
16+
var luajit = Node.new()
17+
luajit.set_script(load("res://luajit.elf"))
18+
19+
luajit.add_function("test", func(name): return "Test " + str(name) + " called!")
20+
luajit.add_function("add", func(a, b): return a + b)
21+
22+
luajit.run("""
23+
print(test(1))
24+
print(add(333, 666))
25+
function fib(n, acc, prev)
26+
if (n < 1) then
27+
return acc
28+
else
29+
return fib(n - 1, prev + acc, acc)
30+
end
31+
end
32+
print("The 500th fibonacci number is " .. fib(500, 0, 1))
33+
""")
34+
```
35+
36+
## Godot Sandbox Programs
37+
38+
There is [a repository with pre-made programs](https://github.com/libriscv/godot-sandbox-programs).
39+
40+
You can find [the latest release here](https://github.com/libriscv/godot-sandbox-programs/releases/latest). The latest release is used by `Sandbox.download_program(name)`.

0 commit comments

Comments
 (0)