Module extend_function.lua
Takes the original function and a callback that receives the old function and arguments.
You can decide if you want to call the old function and in which order to do operations.
Usage
local function add (a, b) a + b end local multiplyAWithTwoAndAdd = extend_function(add, function(og, a, b) og(a * 2, b) end)
Functions
-
# returns... (original_fn, extender_fn) -
Parameters
- original_fn function The function being extended
- extender_fn function The function that extends.
Returns
-
function
extended_fn Takes the same arguments as original function
-
# extender_fn () -
Extender function takes the original function as first argument
followed by the arguments the original function takes.
Returns
-
any
Usually similar to the original_fn
-
# extended_fn () -
The wrapper that takes same args as the original fn
Returns
-
Equal to the return of the extender_fn