github.com/tardisgo/tardisgo@v0.0.0-20161119180838-e0dd9a7e46b5/haxe/hx/hx.go (about) 1 // Package hx provides pseudo-functions to interface to Haxe code, TARDIS Go re-writes these functions as Haxe. 2 // It follows that these functions act more like macros than functions, so some parameters must be constant strings. 3 // 4 // This package provides untyped access to Haxe, which is far from ideal. 5 // The next stage of development will be to provide a typed Go overlay - the gohaxelib approach (as yet incomplete). 6 // The final stage will be to use Haxe types directly... 7 // 8 package hx 9 10 import "unsafe" 11 12 // CallbackFunc returns the Haxe-callable form of a Go function, or 13 // if passed a string value, it gives the actual name of a Haxe function e.g. "Scheduler.timerEventHandler" 14 func CallbackFunc(function interface{}) interface{} { return nil } 15 16 // Resource loads a file resource that was added through the 17 // -resource host/file/path/a.dat@/target/file/path/b.dat haxe command line parameter; 18 // if the file resource does not exist, an empty slice is returned. 19 func Resource(s string) []byte { return []byte{} } 20 21 // Malloc allocates a memory Object and returns an unsafe pointer to it 22 func Malloc(size uintptr) unsafe.Pointer { return nil } 23 24 // IsNull returns if the haxe Dynamic variable is null 25 func IsNull(x uintptr) bool { return false } 26 27 // Null returns a haxe Dynamic null value 28 func Null() uintptr { return 0 } 29 30 // Complex provides a cast from haxe Dynamic type 31 func Complex(x uintptr) complex128 { return 0 + 0i } 32 33 // Int64 provides a cast from haxe Dynamic type 34 func Int64(x uintptr) int64 { return 0 } 35 36 // Source places the contents into a classname.hx file in the haxe output directory at compile time. 37 func Source(classname, contents string) {} 38 39 // Code inserts the given constant Haxe code at this point. This is not suitable for the casual programmer. 40 // ifLogic = a constant string giving the logic for wrapping Haxe complie time condition, ignored if "": #if (ifLogic) ... #end 41 // resTyp = a constant string giving the Go name of the type of the data to be returned as an interface. "" if nothing is returned. 42 // NOTE: the returned values are not converted from Haxe format, e.g. String values will not be converted back to UTF-8 on UTF-16 targets. 43 // code = must be a constant string containing a well-formed Haxe statement, probably terminated with a ";". 44 // args = whatever aguments are passed (as interfaces), typical haxe code to access the value of an argument is "_a[3].val". 45 // Try the Go code: 46 // hx.Code("","trace('HAXE trace:',_a.itemAddr(0).load().val,_a.itemAddr(1).load().val);", 42,43) 47 func Code(ifLogic, code string, args ...interface{}) {} 48 49 // CodeIface - same as Code() but returns an interface. 50 func CodeIface(ifLogic, resTyp, code string, args ...interface{}) interface{} { return nil } 51 52 // CodeBool - same as Code() but returns a bool. 53 func CodeBool(ifLogic, code string, args ...interface{}) bool { return false } 54 55 // CodeInt - same as Code() but returns an int. 56 func CodeInt(ifLogic, code string, args ...interface{}) int { return 0 } 57 58 // CodeFloat - same as Code() but returns a float64. 59 func CodeFloat(ifLogic, code string, args ...interface{}) float64 { return 0.0 } 60 61 // CodeString - same as Code() but returns a string. 62 func CodeString(ifLogic, code string, args ...interface{}) string { return "" } 63 64 // CodeDynamic - same as Code() but returns a Dynamic (modeled as Haxe Dynamic in TARDIS Go, so can hold any Haxe object). 65 func CodeDynamic(ifLogic, code string, args ...interface{}) uintptr { return 0 } 66 67 // Call static Haxe functions, ifLogic, resTyp & target must be constant strings, nargs must be a constant number of arguments. 68 69 func Call(ifLogic, target string, nargs int, args ...interface{}) {} 70 func CallIface(ifLogic, resTyp, target string, nargs int, args ...interface{}) interface{} { return nil } 71 func CallBool(ifLogic, target string, nargs int, args ...interface{}) bool { return false } 72 func CallInt(ifLogic, target string, nargs int, args ...interface{}) int { return 0 } 73 func CallFloat(ifLogic, target string, nargs int, args ...interface{}) float64 { return 0.0 } 74 func CallString(ifLogic, target string, nargs int, args ...interface{}) string { return "" } 75 func CallDynamic(ifLogic, target string, nargs int, args ...interface{}) uintptr { return 0 } 76 77 func New(ifLogic, target string, nargs int, args ...interface{}) uintptr { return 0 } // new haxe type 78 79 // Call Haxe instance functions, method must be a constant string, nargs must be a constant number of arguments. 80 // haxeType is required when the underlying haxe object is a simple type in compiled langs, like Date (int in cpp), otherwise "" 81 // ifLogic, resTyp & haxeType must be constant strings 82 83 func Meth(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) { 84 } 85 func MethIface(ifLogic string, resTyp uintptr, object interface{}, haxeType string, nargs int, method string, args ...interface{}) interface{} { 86 return nil 87 } 88 func MethBool(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) bool { 89 return false 90 } 91 func MethInt(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) int { 92 return 0 93 } 94 func MethFloat(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) float64 { 95 return 0.0 96 } 97 func MethString(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) string { 98 return "" 99 } 100 func MethDynamic(ifLogic string, object uintptr, haxeType string, method string, nargs int, args ...interface{}) uintptr { 101 return 0 102 } 103 104 // Get a static Haxe value, ifLogic, resTyp & name must be constant strings. 105 106 func GetIface(ifLogic, resTyp, name string) interface{} { return nil } 107 func GetBool(ifLogic, name string) bool { return false } 108 func GetInt(ifLogic, name string) int { return 0 } 109 func GetFloat(ifLogic, name string) float64 { return 0.0 } 110 func GetString(ifLogic, name string) string { return "" } 111 func GetDynamic(ifLogic, name string) uintptr { return 0 } 112 113 // Set a static Haxe value, ifLogic, resTyp & name must be constant strings. 114 115 func SetIface(ifLogic, resTyp, name string, val interface{}) {} // TODO is this required? 116 func SetBool(ifLogic, name string, val bool) {} 117 func SetInt(ifLogic, name string, val int) {} 118 func SetFloat(ifLogic, name string, val float64) {} 119 func SetString(ifLogic, name string, val string) {} 120 func SetDynamic(ifLogic, name string, val uintptr) {} 121 122 // Get a field value in a Haxe object, ifLogic, resTyp & name must be constant strings. 123 124 func FgetIface(ifLogic, resTyp string, object uintptr, haxeType string, name string) interface{} { 125 return nil 126 } 127 func FgetBool(ifLogic string, object uintptr, haxeType string, name string) bool { return false } 128 func FgetInt(ifLogic string, object uintptr, haxeType string, name string) int { return 0 } 129 func FgetFloat(ifLogic string, object uintptr, haxeType string, name string) float64 { return 0.0 } 130 func FgetString(ifLogic string, object uintptr, haxeType string, name string) string { return "" } 131 func FgetDynamic(ifLogic string, object uintptr, haxeType string, name string) uintptr { return 0 } 132 133 // Set a field value in a Haxe object, ifLogic, resTyp & name must be constant strings. 134 135 func FsetIface(ifLogic, resTyp string, object uintptr, haxeType string, name string, val interface{}) { 136 } // TODO is this required? 137 func FsetBool(ifLogic string, object uintptr, haxeType string, name string, val bool) {} 138 func FsetInt(ifLogic string, object uintptr, haxeType string, name string, val int) {} 139 func FsetFloat(ifLogic string, object uintptr, haxeType string, name string, val float64) {} 140 func FsetString(ifLogic string, object uintptr, haxeType string, name string, val string) {} 141 func FsetDynamic(ifLogic string, object uintptr, haxeType string, name string, val uintptr) {}