func go_value_to_tcl_obj(value interface{}) *C.Tcl_Obj { v := reflect.ValueOf(value) switch v.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return C.Tcl_NewWideIntObj(C.Tcl_WideInt(v.Int())) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return C.Tcl_NewWideIntObj(C.Tcl_WideInt(v.Uint())) case reflect.Float32, reflect.Float64: return C.Tcl_NewDoubleObj(C.double(v.Float())) case reflect.Bool: if v.Bool() { return C.Tcl_NewBooleanObj(1) } return C.Tcl_NewBooleanObj(0) case reflect.String: s := v.String() sh := *(*reflect.StringHeader)(unsafe.Pointer(&s)) return C.Tcl_NewStringObj((*C.char)(unsafe.Pointer(sh.Data)), C.int(len(s))) } return nil }
func go_value_to_tcl_obj(value interface{}, interp *interpreter) *C.Tcl_Obj { v := reflect.ValueOf(value) switch v.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return C.Tcl_NewWideIntObj(C.Tcl_WideInt(v.Int())) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return C.Tcl_NewWideIntObj(C.Tcl_WideInt(v.Uint())) case reflect.Float32, reflect.Float64: return C.Tcl_NewDoubleObj(C.double(v.Float())) case reflect.Bool: if v.Bool() { return C.Tcl_NewBooleanObj(1) } return C.Tcl_NewBooleanObj(0) case reflect.String: s := v.String() sh := *(*reflect.StringHeader)(unsafe.Pointer(&s)) return C.Tcl_NewStringObj((*C.char)(unsafe.Pointer(sh.Data)), C.int(len(s))) case reflect.Slice, reflect.Array: objv := make([]*C.Tcl_Obj, v.Len()) for i := 0; i < v.Len(); i++ { objv[i] = go_value_to_tcl_obj(v.Index(i).Interface(), interp) } return C.Tcl_NewListObj(C.int(len(objv)), &objv[0]) case reflect.Map: tclmap := C.Tcl_NewDictObj() for _, value := range v.MapKeys() { key := go_value_to_tcl_obj(value.Interface(), interp) val := go_value_to_tcl_obj(v.MapIndex(value).Interface(), interp) if key != nil && val != nil { C.Tcl_DictObjPut(interp.C, tclmap, key, val) } } return tclmap } return nil }
func (iv *IntVar) Set(i int) { iv.data = C.Tcl_WideInt(i) cname := C.CString(iv.name) C.Tcl_UpdateLinkedVar(iv.ir.C, cname) C.free_string(cname) }