gohook/extern.go
htmk 11eee3201f Part 2 of making the lib async
- New event struct mimiking C structs
 - changed c channel library to eb_chan
 - changed API to something more palatable
2019-02-08 20:26:02 -02:00

38 lines
516 B
Go

package hook
/*
// #include "event/hook_async.h"
*/
import "C"
import (
"encoding/json"
"fmt"
"log"
"time"
)
//export go_send
func go_send(s *C.char) {
str := []byte(C.GoString(s))
fmt.Println(string(str))
out := Event{}
err := json.Unmarshal(str, &out)
if err != nil{
log.Fatal(err)
}
out.When = time.Now() //at least it's consistent
if err != nil {
log.Fatal(err)
}
//todo: maybe make non-bloking
ev <- out
}
////export go_sleep
//func go_sleep(){
//
// time.Sleep(time.Millisecond*50)
//}