Exemplo n.º 1
0
// interfaceToDynamic - limited runtime conversion of Go->Haxe types
// TODO consider making public
func interfaceToDynamic(a interface{}) uintptr {
	//fmt.Printf("DEBUG interfaceToDynamic a= %v:%T\n", a, a)
	if a == nil {
		return hx.Null()
	}
	switch a.(type) {
	case []interface{}:
		//println("DEBUG []interface{}")
		ret := hx.New("", "Array<Dynamic>", 0)
		for _, aa := range a.([]interface{}) {
			//fmt.Printf("DEBUG aa= %v:%T\n", aa, aa)
			val := interfaceToDynamic(aa)
			//fmt.Println("DEBUG val=" + hx.CallString("", "Std.string", 1, val))
			hx.Code("", "_a.param(0).val.push(_a.param(1).val);", ret, val)
		}
		return ret
	case bool, string, int, float64:
		return hx.CodeDynamic("", "_a.param(0).val;", a)
	case []byte:
		return hx.CodeDynamic("", "Slice.toBytes(cast(_a.param(0).val,Slice));", a)
	default:
		panic("Unhandled Go interface{} to Haxe Dynamic: " + hx.CallString("", "Std.string", 1, a))
	}
	return hx.Null()
}
Exemplo n.º 2
0
func getUrl(url string, urc chan urlReply) urlReply {
	httpHandler := hx.New("", "haxe.Http", 1, url)
	hx.Code("", "_a.param(0).val.onData=_a.param(1).val;", httpHandler, hx.CallbackFunc(
		func(data string) {
			urc <- urlReply{err: nil, dat: data}
		}))
	hx.Code("", "_a.param(0).val.onError=_a.param(1).val;", httpHandler, hx.CallbackFunc(
		func(msg string) {
			urc <- urlReply{err: errors.New(msg), dat: ""}
		}))
	hx.Meth("", httpHandler, "haxe.Http", "request", 0)
	return <-urc
}
Exemplo n.º 3
0
// Main allows code that might be targeted to broser-based JS code to schedule TARDISgo code periodically, separate from call-backs.
// For non-JS targets it simply calls the given mainFN.
// This should be the last function called in main.main()
func BrowserMain(mainFN func(), msInvocationInterval, runLimit int) {
	if runtime.GOARCH == "js" { // probably only want to do this in a browser
		JScallbackOK = true
		ht := hx.New("js", "haxe.Timer", 1, msInvocationInterval)
		go func() { // put the main program into a goroutine
			mainFN()
			hx.Meth("js", ht, "haxe.Timer", "stop", 0)
		}()
		hx.SetInt("js", "Scheduler.runLimit", runLimit)
		hx.Code("js", "_a.param(0).val.run=Scheduler.timerEventHandler;", ht)
	} else {
		mainFN()
	}
}
Exemplo n.º 4
0
func Dial(endpoint string) *Conn {
	return &Conn{
		conn: hx.New("", "TgoConnect", 1, endpoint),
	}
}