-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
sidebar_position: 11 | ||
sidebar_position: 12 | ||
--- | ||
|
||
# C++ API Reference | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)`. |