Module:Existsmod

--

-- An inexpensive alternative to which looks for a given module, -- and returns one of two values depending on whether it was found. -- -- Syntax: --

local p = {}

local checkType = require("libraryUtil").checkType local normalize = require("Dev:NormalizeModuleName") local getArgs = require("Dev:Arguments").getArgs

function p.module_exists(name, foundVal, missingVal) checkType("Dev:Existsmod", 1, name, "string", true)

if name then name = table.concat{normalize(name)}

if package.loaded[name] then return foundVal else local _, val = pcall(package.loaders[2], name)

if type(val) == "function" or type(val) == "string" then return foundVal end end end

return missingVal end

function p.main(frame) local args = getArgs(frame)

return p.module_exists(args[1], args[2], args[3]) end

return p

-- -- (Add categories here.)