github.com/notti/nocgo@v0.0.0-20190619201224-fc443047424c/steps/3_goffi/prog/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"unsafe"
     7  
     8  	"github.com/notti/go-dynamic/steps/3_goffi/ffi"
     9  )
    10  
    11  var puts__dynload uintptr
    12  var test_call__dynload uintptr
    13  
    14  type putsString struct {
    15  	s   []byte
    16  	num int `ffi:"ret"`
    17  }
    18  
    19  type testCall struct {
    20  	i1  uint16
    21  	i2  int
    22  	f1  float32
    23  	f2  float64
    24  	i3  int
    25  	i4  int
    26  	i5  int
    27  	i6  int
    28  	i7  int
    29  	i8  int
    30  	i9  int16
    31  	ret int `ffi:"ret"`
    32  }
    33  
    34  func main() {
    35  	fmt.Println(os.Args) // check if startup works
    36  
    37  	str := "hello world"
    38  	b := append([]byte(str), 0)
    39  
    40  	argsP := &putsString{s: b}
    41  	specP := ffi.MakeSpec(puts__dynload, argsP)
    42  
    43  	fmt.Println(argsP, specP)
    44  	specP.Call(unsafe.Pointer(argsP))
    45  	fmt.Println(argsP)
    46  
    47  	argsT := &testCall{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, 12}
    48  	specT := ffi.MakeSpec(test_call__dynload, argsT)
    49  
    50  	fmt.Println(argsT, specT)
    51  	specT.Call(unsafe.Pointer(argsT))
    52  	fmt.Println(argsT)
    53  }