本文整理匯總了Golang中github.com/mgalvey/otto.FunctionCall類的典型用法代碼示例。如果您正苦於以下問題:Golang FunctionCall類的具體用法?Golang FunctionCall怎麽用?Golang FunctionCall使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FunctionCall類的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()
}
示例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
}
示例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()
}
示例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()
}
示例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
}
示例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()
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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
}