mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 21:12:25 +00:00
Compare commits
5 Commits
b97febc16e
...
b454f4de8d
| Author | SHA1 | Date | |
|---|---|---|---|
| b454f4de8d | |||
| c161639766 | |||
| dd336a7d9a | |||
| ab37ecb7f7 | |||
| bd02f079ab |
@@ -28,7 +28,11 @@ import (
|
|||||||
var nodeApp = app.New()
|
var nodeApp = app.New()
|
||||||
|
|
||||||
func Run(cmd *cobra.Command, args []string) {
|
func Run(cmd *cobra.Command, args []string) {
|
||||||
nodeApp.InitialHooks()
|
nodeApp.InitialHooks(
|
||||||
|
Init0Hook, Init1Hook, Init2Hook,
|
||||||
|
Init3Hook, Init4Hook, Init5Hook,
|
||||||
|
Init6Hook,
|
||||||
|
)
|
||||||
|
|
||||||
nodeApp.Run(RunHook)
|
nodeApp.Run(RunHook)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ func (h *HandlerV1) Handle(r *http.Request, req *rpc.RPCRequest) *rpc.RPCRespons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return h.HandleLUA(method, req)
|
return h.handleLUA(method, req)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/akyaiy/GoSally-mvp/internal/core/utils"
|
|
||||||
"github.com/akyaiy/GoSally-mvp/internal/engine/logs"
|
"github.com/akyaiy/GoSally-mvp/internal/engine/logs"
|
||||||
"github.com/akyaiy/GoSally-mvp/internal/server/rpc"
|
"github.com/akyaiy/GoSally-mvp/internal/server/rpc"
|
||||||
lua "github.com/yuin/gopher-lua"
|
lua "github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *HandlerV1) HandleLUA(path string, req *rpc.RPCRequest) *rpc.RPCResponse {
|
|
||||||
|
|
||||||
|
func (h *HandlerV1) handleLUA(path string, req *rpc.RPCRequest) *rpc.RPCResponse {
|
||||||
L := lua.NewState()
|
L := lua.NewState()
|
||||||
defer L.Close()
|
defer L.Close()
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ func (h *HandlerV1) HandleLUA(path string, req *rpc.RPCRequest) *rpc.RPCResponse
|
|||||||
paramsTable := L.NewTable()
|
paramsTable := L.NewTable()
|
||||||
if fetchedParams, ok := req.Params.(map[string]any); ok {
|
if fetchedParams, ok := req.Params.(map[string]any); ok {
|
||||||
for k, v := range fetchedParams {
|
for k, v := range fetchedParams {
|
||||||
L.SetField(paramsTable, k, utils.ConvertGolangTypesToLua(L, v))
|
L.SetField(paramsTable, k, ConvertGolangTypesToLua(L, v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
L.SetField(inTable, "Params", paramsTable)
|
L.SetField(inTable, "Params", paramsTable)
|
||||||
@@ -34,29 +35,20 @@ func (h *HandlerV1) HandleLUA(path string, req *rpc.RPCRequest) *rpc.RPCResponse
|
|||||||
|
|
||||||
logTable := L.NewTable()
|
logTable := L.NewTable()
|
||||||
|
|
||||||
L.SetField(logTable, "Info", L.NewFunction(func(L *lua.LState) int {
|
logFuncs := map[string]func(string, ...any){
|
||||||
msg := L.ToString(1)
|
"Info": h.x.SLog.Info,
|
||||||
h.x.SLog.Info(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
"Debug": h.x.SLog.Debug,
|
||||||
return 0
|
"Error": h.x.SLog.Error,
|
||||||
}))
|
"Warn": h.x.SLog.Warn,
|
||||||
|
}
|
||||||
|
|
||||||
L.SetField(logTable, "Debug", L.NewFunction(func(L *lua.LState) int {
|
for name, logFunc := range logFuncs {
|
||||||
msg := L.ToString(1)
|
L.SetField(logTable, name, L.NewFunction(func(L *lua.LState) int {
|
||||||
h.x.SLog.Debug(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
msg := L.ToString(1)
|
||||||
return 0
|
logFunc(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
||||||
}))
|
return 0
|
||||||
|
}))
|
||||||
L.SetField(logTable, "Error", L.NewFunction(func(L *lua.LState) int {
|
}
|
||||||
msg := L.ToString(1)
|
|
||||||
h.x.SLog.Error(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
|
||||||
return 0
|
|
||||||
}))
|
|
||||||
|
|
||||||
L.SetField(logTable, "Warn", L.NewFunction(func(L *lua.LState) int {
|
|
||||||
msg := L.ToString(1)
|
|
||||||
h.x.SLog.Warn(fmt.Sprintf("the script says: %s", msg), slog.String("script", path))
|
|
||||||
return 0
|
|
||||||
}))
|
|
||||||
|
|
||||||
L.SetField(logTable, "Event", L.NewFunction(func(L *lua.LState) int {
|
L.SetField(logTable, "Event", L.NewFunction(func(L *lua.LState) int {
|
||||||
msg := L.ToString(1)
|
msg := L.ToString(1)
|
||||||
@@ -120,7 +112,7 @@ func (h *HandlerV1) HandleLUA(path string, req *rpc.RPCRequest) *rpc.RPCResponse
|
|||||||
|
|
||||||
out := make(map[string]any)
|
out := make(map[string]any)
|
||||||
resultTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
resultTbl.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||||
out[key.String()] = utils.ConvertLuaTypesToGolang(value)
|
out[key.String()] = ConvertLuaTypesToGolang(value)
|
||||||
})
|
})
|
||||||
|
|
||||||
out["responsible-node"] = h.cs.UUID32
|
out["responsible-node"] = h.cs.UUID32
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils
|
package sv1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -17,7 +17,6 @@ func ConvertLuaTypesToGolang(value lua.LValue) any {
|
|||||||
case lua.LTTable:
|
case lua.LTTable:
|
||||||
tbl := value.(*lua.LTable)
|
tbl := value.(*lua.LTable)
|
||||||
|
|
||||||
// Попробуем как массив
|
|
||||||
var arr []any
|
var arr []any
|
||||||
isArray := true
|
isArray := true
|
||||||
tbl.ForEach(func(key, val lua.LValue) {
|
tbl.ForEach(func(key, val lua.LValue) {
|
||||||
Reference in New Issue
Block a user