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

From blackwiki
Jump to navigation Jump to search
blackwiki>Erutuon
blackwiki>Erutuon
(convenient output class)
Line 1: Line 1:
require("Module:No globals")
+
local p = {}
  
local p = {}
+
local Out_mt = {}
 +
Out_mt.__index = Out_mt
 +
 
 +
function Out_mt:add(item)
 +
self.i = self.i + 1
 +
self[self.i] = item
 +
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)
 
function p.show(frame)
local content = mw.title.new
+
local out = Out()
"Template:ISO 15924 script codes and related Unicode data"
+
out:add('hello')
:getContent()
+
return out
 
local Unicode_script_codes = {}
 
local i = 0
 
for script_code in content:gmatch("{{ISO 15924[^|]+|([^}]+)") do
 
i = i + 1
 
Unicode_script_codes[i] = script_code
 
end
 
 
return require "Module:dump"._dump(Unicode_script_codes)
 
 
end
 
end
  
 
return p
 
return p

Revision as of 21:58, 26 May 2018

Test

  • hello



local p = {}

local Out_mt = {}
Out_mt.__index = Out_mt

function Out_mt:add(item)
	self.i = self.i + 1
	self[self.i] = item
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()
	out:add('hello')
	return out
end

return p