mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
tweak(init): store service and name in lib
lib.name for 'ox_lib', and service or 'client' or 'server'.
This commit is contained in:
19
init.lua
19
init.lua
@@ -30,13 +30,11 @@ end
|
|||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
local LoadResourceFile = LoadResourceFile
|
local LoadResourceFile = LoadResourceFile
|
||||||
local file = IsDuplicityVersion() and 'server' or 'client'
|
local service = IsDuplicityVersion() and 'server' or 'client'
|
||||||
local rawset = rawset
|
|
||||||
local rawget = rawget
|
|
||||||
|
|
||||||
local function loadModule(self, module)
|
local function loadModule(self, module)
|
||||||
local dir = ('imports/%s'):format(module)
|
local dir = ('imports/%s'):format(module)
|
||||||
local chunk = LoadResourceFile(ox_lib, ('%s/%s.lua'):format(dir, file))
|
local chunk = LoadResourceFile(ox_lib, ('%s/%s.lua'):format(dir, service))
|
||||||
local shared = LoadResourceFile(ox_lib, ('%s/shared.lua'):format(dir))
|
local shared = LoadResourceFile(ox_lib, ('%s/shared.lua'):format(dir))
|
||||||
|
|
||||||
if shared then
|
if shared then
|
||||||
@@ -45,7 +43,7 @@ local function loadModule(self, module)
|
|||||||
|
|
||||||
if chunk then
|
if chunk then
|
||||||
local err
|
local err
|
||||||
chunk, err = load(chunk, ('@@ox_lib/%s/%s.lua'):format(module, file))
|
chunk, err = load(chunk, ('@@ox_lib/%s/%s.lua'):format(module, service))
|
||||||
if err then
|
if err then
|
||||||
error(('\n^1Error importing module (%s): %s^0'):format(dir, err), 3)
|
error(('\n^1Error importing module (%s): %s^0'):format(dir, err), 3)
|
||||||
else
|
else
|
||||||
@@ -81,6 +79,8 @@ local function call(self, index, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
lib = setmetatable({
|
lib = setmetatable({
|
||||||
|
name = ox_lib,
|
||||||
|
service = service,
|
||||||
exports = {},
|
exports = {},
|
||||||
onCache = setmetatable({}, {
|
onCache = setmetatable({}, {
|
||||||
__call = function(self, key, cb)
|
__call = function(self, key, cb)
|
||||||
@@ -90,14 +90,9 @@ lib = setmetatable({
|
|||||||
}, {
|
}, {
|
||||||
__index = call,
|
__index = call,
|
||||||
__call = call,
|
__call = call,
|
||||||
|
|
||||||
__newindex = function()
|
__newindex = function()
|
||||||
error('Cannot set index on lib')
|
error('Cannot set index on lib')
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__tostring = function()
|
|
||||||
return ox_lib
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local intervals = {}
|
local intervals = {}
|
||||||
@@ -160,9 +155,7 @@ local cache = setmetatable({}, {
|
|||||||
__call = function(self)
|
__call = function(self)
|
||||||
table.wipe(self)
|
table.wipe(self)
|
||||||
|
|
||||||
if file == 'server' then
|
if service == 'client' then
|
||||||
|
|
||||||
else
|
|
||||||
self.playerId = PlayerId()
|
self.playerId = PlayerId()
|
||||||
self.serverId = GetPlayerServerId(self.playerId)
|
self.serverId = GetPlayerServerId(self.playerId)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user