Skip to content

Commit

Permalink
Add libraries docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Dec 5, 2024
1 parent 2b82141 commit 5df6095
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/godot_docs/cppapi.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 11
sidebar_position: 12
---

# C++ API Reference
Expand Down
40 changes: 40 additions & 0 deletions docs/godot_docs/libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
sidebar_position: 11
---

# Program Libraries

Libraries make it easy to use pre-made programs in the sandbox.

```py
if !FileAccess.file_exists("res://luajit.elf"):
var buffer = Sandbox.download_program("luajit")
fa = FileAccess.open("res://luajit.elf", FileAccess.WRITE)
fa.store_buffer(buffer)
fa.close()

var luajit = Node.new()
luajit.set_script(load("res://luajit.elf"))

luajit.add_function("test", func(name): return "Test " + str(name) + " called!")
luajit.add_function("add", func(a, b): return a + b)

luajit.run("""
print(test(1))
print(add(333, 666))
function fib(n, acc, prev)
if (n < 1) then
return acc
else
return fib(n - 1, prev + acc, acc)
end
end
print("The 500th fibonacci number is " .. fib(500, 0, 1))
""")
```

## Godot Sandbox Programs

There is [a repository with pre-made programs](https://github.com/libriscv/godot-sandbox-programs).

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 comments on commit 5df6095

Please sign in to comment.