Difference between revisions of "Module:Sandbox/Erutuon/random"

From blackwiki
Jump to navigation Jump to search
blackwiki>Erutuon
(there)
m (31 revisions imported)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
require("Module:No globals")
 
 
 
local p = {}
 
local p = {}
  
function p.test(frame)
+
local Out_mt = {}
local word = frame.args[1] == "print" and "Printing is allowed"
+
Out_mt.__index = Out_mt
return word
 
end
 
  
function p.currentFrame(frame)
+
function Out_mt:add(...)
local currentFrame = mw.getCurrentFrame(frame)
+
for i = 1, select('#', ...) do
local frameTable = {}
+
self.i = self.i + 1
for k, v in pairs(currentFrame) do
+
self[self.i] = select(i, ...)
frameTable[k] = v
 
 
end
 
end
return frameTable and table.concat(frameTable, ", ") or "nil"
 
 
end
 
end
  
function p.namespace(frame)
+
function Out_mt:__tostring()
return frame:getParent():getTitle() .. " " .. mw.title.getCurrentTitle().nsText
+
return table.concat(self)
 
end
 
end
  
function p.parameterContent(frame)
+
function Out()
local parameter = frame.args[1]
+
local o = setmetatable({}, Out_mt)
return parameter == "" and "Parameter is empty." or parameter == nil and "Parameter is nil." or "Parameter contains <code>" .. parameter .. "</code>."
+
o.i = 0
 +
return o
 
end
 
end
  
function p.gmatch(frame)
+
function p.show(frame)
local parameter = frame.args[1]
+
local out = Out()
local array = {}
+
local n = 0
+
local language_data = require 'Module:Language/data'
for number in string.gmatch(parameter, "%d+") do
+
local Wiktionary = {
n = n + 1
+
name_to_code = require 'Module:Language/Wiktionary name to code',
array[n] = number or "blah"
+
code_to_name = require 'Module:Language/Wiktionary code to name',
 +
}
 +
 +
for code, data in require 'Module:TableTools'.sortedPairs(language_data.languages) do
 +
if not Wiktionary.code_to_name[code] then
 +
out:add(code)
 +
local Wiktionary_code = data.name and Wiktionary.name_to_code[data.name]
 +
if Wiktionary_code then
 +
out:add(' &rarr; ', Wiktionary_code)
 +
local MediaWiki_name = mw.language.fetchLanguageName(Wiktionary_code, 'en')
 +
if MediaWiki_name ~= data.name then
 +
out:add(' (MediaWiki: ',
 +
MediaWiki_name ~= '' and MediaWiki_name or '<none>',
 +
', Wiktionary: ', data.name, ')')
 +
end
 +
end
 +
out:add('\n* ')
 +
elseif data.name and data.name == mw.language.fetchLanguageName(code, 'en') then
 +
out:add(code, ' (', data.name, ')')
 +
out:add('\n* ')
 +
end
 
end
 
end
return n .. " " .. array[n] .. " " .. table.concat(array, ", ")
+
end
+
return out
 
 
function p.args(frame)
 
local currentargs = mw.getCurrentFrame().args
 
local args = mw.getCurrentFrame():getParent().args[1] and mw.getCurrentFrame():getParent().args
 
local out = (args) and args[1]..args[2]..args[3]..": parentargs" or (currentargs[1] and currentargs[2] and currentargs[3]) and currentargs[1]..currentargs[2]..currentargs[3]..": args"
 
return out .. (args == nil and ". no parentargs" or "")
 
 
end
 
end
  
 
return p
 
return p

Latest revision as of 09:46, 27 September 2020

Test

  • Lua error in package.lua at line 80: module 'Module:Language/Wiktionary name to code' not found.



local p = {}

local Out_mt = {}
Out_mt.__index = Out_mt

function Out_mt:add(...)
	for i = 1, select('#', ...) do
		self.i = self.i + 1
		self[self.i] = select(i, ...)
	end
end

function Out_mt:__tostring()
	return table.concat(self)
end

function Out()
	local o = setmetatable({}, Out_mt)
	o.i = 0
	return o
end

function p.show(frame)
	local out = Out()
	
	local language_data = require 'Module:Language/data'
	local Wiktionary = {
		name_to_code = require 'Module:Language/Wiktionary name to code',
		code_to_name = require 'Module:Language/Wiktionary code to name',
	}
	
	for code, data in require 'Module:TableTools'.sortedPairs(language_data.languages) do
		if not Wiktionary.code_to_name[code] then
			out:add(code)
			local Wiktionary_code = data.name and Wiktionary.name_to_code[data.name]
			if Wiktionary_code then
				out:add(' &rarr; ', Wiktionary_code)
				local MediaWiki_name = mw.language.fetchLanguageName(Wiktionary_code, 'en')
				if MediaWiki_name ~= data.name then
					out:add(' (MediaWiki: ',
						MediaWiki_name ~= '' and MediaWiki_name or '<none>',
						', Wiktionary: ', data.name, ')')
				end
			end
			out:add('\n* ')
		elseif data.name and data.name == mw.language.fetchLanguageName(code, 'en') then
			out:add(code, ' (', data.name, ')')
			out:add('\n* ')
		end
	end
	
	return out
end

return p