Пример #1
0
func (v *V8Context) Eval(in string) (res interface{}, err error) {
	ptr := C.CString(in)
	defer C.free(unsafe.Pointer(ptr))
	C.v8_callback_init()
	ret := C.v8_execute(v.v8context, ptr)
	if ret != nil {
		out := C.GoString(ret)
		if out != "" {
			C.free(unsafe.Pointer(ret))
			var buf bytes.Buffer
			buf.Write([]byte(out))
			dec := json.NewDecoder(&buf)
			err = dec.Decode(&res)
			return
		}
		return nil, nil
	}
	ret = C.v8_error(v.v8context)
	out := C.GoString(ret)
	C.free(unsafe.Pointer(ret))
	return nil, errors.New(out)
}
Пример #2
0
func init() {
	C.v8_callback_init()
}