Embedded javascript plugins (#1393)

This commit is contained in:
WithoutPants
2021-05-26 14:17:53 +10:00
committed by GitHub
parent cc5ec650ae
commit 9b57fbbf50
108 changed files with 30179 additions and 91 deletions

22
pkg/plugin/js/util.go Normal file
View File

@@ -0,0 +1,22 @@
package js
import (
"time"
"github.com/robertkrimen/otto"
)
func sleepFunc(call otto.FunctionCall) otto.Value {
arg := call.Argument(0)
ms, _ := arg.ToInteger()
time.Sleep(time.Millisecond * time.Duration(ms))
return otto.UndefinedValue()
}
func AddUtilAPI(vm *otto.Otto) {
util, _ := vm.Object("({})")
util.Set("Sleep", sleepFunc)
vm.Set("util", util)
}