Wikipedia talk:Lua#Can't get require() working

{{WikiProject Lua header|sc1=WT:LUA}}

{{central|text=all Wikipedia:Lua subpages' talk pages and Help talk:Lua redirect here.}}

{{merged-from|Wikipedia:Lua/Requests|5 February 2016|talk=no|target=Wikipedia talk:Lua}}

{{Old MfD|date=21 May 2015|page=Wikipedia:Lua/To do|altpage=Wikipedia:Lua/To do|result=keep}}

{{archive box

|search=yes

|bot=ClueBot III

|1={{flatlist}}

Current archives:

{{User:ClueBot III/ArchiveThis

|archiveprefix=Wikipedia talk:Lua/Archive

|format= %%i

|age=2160

|archivebox=no

|index=yes

|maxarchsize=150000

|minkeepthreads=1

}}

Requests archives:

Other:

{{endflatlist}}

}}

Module calling Wikidata to list European parties' seats in various institutions

Hi,

Total newbie to Lua here (but happy to discover)! Here, I asked for help to make a template that would grab information from Wikidata (using the wikidata module and expressions using that module) based on two arguments (the name of the institution and the name of a party -- or some wildcards).

@Ahecht kindly responded with a proposal, but saying that the conditional structure I was looking for would be better achieved in Lua. Since this looked like a good opportunity to make something better and to learn, I thought I would come here and ask for support.

I won't recap the whole proposal here for the sake of brevity (but the above link should be clear enough, hopefully), but I welcome ideas and pointers! Thanks a lot in advance. Julius Schwarz (talk) 19:32, 17 March 2025 (UTC)

:Any ideas? Julius Schwarz (talk) 06:01, 21 March 2025 (UTC)

::Your code from the original thread would work. Lua is just written with the long form of if statements, so "else if", not "elif" like in python. Also, unlike python, you have to use the word "end" at the end of the if statement, it will not take into account the indentation like python does.

::You could just put your original code with some minor adjustment like that into a function, return the function, save it into the Module namespace and use it with {{#invoke: