fix: removed init(); modified lua function impls based on review

This commit is contained in:
program-- 2022-11-11 15:47:33 -08:00
parent fa74ffa10f
commit 02a614bc6d
1 changed files with 3 additions and 7 deletions

View File

@ -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
}