| 292 | } |
| 293 | |
| 294 | func (s *script) runFunc(name string, f filters.FilterContext) { |
| 295 | L, err := s.getState() |
| 296 | if err != nil { |
| 297 | log.Errorf("Error obtaining lua environment: %v", err) |
| 298 | return |
| 299 | } |
| 300 | defer s.putState(L) |
| 301 | |
| 302 | pt := L.CreateTable(len(s.routeParams), len(s.routeParams)) |
| 303 | for i, p := range s.routeParams { |
| 304 | k, v, _ := strings.Cut(p, "=") |
| 305 | pt.RawSetString(k, lua.LString(v)) |
| 306 | pt.RawSetInt(i+1, lua.LString(p)) |
| 307 | } |
| 308 | |
| 309 | err = L.CallByParam( |
| 310 | lua.P{ |
| 311 | Fn: L.GetGlobal(name), |
| 312 | NRet: 0, |
| 313 | Protect: true, |
| 314 | }, |
| 315 | s.filterContextAsLuaTable(L, f), |
| 316 | pt, |
| 317 | ) |
| 318 | if err != nil { |
| 319 | log.Errorf("Error calling %s from %s: %v", name, s.source, err) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func (s *script) filterContextAsLuaTable(L *lua.LState, f filters.FilterContext) *lua.LTable { |
| 324 | // this will be passed as parameter to the lua functions |