mirror of https://github.com/tidwall/tile38.git
fix: removed init(); modified lua function impls based on review
This commit is contained in:
parent
fa74ffa10f
commit
02a614bc6d
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue