package main

import (
	"fmt"
	"github.com/ebitengine/purego"
	"os"
	// "unsafe"
)

func main() {
	// 加载动态链接库
	lib, err := purego.Dlopen("/home/kingecg/code/gosh/libgosh.so", purego.RTLD_NOW)
	if err != nil {
		fmt.Printf("无法加载动态链接库: %v\n", err)
		os.Exit(1)
	}

	// 定义函数签名
	var (
		Add      func(int, int) int
		Subtract func(int, int) int
		Multiply func(int, int) int
		Divide   func(int, int) int
	)

	// 注册函数
	purego.RegisterLibFunc(&Add, lib, "Add")
	purego.RegisterLibFunc(&Subtract, lib, "Subtract")
	purego.RegisterLibFunc(&Multiply, lib, "Multiply")
	purego.RegisterLibFunc(&Divide, lib, "Divide")

	// 调用函数并打印结果
	a, b := 10, 5
	fmt.Printf("Add(%d, %d) = %d\n", a, b, Add(a, b))
	fmt.Printf("Subtract(%d, %d) = %d\n", a, b, Subtract(a, b))
	fmt.Printf("Multiply(%d, %d) = %d\n", a, b, Multiply(a, b))
	fmt.Printf("Divide(%d, %d) = %d\n", a, b, Divide(a, b))
}
