You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Lua filters call an entrypoint function either in-line (code) or from a file (script). Code within the entrypoint function can call other functions within the same block/file. However, those other functions are not sharable across different filters:
Inline example:
pipeline:
filters:
# WORKS
- name: luamatch: appxmlcall: entrypointcode: | function shared_function(someInput) -- Do something end function entrypoint(tag, timestamp, record) bleep = shared_function(bloop) end# DOES NOT WORK
- name: luamatch: appxmlcall: other_entrypointcode: | function other_entrypoint(tag, timestamp, record) bleep = shared_function(bloop) -- ^ FAILS! `attempt to call global 'shared_function' (a nil value)` end
For maintainability purposes, it can be desirable to define lua functions that get re-used in a single location, rather than duplicated across multiple filters.
Describe the solution you'd like
Provide the ability to include lua code in a more global context that can be accessed by multiple different filters. Perhaps by including all functions from a lua file:
includes.lua:
function shared_function(someInput)
-- Do something
end
pipeline:
filters:
- name: lua
match: appxml
include: includes.lua
call: entrypoint
code: |
function entrypoint(tag, timestamp, record)
blah = shared_function(something)
-- some things
end
filters:
- name: lua
match: appxml
include: includes.lua
call: do_something_else
code: |
function do_something_else(tag, timestamp, record)
blah = shared_function(something)
-- do some other things
end
Describe alternatives you've considered
It is possible although somewhat dubious to define lua code within a variable, then re-use that variable within individual lua filters:
env:
SOME_SHARED_FUNCTION: |
function shared_function(input)
-- do something
end
pipeline:
filters:
- name: lua
match: appxml
call: entrypoint
code: |
function entrypoint(someInput)
${SOME_SHARED_FUNCTION}
blah = shared_function(something)
-- do some other things
end
Additional context
While code can currently be placed inside an external .lua file and called in the filter via script from multiple filters, no custom input can be provided to the entrypoint function in each filter, it only taking (tag, timestamp, record). Providing 'includes' seems to be a versatile solution, since any custom input could be defined in the filter's code block, the shared code being loaded from the external file mentioned inincludes
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Lua filters call an entrypoint function either in-line (
code
) or from a file (script
). Code within the entrypoint function can call other functions within the same block/file. However, those other functions are not sharable across different filters:Inline example:
For maintainability purposes, it can be desirable to define lua functions that get re-used in a single location, rather than duplicated across multiple filters.
Describe the solution you'd like
Provide the ability to include lua code in a more global context that can be accessed by multiple different filters. Perhaps by including all functions from a lua file:
includes.lua:
pipeline:
Describe alternatives you've considered
It is possible although somewhat dubious to define lua code within a variable, then re-use that variable within individual lua filters:
Additional context
While code can currently be placed inside an external .lua file and called in the filter via
script
from multiple filters, no custom input can be provided to the entrypoint function in each filter, it only taking (tag, timestamp, record). Providing 'includes' seems to be a versatile solution, since any custom input could be defined in the filter'scode
block, the shared code being loaded from the external file mentioned inincludes
The text was updated successfully, but these errors were encountered: