RolandUnger
Beigetreten 9. Juni 2006
Inhalt gelöscht Inhalt hinzugefügt
Zeile 253:
::::::I'm not able to develop anything better than this in order to have a function that can work with both LUA functions and templates. Let me know your thoughts.
::::::Now I've also understood better your above "ad1". According to your larger experience, which approach it's better (if any) between "ad1" (i.e. having two separate functions) and the above code (i.e. having one single function for both cases)? --[[Benutzer:Andyrom75|<span style="color:#BB0000; font-family:Papyrus; font-size:12px">'''Andyrom75'''</span>]] ([[Benutzer Diskussion:Andyrom75|Diskussion]]) 20:41, 16. Nov. 2021 (CET)
:Sorry for disturbing you again with the same noob/academic question, but I've noticed that both approach have some missing parts. So I've tried to extend them according to my current knowledge.
:Brief introduction of the problem. Each function can be called in "three different" ways, not "two equivalent" as I've initially supposed.
:# from a wiki-template
:# from an invoke inside a wiki-template
:# from a LUA function
:That said, considering that for the main body of the module, I need both args parameters and frame object (properly created), I've developed the following two approaches, tested in [[:it:Utente:Andyrom75/Sandbox/test#Test]]
:# Unique function that can be called in any way
:# Three different interface functions that will call a single process function
:'''Approach 1''' (see [[:it:Modulo:Marker]]): more flexible than the following one, but spend more time to guess the correct context
:<syntaxhighlight lang="lua">function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function p.Marker(frame)
local args = frame.args
frame = mw.getCurrentFrame():getParent()
if frame and (tablelength( frame.args ) > 0) then --WIKI-TEMPLATE CASE
args = frame.args
else
frame = mw.getCurrentFrame()
if frame and (tablelength( frame.args ) > 0) then --INVOKE CASE
args = frame.args
end
end
...
end</syntaxhighlight>
:'''Approach 2''' (see [[:it:Modulo:Marker/sandbox]]): no need to "guess" the case, hence is quicker than previous one, but has three interfaces
:<syntaxhighlight lang="lua">function p.MarkerTemplate()
return _Marker(mw.getCurrentFrame():getParent())
end
function p.MarkerInvoke()
return _Marker(mw.getCurrentFrame())
end
function p.MarkerModule(frame)
local args = frame.args
frame = mw.getCurrentFrame()
frame.args = args
return _Marker(frame)
end
</syntaxhighlight>
:What do you think? Do you see any improvement on both approaches?
:Furthermore, any preference? --[[Benutzer:Andyrom75|<span style="color:#BB0000; font-family:Papyrus; font-size:12px">'''Andyrom75'''</span>]] ([[Benutzer Diskussion:Andyrom75|Diskussion]]) 16:00, 21. Nov. 2021 (CET)
== z-index ==
|