Module:Sandbox: Difference between revisions

From Tildeverse Wiki
(Replaced content with "local M = {} function M.hello(F) local whom = F.args[1] if whom == nil then return 'Hi!' end return Hello, .. whom .. '!' end function M:fizzbuzz() local r = ''...")
Tag: Replaced
(list to table)
Line 26: Line 26:


local members = mw.loadData [[Module:Sandbox/data]]
local members = mw.loadData [[Module:Sandbox/data]]
local tildes = {}
for _, v in ipairs(members) do
table.insert(tildes, '* [[' .. v.name .. ']]')
end


M.list = function()
M.list = function()
return table.concat(tildes, "\n")
    local tbl = [=[
{|class="wikitable"|
! Name
! Description
! OS
! Link]=]
    for _, v in ipairs(members) do
    local s = "|-\n| " .. table.concat({ v.name, v.description, v.os, v.link}, "\n| ")
    tbl = tbl .. "\n" .. s
    end
    tbl = tbl .. "\n|}"
return tbl
end
end


return M
return M

Revision as of 13:37, 6 June 2021

Documentation for this module may be created at Module:Sandbox/doc

local M = {}

function M.hello(F)
	local whom = F.args[1]
	if whom == nil then return 'Hi!' end
	return [[Hello, ]] .. whom .. '!'
end

function M:fizzbuzz()
	local r = ''
	for i = 1, 100 do
		local s = ''
		if i % 3 == 0 then
			s = s .. 'Fizz'
		end
		if i % 5 == 0 then
			s = s .. 'Buzz'
		end
		if s == '' then
			s = s .. i
		end
		r = r .. s .. "\n"
	end
	return r
end

local members = mw.loadData [[Module:Sandbox/data]]

M.list = function()
    local tbl = [=[
{|class="wikitable"|
! Name
! Description
! OS
! Link]=]
    for _, v in ipairs(members) do
    	local s = "|-\n| " .. table.concat({ v.name, v.description, v.os, v.link}, "\n| ")
	    tbl = tbl .. "\n" .. s
    end
    tbl = tbl .. "\n|}"
	return tbl
end

return M