raylib bindings started

This commit is contained in:
nub31
2025-09-28 19:43:25 +02:00
parent 4bd9a64e67
commit ef8c542bd6
4 changed files with 1515 additions and 55 deletions

View File

@@ -1,19 +1,17 @@
import "core"
import "raylib"
module "main"
struct Human
{
name: cstring
}
extern "main" func main(args: []cstring): i64
{
let x: core::ref<Human> = {}
test(x)
return 0
}
raylib::InitWindow(1600, 900, "Hi from nub-lang")
func test(x: core::ref<Human>)
{
while !raylib::WindowShouldClose()
{
raylib::BeginDrawing()
raylib::EndDrawing()
}
return 0
}

1502
example/src/raylib.nub Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,40 +0,0 @@
module "core"
extern "puts" func puts(text: cstring)
extern "malloc" func malloc(size: u64): ^void
extern "free" func free(address: ^void)
export struct ref<T>
{
value: ^T
count: ^u64
@oncreate
func on_create()
{
puts("on_create")
this.value = @interpret(^T, malloc(@size(T)))
this.count = @interpret(^u64, malloc(@size(u64)))
this.count^ = 1
}
@oncopy
func on_copy()
{
puts("on_copy")
this.count^ = this.count^ + 1
}
@ondestroy
func on_destroy()
{
puts("on_destroy")
this.count^ = this.count^ - 1
if this.count^ <= 0
{
puts("free")
free(@interpret(^void, this.value))
free(@interpret(^void, this.count))
}
}
}