Module:Constructor

--Get Required Modules local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') local lu = require('Module:LibraryUtil') local yesno = require('Module:Yesno') local table = require('Module:Table')

local checkType, checkType, setRequiredArgs, customArgError = unpack{ lu.checkType, lu.checkType, lu.setRequiredArgs, lu.customArgError, }

--Begin Exports local NaN = 0/0 math.NaN = NaN math.Infinity = math.huge _G.Infinity = math.huge _G.NaN = NaN

function _G.isNaN(v) return type(v) == "number" and tostring(v) == "-nan" end

local function makeStaticMethods(t) local tmp = {}

table.each(t, function(v, k)		tmp[k] = { 'static', v }	end) return tmp end

local function length(v) if pcall(table.length, v) then return table.length(v) elseif pcall(string.len, v) then return string.len(v) elseif v == true then return 1 elseif type(v) == "number" then return v	else return 0 end end

(function	tmp = makeStaticMethods(math)	_G.Number = table.makeClass(function(self, n)		local n = n ~= nil and n or 0 local mt = getmetatable(n) or {} if mt.__tonumber then return type(mt.__tonumber) == "function" and mt.__tonumber(n) or mt.__tonumber elseif n == true then return 1 elseif n == false then return 0 elseif n == '' then return 0 elseif tonumber(n) ~= nil then return tonumber(n) elseif type(n) == "string" then return n:len elseif type(n) == "table" then return table.length(n) elseif tonumber(n) == nil then return NaN end end, tmp, nil, { ignoreTableRet=true }) end);

(function	tmp = makeStaticMethods(string)	_G.String = table.makeClass(function(self, v) return tostring(v ~= nil and v or '') end, tmp, nil, { ignore=true })	end);

(function	_G.Boolean = table.makeClass(function(self, v)		local mt = getmetatable(v) or {} if mt.__toboolean then return type(mt.__toboolean) == "function" and mt.__toboolean(v) or mt.__toboolean elseif v == false or v == true then return v		elseif v == nil or v == '' or tonumber(v) == 0 or isNaN(v) then return false elseif tostring(v):lower == "yes" or tostring(v):lower == "y" or tostring(v):lower == "o" or tostring(v):lower == "t" or tostring(v):lower == "tru" or tostring(v):lower == "true" then return true elseif tostring(v):lower == "no" or tostring(v):lower == "n" or tostring(v):lower == "f" or tostring(v):lower == "off" or tostring(v):lower == "fal" or tostring(v):lower == "false" then return false elseif type(v) == "function" or length(v) > 0 then return true else return false end end, { isBoolean = { 'static', function(v) return v == false or v == true end, }, }, nil, { ignore = true })	end);

(function	tmp = makeStaticMethods(table)	_G.Table = table.makeClass(function(self, ...) local t = {} local args = table.pack(... or {}) local mt = getmetatable(args[1]) or {} if table.length(args) <= 2 and mt.__totable and type(args[1]) == "table" then if type(args[2]) == "table" then setmetatable(args[1], args[2]) end return type(mt.__totable) == "function" and mt.__totable(args[1], table.entries(args[1]), table.sortedPairs(args[1]), table.length(args[1])) elseif type(args[1]) == "table" and table.length(args[1]) == 1 then return args[1] end table.each(args, function(v, k)			t[k] = v			end) return t	end, tmp, nil, { ignore=true }) end);

(function	local methods = {}	function methods:callMethod(f, thisArg, ...)		checkType(1, f, 'function')		return f(thisArg, ...)	end

_G.Function = table.makeClass(function(self)		return function end	end, makeStaticMethods(methods), nil, { ignore=true }) end);

--Finish Module/Exports return _G