Fix export & handle unsafe.pointer types

This commit is contained in:
Andrea Maria Piana 2020-06-02 17:30:19 +02:00
parent b8d64cbb1e
commit de698e64a3
2 changed files with 7 additions and 6 deletions

View File

@ -2,15 +2,14 @@ package main
const prelude = `package main const prelude = `package main
// #include <stdlib.h> // #include <stdlib.h>
import ( import "C"
"C" import "unsafe"
mobile "github.com/status-im/status-go/mobile" import mobile "github.com/status-im/status-go/mobile"
)
func main() {} func main() {}
` `
const intType = "int" const intType = "int"
const stringType = "string" const stringType = "string"
const unsafePointerType = "unsafe.Pointer" const unsafePointerType = "&{unsafe Pointer}"
const boolType = "bool" const boolType = "bool"

View File

@ -41,7 +41,7 @@ func handleFunction(name string, funcDecl *ast.FuncDecl) string {
results := funcDecl.Type.Results results := funcDecl.Type.Results
// add export tag // add export tag
output := fmt.Sprintf("// export %s\n", name) output := fmt.Sprintf("//export %s\n", name)
// add initial func declaration // add initial func declaration
output += fmt.Sprintf("func %s (", name) output += fmt.Sprintf("func %s (", name)
@ -56,6 +56,8 @@ func handleFunction(name string, funcDecl *ast.FuncDecl) string {
output += paramIdentity.Name output += paramIdentity.Name
typeString := fmt.Sprint(paramIdentity.Obj.Decl.(*ast.Field).Type) typeString := fmt.Sprint(paramIdentity.Obj.Decl.(*ast.Field).Type)
// We match against the stringified type,
// could not find a better way to match this
switch typeString { switch typeString {
case stringType: case stringType:
output += " *C.char" output += " *C.char"