mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 20:12:25 +00:00
Compare commits
2 Commits
35cebee819
...
095b8559f4
| Author | SHA1 | Date | |
|---|---|---|---|
| 095b8559f4 | |||
| 39532f22ea |
@@ -99,11 +99,19 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
||||
})
|
||||
|
||||
fetchedParamsTable := L.NewTable()
|
||||
if fetchedParams, ok := req.Params.(map[string]any); ok {
|
||||
for k, v := range fetchedParams {
|
||||
switch params := req.Params.(type) {
|
||||
case map[string]any:
|
||||
for k, v := range params {
|
||||
L.SetField(fetchedParamsTable, k, ConvertGolangTypesToLua(L, v))
|
||||
}
|
||||
case []any:
|
||||
for i, v := range params {
|
||||
fetchedParamsTable.RawSetInt(i+1, ConvertGolangTypesToLua(L, v))
|
||||
}
|
||||
default:
|
||||
L.SetField(fetchedParamsTable, "_", ConvertGolangTypesToLua(L, params))
|
||||
}
|
||||
|
||||
|
||||
paramsGetter := L.NewFunction(func(L *lua.LState) int {
|
||||
path := L.OptString(1, "")
|
||||
@@ -517,13 +525,7 @@ func (h *HandlerV1) handleLUA(sid string, r *http.Request, req *rpc.RPCRequest,
|
||||
|
||||
resultVal := outTbl.RawGetString("result")
|
||||
if resultVal != lua.LNil {
|
||||
payload := make(map[string]any)
|
||||
if tbl, ok := resultVal.(*lua.LTable); ok {
|
||||
tbl.ForEach(func(k, v lua.LValue) { payload[k.String()] = ConvertLuaTypesToGolang(v) })
|
||||
} else {
|
||||
return rpc.NewResponse(ConvertLuaTypesToGolang(resultVal), req.ID)
|
||||
}
|
||||
return rpc.NewResponse(payload, req.ID)
|
||||
return rpc.NewResponse(ConvertLuaTypesToGolang(resultVal), req.ID)
|
||||
}
|
||||
return rpc.NewResponse(nil, req.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user