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
|
// For Lua os.clock() impl
|
||||||
var startedAt time.Time
|
var startedAt time.Time = time.Now()
|
||||||
|
|
||||||
var errShaNotFound = errors.New("sha not found")
|
var errShaNotFound = errors.New("sha not found")
|
||||||
var errCmdNotSupported = errors.New("command not supported in scripts")
|
var errCmdNotSupported = errors.New("command not supported in scripts")
|
||||||
@ -45,10 +45,6 @@ type lStatePool struct {
|
|||||||
total int
|
total int
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
startedAt = time.Now()
|
|
||||||
}
|
|
||||||
|
|
||||||
// newPool returns a new pool of lua states
|
// newPool returns a new pool of lua states
|
||||||
func (s *Server) newPool() *lStatePool {
|
func (s *Server) newPool() *lStatePool {
|
||||||
pl := &lStatePool{
|
pl := &lStatePool{
|
||||||
@ -913,7 +909,7 @@ func baseToNumber(L *lua.LState) int {
|
|||||||
L.Push(lv)
|
L.Push(lv)
|
||||||
case lua.LString:
|
case lua.LString:
|
||||||
str := strings.Trim(string(lv), " \n\t")
|
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 {
|
if v, err := strconv.ParseFloat(str, lua.LNumberBit); err != nil {
|
||||||
L.Push(lua.LNil)
|
L.Push(lua.LNil)
|
||||||
} else {
|
} else {
|
||||||
@ -944,7 +940,7 @@ func baseToString(L *lua.LState) int {
|
|||||||
|
|
||||||
// Lua os.clock()
|
// Lua os.clock()
|
||||||
func osClock(L *lua.LState) int {
|
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
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user