OK, I get it. There is several problems indeed. You need to get familiar with programming with modules. There is indeed no "main" function in that module, so the error message is correct.
To call a module within a template, you must provide a function with a single parameter usually called "frame". It's not necessarily called "main" but the name of function must be the the same as used in the #invoke call. You can access the other parameters {{#invoke:youmodule|main|arg1|arg2|plop=bidou}} - here arg1, arg2 and plop thanks through "frame.args". frame.args[1] will have the value "arg1", 2 "arg2" and frame.args["plop"] will have the values "bidou".
The function I wrote don't work like that, so we need to write new one that call my functions.
Such a function would look like
function p.main(frame)
local arg1 = frame.args[1]
local arg2 = frame.args[2]
local plop = frame.args["plop"]
-- The useful code here
end
We kind write several of such functions in a module, for example we could write a second function "show_last_event"
function p.show_last_event(frame)
local start_item = frame.args[1]
local event_type_item = frame.args[2]
local item = p.last_in_sequence(start_item, event_type_item)
-- write here the code to generate a link from an item
return link
end
Now the parameters of my functions needs a start_item and an event type. The start_item could be the Qid of the current season, as time won't turn back, and the event type is the item of the page, probably, as it seem to be the item of the competition class. So we can replace the line local event_type_item = frame.args[2]
with local event_type_item = frame.args[2] or mw.wikibase.getEntityObject()
to set this value by default to the item of the current page.