forked from meesvrh/fmLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.lua
More file actions
110 lines (99 loc) · 3.56 KB
/
api.lua
File metadata and controls
110 lines (99 loc) · 3.56 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
--[[
fmLib - API Export System
Handles exports and proxy creation for external scripts
]]
for category, _ in pairs(AdapterResources) do
if FM[category] then
for funcName, func in pairs(FM[category]) do
if type(func) == 'function' then
local exportName = category .. '_' .. funcName
exports(exportName, function(...)
return FM[category][funcName](...)
end)
Debug(string.format("Registered export: %s", exportName))
end
end
end
end
-- Register exports for modules (manual list)
local modules = {'callback', 'console', 'animation', 'dialog', 'pin', 'loading', 'progress', 'anim', 'cb' }
for _, module in ipairs(modules) do
if FM[module] then
for funcName, func in pairs(FM[module]) do
if type(func) == 'function' then
local exportName = module .. '_' .. funcName
exports(exportName, function(...)
return FM[module][funcName](...)
end)
Debug(string.format("Registered export: %s", exportName))
end
end
end
end
-- Register exports for backwards compatibility categories (not in AdapterResources)
local backwardsCompatCategories = {'vehicle', 'utils', 'player', 'acc', 'p', 'inv'}
for _, category in ipairs(backwardsCompatCategories) do
if FM[category] then
for funcName, func in pairs(FM[category]) do
if type(func) == 'function' then
local exportName = category .. '_' .. funcName
exports(exportName, function(...)
return FM[category][funcName](...)
end)
Debug(string.format("Registered export (backwards compat): %s", exportName))
end
end
end
end
Debug("All exports registered successfully")
local proxy = {}
-- Create proxy for adapter categories
for category, _ in pairs(AdapterResources) do
if FM[category] then
proxy[category] = {}
for funcName, func in pairs(FM[category]) do
if type(func) == 'function' then
proxy[category][funcName] = function(...)
return exports.fmLib[category .. '_' .. funcName](exports.fmLib, ...)
end
end
end
end
end
-- Create proxy for modules
local pModules = {'callback', 'console', 'animation', 'dialog', 'pin', 'loading', 'progress', 'anim', 'cb' }
for _, module in ipairs(pModules) do
if FM[module] then
proxy[module] = {}
for funcName, func in pairs(FM[module]) do
if type(func) == 'function' then
proxy[module][funcName] = function(...)
return exports.fmLib[module .. '_' .. funcName](exports.fmLib, ...)
end
end
end
end
end
-- Create proxy for backwards compatibility categories
local pBackwardsCompatCategories = {'vehicle', 'utils', 'player', 'acc', 'p', 'inv'}
for _, category in ipairs(pBackwardsCompatCategories) do
if FM[category] then
proxy[category] = {}
for funcName, func in pairs(FM[category]) do
if type(func) == 'function' then
proxy[category][funcName] = function(...)
return exports.fmLib[category .. '_' .. funcName](exports.fmLib, ...)
end
end
end
end
end
function proxy:construct()
setmetatable({}, self)
self.__index = self
return self
end
exports('new', function()
return proxy:construct()
end)
Success("fmLib API system initialized")