Skip to content

Commit

Permalink
🎨 Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Feb 27, 2024
1 parent 09ddd5c commit f744442
Show file tree
Hide file tree
Showing 9 changed files with 7,418 additions and 6,005 deletions.
2 changes: 1 addition & 1 deletion server-data/resources/[ox]/ox_lib/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rdr3_warning("I acknowledge that this is a prerelease build of RedM, and I am aw
--
name("ox_lib")
author("Overextended")
version("3.16.2")
version("3.16.3")
license("LGPL-3.0-or-later")
repository("https://github.com/overextended/ox_lib")
description("A library of shared functions to utilise in other resources.")
Expand Down
229 changes: 119 additions & 110 deletions server-data/resources/[ox]/ox_lib/imports/require/shared.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local loaded = {}

package = {
loaded = setmetatable({}, {
__index = loaded,
__newindex = noop,
__metatable = false,
}),
path = './?.lua;'
loaded = setmetatable({}, {
__index = loaded,
__newindex = noop,
__metatable = false,
}),
path = "./?.lua;",
}

local _require = require
Expand All @@ -15,157 +15,166 @@ local _require = require
---@param modname? string
---@return string, string?
local function getModuleInfo(modpath, modname)
local resourceSrc

if not modpath:find('^@') then
local idx = 1

while true do
local di = debug.getinfo(idx, 'S')

if di then
if not di.short_src:find('^@ox_lib/imports/require') and not di.short_src:find('^%[C%]') and not di.short_src:find('^citizen') and di.short_src ~= '?' then
resourceSrc = di.short_src:gsub('^@(.-)/.+', '%1')
break
end
else
resourceSrc = cache.resource
break
end

idx += 1
end

if modname and resourceSrc ~= cache.resource then
modname = ('@%s.%s'):format(resourceSrc, modname)
end
end

return resourceSrc, modname
local resourceSrc

if not modpath:find("^@") then
local idx = 1

while true do
local di = debug.getinfo(idx, "S")

if di then
if
not di.short_src:find("^@ox_lib/imports/require")
and not di.short_src:find("^%[C%]")
and not di.short_src:find("^citizen")
and di.short_src ~= "?"
then
resourceSrc = di.short_src:gsub("^@(.-)/.+", "%1")
break
end
else
resourceSrc = cache.resource
break
end

idx += 1
end

if modname and resourceSrc ~= cache.resource then
modname = ("@%s.%s"):format(resourceSrc, modname)
end
end

return resourceSrc, modname
end

---@param filePath string
---@param env? table
---@return any
---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)
local resourceSrc
local modpath = filePath:gsub('%.', '/')

if not modpath:find('^@') then
resourceSrc = getModuleInfo(modpath)
end
local resourceSrc
local modpath = filePath:gsub("%.", "/")

if not resourceSrc then
resourceSrc = modpath:gsub('^@(.-)/.+', '%1')
modpath = modpath:sub(#resourceSrc + 3)
end
if not modpath:find("^@") then
resourceSrc = getModuleInfo(modpath)
end

for path in package.path:gmatch('[^;]+') do
local scriptPath = path:gsub('?', modpath):gsub('%.+%/+', '')
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)
if not resourceSrc then
resourceSrc = modpath:gsub("^@(.-)/.+", "%1")
modpath = modpath:sub(#resourceSrc + 3)
end

if resourceFile then
for path in package.path:gmatch("[^;]+") do
local scriptPath = path:gsub("?", modpath):gsub("%.+%/+", "")
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)

local chunk, err = load(resourceFile, ('@@%s/%s'):format(resourceSrc, modpath), 't', env or _ENV)
if resourceFile then
local chunk, err = load(resourceFile, ("@@%s/%s"):format(resourceSrc, modpath), "t", env or _ENV)

if not chunk or err then
error(err or 'an unknown error occurred', 2)
end
if not chunk or err then
error(err or "an unknown error occurred", 2)
end

return chunk()
end
end
return chunk()
end
end

error(('cannot load file at path %s'):format(modpath))
error(("cannot load file at path %s"):format(modpath))
end

---@param filePath string
---@return table
---Loads and decodes a json file at the given path.
function lib.loadJson(filePath)
local resourceSrc
local modpath = filePath:gsub('%.', '/')
local resourceSrc
local modpath = filePath:gsub("%.", "/")

if not modpath:find('^@') then
resourceSrc = getModuleInfo(modpath)
end
if not modpath:find("^@") then
resourceSrc = getModuleInfo(modpath)
end

if not resourceSrc then
resourceSrc = modpath:gsub('^@(.-)/.+', '%1')
modpath = modpath:sub(#resourceSrc + 3)
end
if not resourceSrc then
resourceSrc = modpath:gsub("^@(.-)/.+", "%1")
modpath = modpath:sub(#resourceSrc + 3)
end

local scriptPath = ('%s.json'):format(modpath)
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)
local scriptPath = ("%s.json"):format(modpath)
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)

if resourceFile then
return json.decode(resourceFile)
end
if resourceFile then
return json.decode(resourceFile)
end

error(('cannot load json file at path %s'):format(modpath))
error(("cannot load json file at path %s"):format(modpath))
end

---Loads the given module inside the current resource, returning any values returned by the file or `true` when `nil`.
---@param modname string
---@return unknown?
function lib.require(modname)
if type(modname) ~= 'string' then return end
if type(modname) ~= "string" then
return
end

local modpath = modname:gsub('%.', '/')
local module = loaded[modname]
local modpath = modname:gsub("%.", "/")
local module = loaded[modname]

if module then return module end
if module then
return module
end

local success, result = pcall(_require, modname)
local success, result = pcall(_require, modname)

if success then
loaded[modname] = result
return result
end
if success then
loaded[modname] = result
return result
end

local resourceSrc
local resourceSrc

if not modpath:find('^@') then
resourceSrc, modname = getModuleInfo(modpath, modname) --[[@as string]]
end
if not modpath:find("^@") then
resourceSrc, modname = getModuleInfo(modpath, modname) --[[@as string]]
end

if not module then
if module == false then
error(("^1circular-dependency occurred when loading module '%s'^0"):format(modname), 2)
end
if not module then
if module == false then
error(("^1circular-dependency occurred when loading module '%s'^0"):format(modname), 2)
end

if not resourceSrc then
resourceSrc = modpath:gsub('^@(.-)/.+', '%1')
modpath = modpath:sub(#resourceSrc + 3)
end
if not resourceSrc then
resourceSrc = modpath:gsub("^@(.-)/.+", "%1")
modpath = modpath:sub(#resourceSrc + 3)
end

for path in package.path:gmatch('[^;]+') do
local scriptPath = path:gsub('?', modpath):gsub('%.+%/+', '')
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)
for path in package.path:gmatch("[^;]+") do
local scriptPath = path:gsub("?", modpath):gsub("%.+%/+", "")
local resourceFile = LoadResourceFile(resourceSrc, scriptPath)

if resourceFile then
loaded[modname] = false
scriptPath = ('@@%s/%s'):format(resourceSrc, scriptPath)
if resourceFile then
loaded[modname] = false
scriptPath = ("@@%s/%s"):format(resourceSrc, scriptPath)

local chunk, err = load(resourceFile, scriptPath)
local chunk, err = load(resourceFile, scriptPath)

if err or not chunk then
loaded[modname] = nil
return error(err or ("unable to load module '%s'"):format(modname), 3)
end
if err or not chunk then
loaded[modname] = nil
return error(err or ("unable to load module '%s'"):format(modname), 3)
end

module = chunk(modname) or true
loaded[modname] = module
local result = chunk(modname)
module = result or result == nil
loaded[modname] = module

return module
end
end
return module
end
end

return error(result, 2)
end
return error(result, 2)
end

return module
return module
end

return lib.require
6 changes: 3 additions & 3 deletions server-data/resources/[ox]/ox_lib/imports/waitFor/shared.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---Yields the current thread until a non-nil value is returned by the function.
---@generic T
---@param cb fun(): T?
---@param cb fun(): T
---@param errMessage string?
---@param timeout number? Error out after `~x` ms. Defaults to 1000, unless set to `false`.
---@return T?
---@param timeout? number | false Error out after `~x` ms. Defaults to 1000, unless set to `false`.
---@return T
---@async
function lib.waitFor(cb, errMessage, timeout)
local value = cb()
Expand Down
15 changes: 15 additions & 0 deletions server-data/resources/[ox]/ox_lib/locales/ar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"language": "العربية",
"ui": {
"cancel": "إلغاء",
"close": "إغلاق",
"confirm": "تأكيد",
"more": "المزيد ..."
},
"txadmin_announcement": "إعلان من قبل %s",
"txadmin_dm": "رسالة من %s",
"txadmin_warn": "تم تحذيرك من قبل %s",
"txadmin_warn_content": "%s \nأيدي: %s",
"txadmin_scheduledrestart": "تحديد ريستارت للسرفر"
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local openContextMenu = nil
---@field description? string
---@field metadata? string | { [string]: any } | string[]
---@field disabled? boolean
---@field readOnly? boolean
---@field event? string
---@field serverEvent? string
---@field args? any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local input
---@field required? boolean
---@field format? string
---@field returnString? boolean
---@field clearable? string
---@field clearable? boolean
---@field description? string

---@class InputDialogOptionsProps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left'
---@alias NotificationType 'info' | 'warning' | 'success' | 'error'
---@alias IconAnimationType 'spin' | 'spinPulse' | 'spinReverse' | 'pulse' | 'beat' | 'fade' | 'beatFade' | 'bounce' | 'shake'

---@class NotifyProps
---@field id? string
Expand All @@ -10,6 +11,7 @@
---@field type? NotificationType
---@field style? { [string]: any }
---@field icon? string | {[1]: IconProp, [2]: string};
---@field iconAnimation? IconAnimationType;
---@field iconColor? string;
---@field alignIcon? 'top' | 'center';

Expand Down
Loading

0 comments on commit f744442

Please sign in to comment.