当前位置: 首页>>代码示例>>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;未经允许,请勿转载。