Exemplo n.º 1
0
//export call_go_func
func call_go_func(c unsafe.Pointer, name *C.char, argc C.uintN, vp *C.jsval) C.JSBool {
	var context = (*Context)(c)

	var args = make([]*Value, int(argc))

	for i := 0; i < len(args); i++ {
		args[i] = newValue(context, C.GET_ARGV(context.jscx, vp, C.int(i)))
	}

	var gname = C.GoString(name)
	var f = Func{
		context: context,
		name:    gname,
		args:    args,
	}

	context.funcs[gname](&f)

	if f.result != nil {
		C.SET_RVAL(context.jscx, vp, f.result.val)
		return C.JS_TRUE
	}

	return C.JS_FALSE
}
Exemplo n.º 2
0
//export call_go_obj_func
func call_go_obj_func(op unsafe.Pointer, name *C.char, argc C.uintN, vp *C.jsval) C.JSBool {
	var o = (*Object)(op)

	var argv = make([]*Value, int(argc))

	for i := 0; i < len(argv); i++ {
		argv[i] = newValue(o.cx, C.GET_ARGV(o.cx.jscx, vp, C.int(i)))
	}

	var gname = C.GoString(name)
	var result = o.funcs[gname](o, gname, argv)

	if result != nil {
		C.SET_RVAL(o.cx.jscx, vp, result.val)
		return C.JS_TRUE
	}

	return C.JS_FALSE
}