This commit is contained in:
2024-08-04 15:13:35 +03:00
parent b8baf276b6
commit c440275314
4 changed files with 57 additions and 1 deletions

View File

@@ -1,3 +1,3 @@
# go-bin-example # glib-example
Example binary module Example binary module

47
example.go Normal file
View File

@@ -0,0 +1,47 @@
package main
// compile: CGO_LDFLAGS_ALLOW=".*" CGO_ENABLED=1 go build -buildmode=c-shared
/*
#cgo LDFLAGS: "-Wl,--version-script=${SRCDIR}/script.exp"
int gmod13_open(void* L);
int gmod13_close(void* L);
int glib_test(void* L);
*/
import "C"
import (
"fmt"
"unsafe"
"code.gurenya.net/gmod/glib"
)
type State = unsafe.Pointer
//export glib_test
func glib_test(L State) C.int {
fmt.Println("Hello from glib_test function!")
return 0
}
//export gmod13_open
func gmod13_open(L State) C.int {
fmt.Println("Hello from binary module!")
glib.PushFunc(L, C.glib_test)
glib.SetGlobal(L, "glib_test")
return 0
}
//export gmod13_close
func gmod13_close(L State) C.int {
fmt.Println("Goodbye from binary module!")
return 0
}
func main() {}

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module code.gurenya.net/gmod/glib-example
go 1.22.2
require "code.gurenya.net/gmod/glib" v0.0.1

4
script.exp Normal file
View File

@@ -0,0 +1,4 @@
{
global: gmod13_open; gmod13_close;
local: *;
};