func GoEval2(expr *C.char, result **C.char) int { var res string var ret int src := C.GoString(expr) world := eval.NewWorld() world.DefineVar("remote_expr", eval.NewFuncType([]eval.Type{eval.StringType, eval.StringType}, false, []eval.Type{eval.StringType}), &funcV{&w_remote_expr{}}) code, err := world.Compile(fset, src) if err != nil { res = err.String() ret = -1 } else { value, err := code.Run() if err != nil { res = err.String() ret = -1 } else { res = value.String() ret = 0 } } p := C.CString(res) defer C.free(unsafe.Pointer(p)) *result = (*C.char)(C.vimremote_malloc((C.size_t)(len(res) + 1))) C.memmove(unsafe.Pointer(*result), unsafe.Pointer(p), (C.size_t)(len(res)+1)) return ret }
//export GoEval func GoEval(expr *C.char, result **C.char) int { var ret int func() { defer func() { if x := recover(); x != nil { ret = -1 res := fmt.Sprintf("%s", x) p := C.CString(res) defer C.free(unsafe.Pointer(p)) *result = (*C.char)(C.vimremote_malloc((C.size_t)(len(res) + 1))) C.memmove(unsafe.Pointer(*result), unsafe.Pointer(p), (C.size_t)(len(res)+1)) } }() ret = GoEval2(expr, result) }() return ret }