fix: handle errors in goro and timeout callbacks

windows-fixes
TorchedSammy 2022-03-04 22:21:34 -04:00
parent 83ca8066e6
commit 5175367b35
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 12 additions and 8 deletions

20
api.go
View File

@ -274,11 +274,13 @@ func hlgoro(L *lua.LState) int {
// call fn // call fn
go func() { go func() {
L.CallByParam(lua.P{ if err := L.CallByParam(lua.P{
Fn: fn, Fn: fn,
NRet: 0, NRet: 0,
Protect: true, Protect: true,
}, args...) }, args...); err != nil {
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
}
}() }()
return 0 return 0
@ -295,11 +297,13 @@ func hltimeout(L *lua.LState) int {
timeout := time.Duration(ms) * time.Millisecond timeout := time.Duration(ms) * time.Millisecond
time.Sleep(timeout) time.Sleep(timeout)
L.CallByParam(lua.P{ if err := L.CallByParam(lua.P{
Fn: cb, Fn: cb,
NRet: 0, NRet: 0,
Protect: true, Protect: true,
}) }); err != nil {
fmt.Fprintln(os.Stderr, "Error in goro function:\n\n", err)
}
return 0 return 0
} }