Repository navigation
Expand file tree
/
Copy pathrequire.lua
More file actions
62 lines (49 loc) · 1.8 KB
/
Copy pathrequire.lua
File metadata and controls
62 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- See https://github.com/overextended/cfxlua-require
---@diagnostic disable-next-line: undefined-global
if not package or not runtime then
load(LoadResourceFile('require', 'init.lua'), '@@require')()
end
-- Provide compatibility for old API
lib.require = require
lib.loadJson = json.load
---@param filePath string
---@param env? table
---@return unknown
---@deprecated
---@see loadfile
---@see dofile
---Loads and runs a Lua file at the given path. Unlike require, the chunk is not cached for future use.
function lib.load(filePath, env)
return loadfile(filePath, 't', env)()
end
---Module v2 searcher
---@param modName string
table.insert(package.searchers, 1, function(modName)
local module, matched = modName:gsub('^Ox%.', '@ox_lib.modules.')
if matched > 0 then
return function() return require(module) end
end
end)
require 'Ox.Class'
local SemVer = require 'Ox.SemVer'
local errors = {}
for i = 0, GetNumResourceMetadata(cache.resource, 'fx_dependencie') - 1 do
local resource, required = string.strsplit(':', GetResourceMetadata(cache.resource, 'fx_dependencie', i), 2)
local version = SemVer:new(GetResourceMetadata(resource, 'version', 0))
required = SemVer:new(required)
if required:compare(version) == 1 then
local url = GetResourceMetadata(resource, 'repository', 0) or GetResourceMetadata(resource, 'url', 0)
errors[#errors + 1] = ("- %s: required %s, installed %s%s"):format(
resource,
required,
version,
url and (' (%s)'):format(url) or ''
)
end
end
if #errors > 0 then
error(([[The following resource dependencies do not meet the required version:
%s
Please update the listed resources to their required versions and restart.]]):format(table.concat(errors, '\n\t')), 0)
end
return require