- Fixed the placement of "not" operators in the code to ensure proper logic. - Corrected the casing of a helper function to maintain consistency. - Reworded the description for better clarity and alignment with Git commit terms. - Updated the bridge description to highlight its community-driven approach. - Fixed minor syntax and readability issues throughout the documentation.
36 lines
961 B
Lua
36 lines
961 B
Lua
local loadedModules = {}
|
|
|
|
function Require(modulePath, resourceName)
|
|
if resourceName and type(resourceName) ~= "string" then
|
|
resourceName = GetCurrentResourceName()
|
|
end
|
|
|
|
if not resourceName then
|
|
resourceName = "community_bridge"
|
|
end
|
|
|
|
local id = resourceName .. ":" .. modulePath
|
|
if loadedModules[id] then
|
|
print("Returning cached module [" .. id .. "]")
|
|
return loadedModules[id]
|
|
end
|
|
|
|
local file = LoadResourceFile(resourceName, modulePath)
|
|
if not file then
|
|
error("Error loading file [" .. id .. "]")
|
|
end
|
|
|
|
local chunk, loadErr = load(file, id)
|
|
if not chunk then
|
|
error("Error wrapping module [" .. id .. "] Message: " .. loadErr)
|
|
end
|
|
|
|
local success, result = pcall(chunk)
|
|
if not success then
|
|
error("Error executing module [" .. id .. "] Message: " .. result)
|
|
end
|
|
loadedModules[id] = result
|
|
return result
|
|
end
|
|
|
|
exports('Require', Require) |