From 6825103dd5004765fd702ffab870d64f2187c86d Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 21 Nov 2022 20:37:28 +1100 Subject: [PATCH] fix(resource): don't export internally loaded modules i.e. exports.ox_lib:callback is invalid --- fxmanifest.lua | 2 +- resource/{main.lua => init.lua} | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) rename resource/{main.lua => init.lua} (50%) diff --git a/fxmanifest.lua b/fxmanifest.lua index 3b1e27d..5ddb371 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -30,7 +30,7 @@ files { 'locales/*.json', } -shared_script 'resource/main.lua' +shared_script 'resource/init.lua' shared_scripts { 'resource/**/shared.lua', diff --git a/resource/main.lua b/resource/init.lua similarity index 50% rename from resource/main.lua rename to resource/init.lua index 44d1493..1db9676 100644 --- a/resource/main.lua +++ b/resource/init.lua @@ -1,21 +1,27 @@ +local debug_getinfo = debug.getinfo + lib = setmetatable({ - name = 'ox_lib', - context = IsDuplicityVersion() and 'server' or 'client', + name = 'ox_lib', + context = IsDuplicityVersion() and 'server' or 'client', }, { - __newindex = function(self, name, fn) - exports(name, fn) - rawset(self, name, fn) - end + __newindex = function(self, name, fn) + rawset(self, name, fn) + + if debug_getinfo(2, 'S').short_src:find('@ox_lib/resource') then + exports(name, fn) + end + end }) cache = { - resource = lib.name + resource = lib.name } if not LoadResourceFile(lib.name, 'web/build/index.html') then 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 - error(err) + + error(err) end function lib.hasLoaded() return true end