Module:Table/sandbox
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
This module is meant for table testing
Module:Table/sandbox/doc for its documentatiom
{{#invoke:Table/sandbox|kitst}}orig tab: cm cn cer bi d9 dk cb ad ar cs ch
{{#invoke:Table/sandbox|kotst}}chgd tab: cm cn cer bi d9 dk cb XY ar cs ch
{{#invoke:Table/sandbox|kstst}}sort out: ad XY XY XY XY XY XY XY XY XY XY
{{#invoke:Table/sandbox|kdtst}}sort tbl: ad ar bi cb cer ch cm cn cs d9 dk
Code
local libraryUtil = require('libraryUtil')
local TableTools = require('Module:TableTools')
local checkType = libraryUtil.checkType
--local checkTypeMulti = libraryUtil.checkTypeMulti
local utab = {};
local p = {}
utab =
{
-- user: 1 2 3 4 5 gc sd U,u su ca
ad = { 'I', nil, 'c', 'gf', nil, ':Adalric67', nil, 'Adalric67' };
ar = { 'I', nil, 'c', 'gf', nil, ':Aroche', nil, 'Aroche' };
bi = { 'I', nil, 'c', 'gf', nil, ':Bibar', nil, 'Bibar' }; -- nil, '-Blasons' };
cb = { 'I', nil, 'c', 'gf', nil, ':Celbusro', nil, 'Celbusro' };
cer = { 'I', nil, 'ce','gf', nil, ':Chatsam' };
ch = { 'I', nil, 'c', 'gf', nil, ':Chatsam', nil, nil,'Chatsam', nil, 'Blason chatsam' };
cm = { 'DrawShield', nil, 'c', 'ei', nil, nil, nil,'Charles Matthews' };
cn = { 'I', nil, 'c', 'gf', nil, ':Caranorn', nil, ' Caranorn' };
cs = { 'I', nil, 'c', nil, nil, nil, nil, nil,'Chris die Seele', 'CoA by Chris die Seele' };
d9 = { 'Im', '5', 'c', nil, nil, nil, nil, 'Delta-9' };
dk = { 'I', nil, 'c', nil, nil, nil, nil, nil,'Dan Koehl', nil, 'Coats of arms by Dan Koehl'};
-- etc.
}
--------------------------------------------------------------------------------
local function gsort ( ixtab ) -- local function --
local minm = ixtab[1]; -- assume it's rel. min.
local minx = 1;
for linx = 1, #ixtab do
-- if ixtab[linx] ~= 'ZZ' then
if minm > ixtab[linx] then --
minm = ixtab[linx] -- rel. min.
minx = linx --
end
-- end
end
return minx; -- return the rel. minimal element index
end -- local function gsort
--------------------------------------------------------------------------------
function p.kotst ( frame ) -- KeysToList --
local ixtab = {}
local elem = '';
local rval = '';
local indx = 1
local checkType = libraryUtil.checkType;
local checkTypeMulti = libraryUtil.checkTypeMulti
checkType('keysToList', 1, utab, 'table')
checkTypeMulti('keysToList', 2, nil, { 'function', 'boolean', 'nil' })
for key, value in pairs(utab) do
ixtab[indx] = key;
indx = indx + 1;
end
for l = 1, #ixtab do
-- rval = rval .. ' ' .. gsort (ixtab, l); -- ()
indx = gsort (ixtab);
ixtab [indx] = 'XY';
end
for l = 1, #ixtab do
rval = rval .. ' ' .. ixtab[l] ; -- ()
end
return rval; -- output changed table
end -- function
--------------------------------------------------------------------------------
function p.kstst ( frame ) -- KeysToList --
local ixtab = {}
local elem = '';
local rval = '';
local indx = 1
local checkType = libraryUtil.checkType;
local checkTypeMulti = libraryUtil.checkTypeMulti
checkType('keysToList', 1, utab, 'table')
checkTypeMulti('keysToList', 2, nil, { 'function', 'boolean', 'nil' })
for key, value in pairs(utab) do
ixtab[indx] = key;
indx = indx + 1;
end
for l = 1, #ixtab do
-- rval = rval .. ' ' .. gsort (ixtab, l); -- ()
indx = gsort (ixtab);
rval = rval .. ' ' .. ixtab [indx];
elem = ixtab [indx];
ixtab [indx] = 'XY';
end
return rval; -- output after sort
end -- function
--------------------------------------------------------------------------------
function p.kltst ( frame ) -- KeysToList sort --
local ixtab = {};
local rval = '';
local index = 1;
local keylist = TableTools.keysToList
-- keylist(utab);
xtab = TableTools.keysToList(utab, nil);
for l = 1, 11 do
rval = rval .. ' ' .. ixtab (l); --
end
return rval; -- output after sort
end -- function
--------------------------------------------------------------------------------
function p.ktest ( frame ) -- ut --
local ixtab = {};
local rval = '';
local index = 1;
local checkType = libraryUtil.checkType;
local checkTypeMulti = libraryUtil.checkTypeMulti
checkType('keysToList', 1, utab, 'table')
checkTypeMulti('keysToList', 2, nil, { 'function', 'boolean', 'nil' })
for key, value in pairs(utab) do
ixtab[index] = key;
index = index + 1;
end
for l = 1, #ixtab do
if ixtab[l] == nil then
rval = rval .. ' ∅ ' ;
else
rval = rval .. ' ' .. ixtab[l];
end
end
return rval; -- output without sort
end -- function
--------------------------------------------------------------------------------
function p.tltst ( frame ) -- local --
local tltab = { 'k1', 'k2', 'k3', 'k4', 'k5', 'k6', 'k7', 'k8', 'k9', 'kA', 'kB' };
local rval = '';
for l = 1, 11 do --
rval = rval .. ' ' .. tltab[l]
end
return rval;
end -- function
--------------------------------------------------------------------------------
function p.kitst ( frame ) -- KeysToList --
local rval = '';
local checkType = libraryUtil.checkType;
local checkTypeMulti = libraryUtil.checkTypeMulti
checkType('keysToList', 1, utab, 'table')
checkTypeMulti('keysToList', 2, nil, { 'function', 'boolean', 'nil' })
for key, value in pairs(utab) do
rval = rval .. ' ' .. key; --
end
return rval; -- output original table
end -- function
-------------------------------------------------------------------------------
function p.kdtst ( frame ) -- KeysToList --
local ixtab = {};
local rval = '';
local index = 1;
local checkType = libraryUtil.checkType;
--local checkTypeMulti = libraryUtil.checkTypeMulti
checkType('keysToList', 1, utab, 'table')
-- checkTypeMulti('keysToList', 2, nil, { 'function', 'boolean', 'nil' })
for key, value in pairs(utab) do
ixtab[index] = key;
index = index + 1;
end
keySort = type(keySort) == 'function' and keySort or defaultKeySort
table.sort(ixtab)
for l = 1, #ixtab do
rval = rval .. ' ' .. ixtab [l]; --
end
return rval; -- output after sort
end -- function
--------------------------------------------------------------------------------
return p;