mirror of https://github.com/Hilbis/Hilbish
feat: add timeout function
timeout(func, time) works exactly like the `setTimeout` function in javascript runs `func` after a period of `time` in millisecondspull/61/head
parent
419e327d95
commit
fe3df8c66e
8
lua.go
8
lua.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"hilbish/golibs/bait"
|
"hilbish/golibs/bait"
|
||||||
"hilbish/golibs/commander"
|
"hilbish/golibs/commander"
|
||||||
|
@ -32,6 +33,7 @@ func LuaInit() {
|
||||||
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
||||||
l.SetGlobal("exec", l.NewFunction(hshexec))
|
l.SetGlobal("exec", l.NewFunction(hshexec))
|
||||||
l.SetGlobal("goro", luar.New(l, hshgoroutine))
|
l.SetGlobal("goro", luar.New(l, hshgoroutine))
|
||||||
|
l.SetGlobal("timeout", luar.New(l, hshtimeout))
|
||||||
|
|
||||||
// yes this is stupid, i know
|
// yes this is stupid, i know
|
||||||
l.PreloadModule("hilbish", HilbishLoader)
|
l.PreloadModule("hilbish", HilbishLoader)
|
||||||
|
@ -151,3 +153,9 @@ func hshexec(L *lua.LState) int {
|
||||||
func hshgoroutine(gofunc func()) {
|
func hshgoroutine(gofunc func()) {
|
||||||
go gofunc()
|
go gofunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hshtimeout(timeoutfunc func(), ms int) {
|
||||||
|
timeout := time.Duration(ms) * time.Millisecond
|
||||||
|
time.AfterFunc(timeout, timeoutfunc)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue