2022-11-21 20:37:28 +11:00
local debug_getinfo = debug.getinfo
2023-07-31 15:14:10 +10:00
function noop ( ) end
2022-05-06 16:37:36 +10:00
lib = setmetatable ( {
2022-11-21 20:37:28 +11:00
name = ' ox_lib ' ,
context = IsDuplicityVersion ( ) and ' server ' or ' client ' ,
2022-05-06 16:37:36 +10:00
} , {
2023-07-31 15:14:10 +10:00
__newindex = function ( self , key , fn )
rawset ( self , key , fn )
2022-11-21 20:37:28 +11:00
if debug_getinfo ( 2 , ' S ' ) . short_src : find ( ' @ox_lib/resource ' ) then
2023-07-31 15:14:10 +10:00
exports ( key , fn )
end
end ,
__index = function ( self , key )
local dir = ( ' imports/%s ' ) : format ( key )
local chunk = LoadResourceFile ( self.name , ( ' %s/%s.lua ' ) : format ( dir , self.context ) )
local shared = LoadResourceFile ( self.name , ( ' %s/shared.lua ' ) : format ( dir ) )
if shared then
chunk = ( chunk and ( ' %s \n %s ' ) : format ( shared , chunk ) ) or shared
end
if chunk then
local fn , err = load ( chunk , ( ' @@ox_lib/%s/%s.lua ' ) : format ( key , self.context ) )
if not fn or err then
return error ( ( ' \n ^1Error importing module (%s): %s^0 ' ) : format ( dir , err ) , 3 )
end
rawset ( self , key , fn ( ) or noop )
return self [ key ]
2022-11-21 20:37:28 +11:00
end
end
2022-02-28 00:49:44 +00:00
} )
2022-04-17 18:22:19 +02:00
2022-09-14 00:50:27 +10:00
cache = {
2022-12-06 13:30:24 +11:00
resource = lib.name ,
game = GetGameName ( ) ,
2022-09-14 00:50:27 +10:00
}
2022-05-06 16:37:36 +10:00
if not LoadResourceFile ( lib.name , ' web/build/index.html ' ) then
2022-10-28 18:26:27 +11:00
local err = ' ^1Unable to load UI. Build ox_lib or download the latest release. \n ^3https://github.com/overextended/ox_lib/releases/latest/download/ox_lib.zip^0 '
function lib . hasLoaded ( ) return err end
2022-11-21 20:37:28 +11:00
error ( err )
2022-04-29 03:02:28 +10:00
end
2022-10-28 18:26:27 +11:00
function lib . hasLoaded ( ) return true end