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


Golang FunctionCall.Argument方法代碼示例

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


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

示例1: apiAudioPlay

func (p *Plugin) apiAudioPlay(call otto.FunctionCall) otto.Value {
	if p.instance.Audio.IsPlaying() {
		return otto.FalseValue()
	}
	obj := call.Argument(0).Object()
	if obj == nil {
		return otto.FalseValue()
	}

	filenameValue, _ := obj.Get("filename")
	callbackValue, _ := obj.Get("callback")

	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetApplication(gopus.Audio)
	}

	p.instance.Audio.Source = gumble_ffmpeg.SourceFile(filenameValue.String())
	p.instance.Audio.Play()
	go func() {
		p.instance.Audio.Wait()
		if callbackValue.IsFunction() {
			p.callValue(callbackValue)
		}
	}()
	return otto.TrueValue()
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:26,代碼來源:audio.go

示例2: apiProcessNew

func (p *Plugin) apiProcessNew(call otto.FunctionCall) otto.Value {
	callback := call.Argument(0)
	command := call.Argument(1).String()

	args := make([]string, len(call.ArgumentList)-2)
	for i, arg := range call.ArgumentList[2:] {
		args[i] = arg.String()
	}

	proc := &process{
		cmd: exec.Command(command, args...),
	}

	go func() {
		var str string
		bytes, err := proc.cmd.Output()
		if err == nil {
			if bytes != nil {
				str = string(bytes)
			}
			p.callValue(callback, proc.cmd.ProcessState.Success(), str)
		} else {
			p.callValue(callback, false, "")
		}
	}()

	ret, _ := p.state.ToValue(proc)
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:29,代碼來源:process.go

示例3: apiAudioSetVolume

func (p *Plugin) apiAudioSetVolume(call otto.FunctionCall) otto.Value {
	volume, err := call.Argument(0).ToFloat()
	if err != nil {
		return otto.UndefinedValue()
	}
	p.instance.Audio.Volume = float32(volume)
	return otto.UndefinedValue()
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:8,代碼來源:audio.go

示例4: apiAudioSetBitrate

func (p *Plugin) apiAudioSetBitrate(call otto.FunctionCall) otto.Value {
	bitrate, err := call.Argument(0).ToInteger()
	if err != nil {
		return otto.UndefinedValue()
	}
	if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok {
		enc.SetBitrate(int(bitrate))
	}
	return otto.UndefinedValue()
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:10,代碼來源:audio.go

示例5: apiAudioNewTarget

func (p *Plugin) apiAudioNewTarget(call otto.FunctionCall) otto.Value {
	id, err := call.Argument(0).ToInteger()
	if err != nil {
		return otto.UndefinedValue()
	}

	target := &gumble.VoiceTarget{}
	target.ID = uint32(id)
	value, _ := p.state.ToValue(target)
	return value
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:11,代碼來源:audio.go

示例6: apiAudioSetTarget

func (p *Plugin) apiAudioSetTarget(call otto.FunctionCall) otto.Value {
	if len(call.ArgumentList) == 0 {
		p.instance.Client.VoiceTarget = nil
		return otto.TrueValue()
	}
	target, err := call.Argument(0).Export()
	if err != nil {
		return otto.UndefinedValue()
	}
	voiceTarget := target.(*gumble.VoiceTarget)
	p.instance.Client.Send(voiceTarget)
	p.instance.Client.VoiceTarget = voiceTarget
	return otto.TrueValue()
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:14,代碼來源:audio.go

示例7: Read

func (f *file) Read(call otto.FunctionCall) otto.Value {
	bytes, err := call.Argument(0).ToInteger()
	var data []byte
	if bytes <= 0 {
		data, err = ioutil.ReadAll(f.f)
		if err != nil {
			return otto.UndefinedValue()
		}
	} else {
		data = make([]byte, bytes)
		_, err = io.ReadFull(f.f, data)
		if err != nil {
			panic(err)
			return otto.UndefinedValue()
		}
	}

	ret, _ := call.Otto.ToValue(string(data))
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:20,代碼來源:file.go

示例8: Seek

func (f *file) Seek(call otto.FunctionCall) otto.Value {
	offset, _ := call.Argument(0).ToInteger()
	whence := call.Argument(1).String()

	if whence == "" {
		whence = "cur"
	}
	var iWhence int
	switch whence {
	case "set":
		iWhence = 0
	case "cur":
		iWhence = 1
	case "end":
		iWhence = 2
	default:
		return otto.UndefinedValue()
	}

	val, _ := f.f.Seek(offset, iWhence)
	ret, _ := call.Otto.ToValue(val)
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:23,代碼來源:file.go

示例9: apiTimerNew

func (p *Plugin) apiTimerNew(call otto.FunctionCall) otto.Value {
	callback := call.Argument(0)
	timeout, _ := call.Argument(1).ToInteger()

	t := &timer{
		cancel: make(chan bool),
	}

	go func() {
		defer func() {
			close(t.cancel)
			t.cancel = nil
		}()

		select {
		case <-time.After(time.Millisecond * time.Duration(timeout)):
			p.callValue(callback)
		case <-t.cancel:
		}
	}()

	ret, _ := p.state.ToValue(t)
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:24,代碼來源:timer.go

示例10: apiFileOpen

func (p *Plugin) apiFileOpen(call otto.FunctionCall) otto.Value {
	var filename, mode string
	switch len(call.ArgumentList) {
	case 1:
		filename = call.Argument(0).String()
		mode = "r"
	case 2:
		filename = call.Argument(0).String()
		mode = call.Argument(1).String()
	default:
		return otto.UndefinedValue()
	}

	var iMode int

	switch mode {
	case "r":
		iMode = os.O_RDONLY
	case "r+":
		iMode = os.O_RDWR
	case "w":
		iMode = os.O_WRONLY | os.O_CREATE
	case "w+":
		iMode = os.O_RDWR | os.O_CREATE | os.O_TRUNC
	case "a":
		iMode = os.O_WRONLY | os.O_CREATE | os.O_APPEND
	case "a+":
		iMode = os.O_RDWR | os.O_CREATE | os.O_APPEND
	default:
		return otto.UndefinedValue()
	}

	osFile, err := os.OpenFile(filename, iMode, 0644)
	if err != nil {
		return otto.UndefinedValue()
	}

	f := &file{
		f: osFile,
	}

	ret, _ := p.state.ToValue(f)
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:44,代碼來源:file.go

示例11: apiOn

func (p *Plugin) apiOn(call otto.FunctionCall) otto.Value {
	event := strings.ToLower(call.Argument(0).String())
	function := call.Argument(1)
	p.listeners[event] = append(p.listeners[event], function)
	return otto.UndefinedValue()
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:6,代碼來源:plugin.go

示例12: Write

func (f *file) Write(call otto.FunctionCall) otto.Value {
	val, _ := f.f.WriteString(call.Argument(0).String())
	ret, _ := call.Otto.ToValue(val)
	return ret
}
開發者ID:mgalvey,項目名稱:piepan,代碼行數:5,代碼來源:file.go


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