func (v7 *V7) Apply(fn Val, thisObj Val, args Val) (Val, error) { var result C.v7_val_t e := C.v7_apply((*C.struct_v7)(v7), &result, C.v7_val_t(fn), C.v7_val_t(thisObj), C.v7_val_t(args)) v := Val(result) // DEBUG //fmt.Println(v7.ToJSON(v, 2048)) return v, v7.convertError(v, e) }
func (v7 *V7) ToString(v Val) (string, error) { if !v7.IsString(v) { return "", errors.New("value is not a string") } var l *C.size_t = new(C.size_t) cv := C.v7_val_t(v) return C.GoString(C.v7_to_string((*C.struct_v7)(v7), &cv, l)), nil }
func (v7 *V7) ToJSON(v Val, size int) string { buflen := C.size_t(size) buf := (*C.char)(C.malloc(buflen)) defer C.free(unsafe.Pointer(buf)) C.v7_to_json((*C.struct_v7)(v7), C.v7_val_t(v), buf, buflen) return C.GoString(buf) }
func (v7 *V7) Set(obj Val, name string, attrs uint, v Val) error { cs := C.CString(name) defer C.free(unsafe.Pointer(cs)) if 0 != C.v7_set((*C.struct_v7)(v7), C.v7_val_t(obj), cs, C.size_t(len(name)), C.uint(attrs), C.v7_val_t(v)) { return errors.New("failed to set " + name) } return nil }
func (v7 *V7) Get(obj Val, name string) Val { cs := C.CString(name) defer C.free(unsafe.Pointer(cs)) return Val(C.v7_get((*C.struct_v7)(v7), C.v7_val_t(obj), cs, C.size_t(len(name)))) }
func (v7 *V7) ToNumber(v Val) (float64, error) { if !v7.IsNumber(v) { return math.NaN(), errors.New("value is not a number") } return float64(C.v7_to_number(C.v7_val_t(v))), nil }
func (v7 *V7) IsUndefined(v Val) bool { return C.v7_is_undefined(C.v7_val_t(v)) != 0 }
func (v7 *V7) ArrayPush(ary Val, v Val) { C.v7_array_push((*C.struct_v7)(v7), C.v7_val_t(ary), C.v7_val_t(v)) }