Difference between revisions of "Module:Common"

From Foundation - Wiki
Jump to navigation Jump to search
(Created page with "--[[ Additional functions that are common to other modules. As they cannot be outside of modules there is no invoke level function calls. ]] local function trim(object) -...")
 
Line 1: Line 1:
--[[  
--[[  
Additional functions that are common to other modules. As they cannot be
Additional functions that are common to other modules. Although they could
outside of modules there is no invoke level function calls.
be called into templates the overhead call into lua would generally greater
than using a built in mediawiki parser function where one exists.
]]
]]


local function trim(object)
local com = {}
 
function com.trim(object)
--Use of while instead of if incase multiple whitespaces are present.
--Use of while instead of if incase multiple whitespaces are present.
while string.sub(object, 1, 1) == ' ' do  
while string.sub(object, 1, 1) == ' ' do  
Line 17: Line 20:
end
end


function exists(object)
function com.exists(object)
if object == nil or object == '' then
if object == nil or object == '' then
return false
return false
Line 24: Line 27:
end
end
end
end
return com

Revision as of 20:09, 23 October 2021

Additional functions that are common to other modules. Although they could be called into templates the overhead call into lua would generally greater than using a built in mediawiki parser function where one exists.

When calling in to another module, use local com = require( "Module:Common"). This will ensure consistency between modules.


--[[ 
	Additional functions that are common to other modules. Although they could
	be called into templates the overhead call into lua would generally greater
	than using a built in mediawiki parser function where one exists.
]]

local com = {}

function com.trim(object)
	--Use of while instead of if incase multiple whitespaces are present.
	while string.sub(object, 1, 1) == ' ' do 
		object = string.sub(object, 2)
	end
	
	while string.sub(object, string.len(object)) == ' ' do
		object = string.sub(object, 1, string.len(object) - 1)
	end
	
	return object
end

function com.exists(object)
	if object == nil or object == '' then
		return false
	else
		return true
	end
end

return com