38 lines
820 B
Go
38 lines
820 B
Go
|
|
package dart_bridge
|
||
|
|
|
||
|
|
/*
|
||
|
|
#include "stdint.h"
|
||
|
|
#include "include/dart_api_dl.h"
|
||
|
|
#include "include/dart_api_dl.c"
|
||
|
|
#include "include/dart_native_api.h"
|
||
|
|
|
||
|
|
bool GoDart_PostCObject(Dart_Port_DL port, Dart_CObject* obj) {
|
||
|
|
return Dart_PostCObject_DL(port, obj);
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
import "C"
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"unsafe"
|
||
|
|
)
|
||
|
|
|
||
|
|
func InitDartApi(api unsafe.Pointer) {
|
||
|
|
if C.Dart_InitializeApiDL(api) != 0 {
|
||
|
|
panic("failed to create dart bridge")
|
||
|
|
} else {
|
||
|
|
fmt.Println("Dart Api DL is initialized")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func sendToPort(port int64, msg string) {
|
||
|
|
var obj C.Dart_CObject
|
||
|
|
obj._type = C.Dart_CObject_kString
|
||
|
|
msgString := C.CString(msg)
|
||
|
|
ptr := unsafe.Pointer(&obj.value[0])
|
||
|
|
*(**C.char)(ptr) = msgString
|
||
|
|
isSuccess := C.GoDart_PostCObject(C.Dart_Port_DL(port), &obj)
|
||
|
|
if !isSuccess {
|
||
|
|
fmt.Println("ERROR: post to port ", port, " failed", msg)
|
||
|
|
}
|
||
|
|
}
|