Module:User:Litzsch/Sandbox

local util = require 'libraryUtil' local checkType = util.checkType local checkTypeMulti = util.checkTypeMulti

local Tabber = {} Tabber.__index = Tabber

local function validateTabs( tabs ) checkType( 'new', 1, tabs, 'table' )

for i,tab in ipairs( tabs ) do   if type( tab ) ~= 'table' or #tab > 2 then error( string.format( "invalid tab at index '%s'", i ), 2 ) end end end

function Tabber:new( tabs ) checkType( 'new', 1, tabs, 'table', true )

local tbbr = {} setmetatable( tbbr, Tabber ) tbbr.tabs = tabs or {}

validateTabs( tbbr.tabs )

return tbbr end

function Tabber:addTab( page, title ) checkType( 'addTab', 1, page, 'string' ) checkTypeMulti( 'addTab', 2, title, { 'string', 'number', 'nil' } )

self.tabs[#self.tabs+1] = { page, title } end

function Tabber:removeTab( index ) checkType( 'removeTab', 1, index, 'number' )

self.tabs[index] = nil end

return Tabber