3 ms·
Odin code: package main import "core:fmt" @export sayhi :: proc() { fmt.println("Hello World") } Key is the "@export" statement.
by dismalaf 1y ago
Odin code:
package main
import "core:fmt"
@export
sayhi :: proc() {
fmt.println("Hello World")
}
Key is the "@export" statement. Then build Linux dynamic library by doing "odin build main.odin -file -build-mode:shared". -file flag is since I'm just building a single Odin file, didn't set up a project structure or anything. -build-mode:shared is pretty obvious, there's separate build mode flags for Windows or Mac platforms (called "dll" and "dynamic" I think).
Ruby code:
require 'ffi'
module MyLib
extend FFI::Library
ffi_lib "./main.so"
attach_function :sayhi, [], :void
end
MyLib.sayhi
That's literally all there is to it. Odin lib is a single file. Ruby code is a single file. Don't even need a project setup since Odin can compile single files into programs or libraries and Ruby can of course link to a shared lib that's anywhere.
- Alifatisk 1y agoThank you so much, that was way easier than what I expected, amazing!