Module:Test: Difference between revisions
Jump to navigation
Jump to search
KokoroSenshi (talk | contribs) m (hmm the previous one // return p.func( { args = { "something" } } ) // isn't good for readability I think) |
KokoroSenshi (talk | contribs) m (Converted the test function (that converts text to hylian, gerudo, etc.) to use a function that gives the individual character image) |
||
Line 38: | Line 38: | ||
end | end | ||
-- | --like Template:HylianALBW/Letter | ||
function p. | function p.getChar( frame ) | ||
local game = frame.args[1] | |||
local char = frame.args[2] | |||
local size = frame.args[3] | |||
char = char:upper() | |||
--char = string.upper(char) | |||
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Control_structures | |||
--No case-switch in Lua | |||
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Relational_operators | |||
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Logical_operators | |||
--https://stackoverflow.com/questions/27633331/can-i-check-strings-equality-in-lua#27634079 | |||
local letter = char | |||
if game == 'SS' then | |||
if char == 'D' or char == 'W' then letter = 'DW' | |||
elseif char == 'E' or char == 'K' then letter = 'EK' | |||
elseif char == 'O' or char == 'Z' then letter = 'OZ' | |||
end | |||
elseif game == 'ALBW' then | |||
if char == 'D' or char == 'G' then letter = 'DG' | |||
elseif char == 'F' or char == 'R' then letter = 'FR' | |||
elseif char == 'J' or char == 'T' then letter = 'JT' | |||
elseif char == 'E' or char == 'W' then letter = 'EW' | |||
elseif char == 'O' or char == 'Z' then letter = 'OZ' | |||
end | |||
end | |||
local ext = 'png' | |||
if game == 'ALBW' then ext = 'svg' end | |||
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Concatenation_operator | |||
return '<span class="tooltip" title="' .. char .. '">[[File:' .. game .. ' ' .. letter .. '.' .. ext .. '|x' .. size .. 'px|link=]]</span>' | |||
end | |||
--like Template:HylianALBW | |||
function p.getWord( frame ) | |||
---- | ---- | ||
-- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual | -- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual | ||
Line 70: | Line 106: | ||
--local char = string.sub(word,i,i) | --local char = string.sub(word,i,i) | ||
--local char = word.sub(word,i,i) | --local char = word.sub(word,i,i) | ||
-- | --argument formatted like a frame object: | ||
t[i+1] = p.getChar({args={ game, char, size }}) | |||
t[i+1] = | |||
i = i+1 | i = i+1 | ||
Line 116: | Line 128: | ||
--should return something when #invoked | --should return something when #invoked | ||
function p.funcDriver( frame ) | function p.funcDriver( frame ) | ||
--nope--f.args[1] = "something" | --nope--local f.args[1] = "something" | ||
--f = {} | --local f = {} | ||
--f.args = {} | --f.args = {} | ||
--f.args[1] = "something" | --f.args[1] = "something" | ||
--f = {} | --local f = {} | ||
--f.args = { "something" } | --f.args = { "something" } | ||
--return p.func( { args = { "something" } } ) | --return p.func( { args = { "something" } } ) | ||
---f = { args = { <insert csv list of arguments to p.func here> } } | ---local f = { args = { <insert csv list of arguments to p.func here> } } | ||
f = { args = { "something" } } | local f = { args = { "something" } } | ||
return p.func( f ) | return p.func( f ) | ||
end | end | ||
return p | return p |
Revision as of 09:43, 6 August 2017
Documentation for this module may be created at Module:Test/Documentation
local p = {}
--Hello, world!
function p.hello( frame )
return "Hello, world!"
end
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#table
function p.tabletest( frame )
-- Create table
t = {}
t["foo"] = "foo"
t.bar = "bar"
t[1] = "one"
t[2] = "two"
t[3] = "three"
t[12] = "the number twelve"
t["12"] = "the string twelve"
t[true] = "true"
t[tonumber] = "yes, even functions may be table keys"
t[t] = "yes, a table may be a table key too. Even in itself."
-- This creates a table roughly equivalent to the above
t2 = {
foo = "foo",
bar = "bar",
"one",
"two",
[12] = "the number twelve",
["12"] = "the string twelve",
"three",
[true] = "true",
[tonumber] = "yes, even functions may be table keys",
}
t2[t2] = "yes, a table may be a table key too. Even in itself."
end
--like Template:HylianALBW/Letter
function p.getChar( frame )
local game = frame.args[1]
local char = frame.args[2]
local size = frame.args[3]
char = char:upper()
--char = string.upper(char)
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Control_structures
--No case-switch in Lua
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Relational_operators
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Logical_operators
--https://stackoverflow.com/questions/27633331/can-i-check-strings-equality-in-lua#27634079
local letter = char
if game == 'SS' then
if char == 'D' or char == 'W' then letter = 'DW'
elseif char == 'E' or char == 'K' then letter = 'EK'
elseif char == 'O' or char == 'Z' then letter = 'OZ'
end
elseif game == 'ALBW' then
if char == 'D' or char == 'G' then letter = 'DG'
elseif char == 'F' or char == 'R' then letter = 'FR'
elseif char == 'J' or char == 'T' then letter = 'JT'
elseif char == 'E' or char == 'W' then letter = 'EW'
elseif char == 'O' or char == 'Z' then letter = 'OZ'
end
end
local ext = 'png'
if game == 'ALBW' then ext = 'svg' end
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Concatenation_operator
return '<span class="tooltip" title="' .. char .. '">[[File:' .. game .. ' ' .. letter .. '.' .. ext .. '|x' .. size .. 'px|link=]]</span>'
end
--like Template:HylianALBW
function p.getWord( frame )
----
-- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual
-- https://www.lua.org/cgi-bin/demo
----
--Precondition: Assumes no spaces in the string
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Variables
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Frame_object
local game = frame.args[1]
local word = frame.args[2]
local size = frame.args[3]
game = game:upper()
if game == 'BOTW' then game = 'ALBW' end
if size == nil or '' then size = '20' end
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#table
local t = {}
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#string
t[1] = '<span style="display:inline-block; margin:1px 4px;">'
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Length_operator
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Control_structures
local i = 1
repeat
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Function_calls
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#string.sub
local char = word:sub(i,i)
--local char = string.sub(word,i,i)
--local char = word.sub(word,i,i)
--argument formatted like a frame object:
t[i+1] = p.getChar({args={ game, char, size }})
i = i+1
until( i > #word )
t[i+1] = '</span>'
--https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#table.concat
return table.concat(t," ")
end
--should return the first arg when #invoked
function p.func( frame )
return frame.args[1]
end
--should return something when #invoked
function p.funcDriver( frame )
--nope--local f.args[1] = "something"
--local f = {}
--f.args = {}
--f.args[1] = "something"
--local f = {}
--f.args = { "something" }
--return p.func( { args = { "something" } } )
---local f = { args = { <insert csv list of arguments to p.func here> } }
local f = { args = { "something" } }
return p.func( f )
end
return p