|
@@ -1,4 +1,5 @@
|
|
-/**
|
|
|
|
|
|
+/*
|
|
|
|
+*
|
|
脚本加载+调用 封装,
|
|
脚本加载+调用 封装,
|
|
前期走文件系统加载
|
|
前期走文件系统加载
|
|
后期走数据库配置,
|
|
后期走数据库配置,
|
|
@@ -38,7 +39,7 @@ import (
|
|
"github.com/yuin/gopher-lua"
|
|
"github.com/yuin/gopher-lua"
|
|
)
|
|
)
|
|
|
|
|
|
-//脚本
|
|
|
|
|
|
+// 脚本
|
|
type Script struct {
|
|
type Script struct {
|
|
SCode, ScriptFile string
|
|
SCode, ScriptFile string
|
|
Encoding string
|
|
Encoding string
|
|
@@ -51,7 +52,7 @@ type Script struct {
|
|
Test_goreqcon int //go发起次数(正文)
|
|
Test_goreqcon int //go发起次数(正文)
|
|
}
|
|
}
|
|
|
|
|
|
-//加载文件
|
|
|
|
|
|
+// 加载文件
|
|
func (s *Script) LoadScript(site *string, downloadnode, script string, isfile ...string) {
|
|
func (s *Script) LoadScript(site *string, downloadnode, script string, isfile ...string) {
|
|
s.ScriptFile = script
|
|
s.ScriptFile = script
|
|
options := lua.Options{
|
|
options := lua.Options{
|
|
@@ -526,6 +527,17 @@ func (s *Script) LoadScript(site *string, downloadnode, script string, isfile ..
|
|
S.Push(lua.LString(result))
|
|
S.Push(lua.LString(result))
|
|
return 1
|
|
return 1
|
|
}))
|
|
}))
|
|
|
|
+ //GB2312字符集解码
|
|
|
|
+ s.L.SetGlobal("decodeGB2312", s.L.NewFunction(func(S *lua.LState) int {
|
|
|
|
+ text := S.ToString(-1)
|
|
|
|
+ result := ""
|
|
|
|
+ decodedString, _, err := transform.String(simplifiedchinese.GB18030.NewDecoder(), text)
|
|
|
|
+ if err == nil {
|
|
|
|
+ result = decodedString
|
|
|
|
+ }
|
|
|
|
+ S.Push(lua.LString(result))
|
|
|
|
+ return 1
|
|
|
|
+ }))
|
|
//aes cbc模式加密
|
|
//aes cbc模式加密
|
|
s.L.SetGlobal("aesEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
s.L.SetGlobal("aesEncryptCBC", s.L.NewFunction(func(S *lua.LState) int {
|
|
origData := S.ToString(-3)
|
|
origData := S.ToString(-3)
|
|
@@ -930,7 +942,7 @@ func (s *Script) Reload() {
|
|
s.LoadScript(&site, "", s.ScriptFile)
|
|
s.LoadScript(&site, "", s.ScriptFile)
|
|
}
|
|
}
|
|
|
|
|
|
-//unicode转码
|
|
|
|
|
|
+// unicode转码
|
|
func transUnic(str string) string {
|
|
func transUnic(str string) string {
|
|
buf := bytes.NewBuffer(nil)
|
|
buf := bytes.NewBuffer(nil)
|
|
i, j := 0, len(str)
|
|
i, j := 0, len(str)
|
|
@@ -957,12 +969,11 @@ func transUnic(str string) string {
|
|
return buf.String()
|
|
return buf.String()
|
|
}
|
|
}
|
|
|
|
|
|
-//取得变量
|
|
|
|
|
|
+// 取得变量
|
|
func (s *Script) GetVar(key string) string {
|
|
func (s *Script) GetVar(key string) string {
|
|
return s.L.GetGlobal(key).String()
|
|
return s.L.GetGlobal(key).String()
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func (s *Script) GetIntVar(key string) int {
|
|
func (s *Script) GetIntVar(key string) int {
|
|
lv := s.L.GetGlobal(key)
|
|
lv := s.L.GetGlobal(key)
|
|
if v, ok := lv.(lua.LNumber); ok {
|
|
if v, ok := lv.(lua.LNumber); ok {
|
|
@@ -971,7 +982,6 @@ func (s *Script) GetIntVar(key string) int {
|
|
return -1
|
|
return -1
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
func (s *Script) GetBoolVar(key string) bool {
|
|
func (s *Script) GetBoolVar(key string) bool {
|
|
lv := s.L.GetGlobal(key)
|
|
lv := s.L.GetGlobal(key)
|
|
if v, ok := lv.(lua.LBool); ok {
|
|
if v, ok := lv.(lua.LBool); ok {
|