feat: call rust ffi from go
This commit is contained in:
29
call-from-go.go
Normal file
29
call-from-go.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
)
|
||||
|
||||
func main() {
|
||||
libPath := "target/debug/librust_ffi_from_go.dylib"
|
||||
|
||||
arcjetlib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
|
||||
|
||||
if err != nil {
|
||||
// Handle error
|
||||
panic("load dylib error")
|
||||
}
|
||||
|
||||
defer purego.Dlclose(arcjetlib)
|
||||
|
||||
// Register the function
|
||||
var launch func(string) string
|
||||
purego.RegisterLibFunc(&launch, arcjetlib, "arcjet_launch")
|
||||
|
||||
result := launch("hatter")
|
||||
|
||||
fmt.Println("result: ", result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user