Sfoglia il codice sorgente

'新增formatToString公共方法'

maxiaoshan 3 anni fa
parent
commit
a5058b802d
1 ha cambiato i file con 10 aggiunte e 0 eliminazioni
  1. 10 0
      src/spider/script.go

+ 10 - 0
src/spider/script.go

@@ -18,6 +18,8 @@ import (
 	"net/url"
 	"path"
 
+	"github.com/shopspring/decimal"
+
 	qu "qfw/util"
 	_ "qfw/util/redis"
 	"regexp"
@@ -765,6 +767,14 @@ func (s *Script) LoadScript(code, script_file string, newstate bool) string {
 		S.Push(lua.LString(con))
 		return 1
 	}))
+	//interface转string
+	s.L.SetGlobal("formatToString", s.L.NewFunction(func(S *lua.LState) int {
+		strNum := S.ToString(-1)
+		decimalNum, _ := decimal.NewFromString(strNum)
+		S.Push(lua.LString(decimalNum.String()))
+		return 1
+	}))
+
 	return ""
 }
 func dealHref(pageListUrl, href string) string {