From 02a614bc6db5102a9cd2d63c92d2349139481b03 Mon Sep 17 00:00:00 2001 From: program-- Date: Fri, 11 Nov 2022 15:47:33 -0800 Subject: [PATCH] fix: removed init(); modified lua function impls based on review --- internal/server/scripts.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/internal/server/scripts.go b/internal/server/scripts.go index 5f781f80..0956f224 100644 --- a/internal/server/scripts.go +++ b/internal/server/scripts.go @@ -27,7 +27,7 @@ const ( ) // For Lua os.clock() impl -var startedAt time.Time +var startedAt time.Time = time.Now() var errShaNotFound = errors.New("sha not found") var errCmdNotSupported = errors.New("command not supported in scripts") @@ -45,10 +45,6 @@ type lStatePool struct { total int } -func init() { - startedAt = time.Now() -} - // newPool returns a new pool of lua states func (s *Server) newPool() *lStatePool { pl := &lStatePool{ @@ -913,7 +909,7 @@ func baseToNumber(L *lua.LState) int { L.Push(lv) case lua.LString: str := strings.Trim(string(lv), " \n\t") - if strings.Index(str, ".") > -1 { + if strings.Contains(str, ".") { if v, err := strconv.ParseFloat(str, lua.LNumberBit); err != nil { L.Push(lua.LNil) } else { @@ -944,7 +940,7 @@ func baseToString(L *lua.LState) int { // Lua os.clock() func osClock(L *lua.LState) int { - L.Push(lua.LNumber(float64(time.Now().Sub(startedAt)) / float64(time.Second))) + L.Push(lua.LNumber(time.Since(startedAt).Seconds())) return 1 }