Anonymous

Module:Shared: Difference between revisions

From Melvor Idle
Move getNamespacedID & getLocalID from Module:GameData, such that modules don't have to require an expensive module to use these functions
(Implement printError())
(Move getNamespacedID & getLocalID from Module:GameData, such that modules don't have to require an expensive module to use these functions)
Line 432: Line 432:
     end
     end
     return resultDesc
     return resultDesc
end
-- Given a namespace & local ID, returns a namespaced ID
function p.getNamespacedID(namespace, localID)
if string.find(localID, ':') == nil then
return namespace .. ':' .. localID
else
-- ID already appears to be namespaced
return localID
end
end
-- Given a namespaced ID, returns both the namespace & local ID
function p.getLocalID(ID)
local namespace, localID = nil, nil
local sepIdx = string.find(ID, ':')
if sepIdx == nil then
-- Provided ID doesn't appear to be namespaced
localID = ID
else
namespace = string.sub(ID, 1, sepIdx - 1)
localID = string.sub(ID, sepIdx + 1, string.len(ID))
end
return namespace, localID
end
end


return p
return p