當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Value.Call方法代碼示例

本文整理匯總了Golang中github.com/robertkrimen/otto.Value.Call方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.Call方法的具體用法?Golang Value.Call怎麽用?Golang Value.Call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/robertkrimen/otto.Value的用法示例。


在下文中一共展示了Value.Call方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runIteratorWithCallback

func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
	count := 0
	it, _ = it.Optimize()
	for {
		if ses.doHalt {
			return
		}
		_, ok := it.Next()
		if !ok {
			break
		}
		tags := make(map[string]graph.TSVal)
		it.TagResults(&tags)
		val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
		val, _ = callback.Call(this.This, val)
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return
			}
			tags := make(map[string]graph.TSVal)
			it.TagResults(&tags)
			val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
			val, _ = callback.Call(this.This, val)
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
}
開發者ID:heshizhu,項目名稱:cayley,代碼行數:35,代碼來源:finals.go

示例2: runIteratorWithCallback

func (wk *worker) runIteratorWithCallback(it graph.Iterator, callback otto.Value, this otto.FunctionCall, limit int) {
	ctx, cancel := wk.newContext()
	defer cancel()

	err := graph.Iterate(ctx, it).Paths(true).Limit(limit).TagEach(func(tags map[string]graph.Value) {
		val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
		val, _ = callback.Call(this.This, val)
	})
	if err != nil {
		clog.Errorf("gremlin: %v", err)
	}
}
開發者ID:rlugojr,項目名稱:cayley,代碼行數:12,代碼來源:finals.go

示例3: PrettyPrint

// uses the "prettyPrint" JS function to format a value
func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error) {
	var method otto.Value
	v, err = self.vm.ToValue(v)
	if err != nil {
		return
	}
	method, err = self.vm.Get("prettyPrint")
	if err != nil {
		return
	}
	return method.Call(method, v)
}
開發者ID:CedarLogic,項目名稱:go-ethereum,代碼行數:13,代碼來源:jsre.go

示例4: AddCallback

func (p *Plugin) AddCallback(eventCode string, name string, callback otto.Value) {
	wrappedCallback := func(env otto.Value) {
		_, err := callback.Call(env)
		if err != nil {
			p.log.Printf("Callback `%s` (%#v) for event code `%s` errored: %s", name, callback, eventCode, err)
		}
	}
	p.callbacks[eventCode] = append(p.callbacks[eventCode], &pluginFunc{
		function: wrappedCallback,
		help:     name,
	})
}
開發者ID:Zenithar,項目名稱:aktarus,代碼行數:12,代碼來源:plugin.go

示例5: PrettyPrint

// PrettyPrint writes v to standard output.
func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error) {
	var method otto.Value
	self.do(func(vm *otto.Otto) {
		val, err = vm.ToValue(v)
		if err != nil {
			return
		}
		method, err = vm.Get("prettyPrint")
		if err != nil {
			return
		}
		val, err = method.Call(method, val)
	})
	return val, err
}
開發者ID:ssonneborn22,項目名稱:go-ethereum,代碼行數:16,代碼來源:jsre.go

示例6: runIteratorWithCallback

func (wk *worker) runIteratorWithCallback(it graph.Iterator, callback otto.Value, this otto.FunctionCall, limit int) {
	n := 0
	it, _ = it.Optimize()
	if glog.V(2) {
		b, err := json.MarshalIndent(it.Describe(), "", "  ")
		if err != nil {
			glog.V(2).Infof("failed to format description: %v", err)
		} else {
			glog.V(2).Infof("%s", b)
		}
	}
	for {
		select {
		case <-wk.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
		val, _ = callback.Call(this.This, val)
		n++
		if limit >= 0 && n >= limit {
			break
		}
		for it.NextPath() {
			select {
			case <-wk.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
			val, _ = callback.Call(this.This, val)
			n++
			if limit >= 0 && n >= limit {
				break
			}
		}
	}
	it.Close()
}
開發者ID:ericcapricorn,項目名稱:cayley,代碼行數:46,代碼來源:finals.go

示例7: callHandler

func (ctrl *JsController) callHandler(handler otto.Value, params ...interface{}) (interface{}, error) {
	if !handler.IsFunction() {
		return nil, fmt.Errorf("Result should be a function, got %v", handler)
	}
	out, err := handler.Call(handler, params...)
	if err != nil {
		glog.Errorf("Call resulted in failure %#v", err)
		return nil, err
	}

	obj, err := out.Export()
	if err != nil {
		glog.Errorf("Failed to extract response %#v", err)
		return nil, err
	}
	return obj, nil
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:17,代碼來源:js.go

示例8: SetCommand

func (p *Plugin) SetCommand(name string, command otto.Value, help string) {
	if _, ok := p.commands[name]; ok {
		if p.cfg.Irc.Debug || p.cfg.Debug {
			p.log.Printf("Warning: Command `%s` was already defined. Overriding...", name)
		}
	}
	wrappedCommand := func(env otto.Value) {
		_, err := command.Call(env)
		if err != nil {
			p.log.Printf("Command `%s` errored: %s", name, err)
		}
	}
	p.commands[name] = &pluginFunc{
		function: wrappedCommand,
		help:     help,
	}
}
開發者ID:Zenithar,項目名稱:aktarus,代碼行數:17,代碼來源:plugin.go

示例9: evaluateScript

func evaluateScript(src string, payload []FinalInput) (string, error) {
	javaScript := otto.New()
	var evalFunc otto.Value
	javaScript.Set("eval", func(call otto.FunctionCall) otto.Value {
		evalFunc = call.Argument(0)
		return otto.UndefinedValue()
	})

	javaScript.Run(src)
	arg, err := javaScript.ToValue(payload)
	if err != nil {
		return "", err
	}

	ret, err := evalFunc.Call(otto.NullValue(), arg)
	if err != nil {
		return "", err
	}
	return ret.ToString()
}
開發者ID:gophergala2016,項目名稱:scattr,代碼行數:20,代碼來源:evaluate.go

示例10: runIteratorWithCallback

func (wk *worker) runIteratorWithCallback(it graph.Iterator, callback otto.Value, this otto.FunctionCall, limit int) {
	n := 0
	it, _ = it.Optimize()
	glog.V(2).Infoln(it.DebugString(0))
	for {
		select {
		case <-wk.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
		val, _ = callback.Call(this.This, val)
		n++
		if limit >= 0 && n >= limit {
			break
		}
		for it.NextPath() {
			select {
			case <-wk.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
			val, _ = callback.Call(this.This, val)
			n++
			if limit >= 0 && n >= limit {
				break
			}
		}
	}
	it.Close()
}
開發者ID:Joeento,項目名稱:cayley,代碼行數:39,代碼來源:finals.go

示例11: runIteratorWithCallback

func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) {
	count := 0
	it, _ = it.Optimize()
	for {
		select {
		case <-ses.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
		val, _ = callback.Call(this.This, val)
		count++
		if limit >= 0 && count >= limit {
			break
		}
		for it.NextPath() {
			select {
			case <-ses.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			val, _ := this.Otto.ToValue(tagsToValueMap(tags, ses))
			val, _ = callback.Call(this.This, val)
			count++
			if limit >= 0 && count >= limit {
				break
			}
		}
	}
	it.Close()
}
開發者ID:jacqui,項目名稱:cayley,代碼行數:38,代碼來源:finals.go

示例12: evaluateRule

func evaluateRule(src string, payload *Message) (bool, error) {
	js := otto.New()
	var ruleFunc otto.Value
	js.Set("rule", func(call otto.FunctionCall) otto.Value {
		ruleFunc = call.Argument(0)
		return otto.UndefinedValue()
	})

	js.Run(src)
	arg, err := js.ToValue(payload)

	if err != nil {
		return false, err
	}

	ret, err := ruleFunc.Call(otto.NullValue(), arg)

	if err != nil {
		return false, err
	}

	return ret.ToBoolean()
}
開發者ID:ashaniray,項目名稱:mailhook,代碼行數:23,代碼來源:rule.go

示例13: TriggerEvent

func (s *Scripting) TriggerEvent(eventName string, rawArguments ...interface{}) (err error) {
	var (
		present   bool
		callbacks []otto.Value
		callback  otto.Value
		response  otto.Value
		arguments []interface{}
	)
	if callbacks, present = s.listeners[eventName]; !present {
		return // Not an error to have no listeners.
	}
	if arguments, err = s.convertArguments(rawArguments); err != nil {
		return
	}
	for _, callback = range callbacks {
		if response, err = callback.Call(callback, arguments...); err != nil {
			return
		}
		if response.IsString() {
			fmt.Printf("Response from callback: %s\n", response.String())
		}
	}
	return
}
開發者ID:pikkpoiss,項目名稱:twodee,代碼行數:24,代碼來源:script.go


注:本文中的github.com/robertkrimen/otto.Value.Call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。