forked from inceptionnet/mtasa-uikit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_exporter.lua
76 lines (63 loc) · 2.27 KB
/
_exporter.lua
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
Exporter = {}
Exporter.resourceName = getResourceName(getThisResource())
Exporter.injection = {
'RESOURCE_NAME = "' .. Exporter.resourceName .. '"',
'IS_EXTERNAL = true',
}
Exporter.replicationStr = [[
for type in pairs(ElementType) do
_G[type] = {}
_G[type].new = function(self)
error(type .. ' is not imported. Please add this to the top line: import(\'' .. type .. '\')')
end
end
]]
Exporter.replicationDependency = [[
function import(...)
loadstring(exports.]] .. Exporter.resourceName .. [[:import(...))()
end
]]
Exporter.modules = {}
createNativeEvent(ClientEventNames.onClientResourceStart, resourceRoot, function()
local xml = XML.load('meta.xml')
local nodes = xml:getChildren()
for i, node in ipairs(nodes) do
if node:getName() == 'script' then
local src = node:getAttribute('src')
local isSkip = node:getAttribute('skip')
local isIgnore = node:getAttribute('ignore')
local module = node:getAttribute('module')
if isSkip and not isIgnore then
if not File.exists(src) then
outputConsole('[UIKit] Failed to load module, file not found: ' .. src)
break
end
local file = File.open(src)
local content = file:read(file:getSize())
file:close()
if not module then
table.insert(Exporter.injection, content)
else
if not Exporter.modules[module] then
Exporter.modules[module] = ''
end
Exporter.modules[module] = Exporter.modules[module] .. '\n' .. content
end
end
end
end
table.insert(Exporter.injection, Exporter.replicationStr)
table.insert(Exporter.injection, 'screenSize = Vector2(guiGetScreenSize())')
table.insert(Exporter.injection, 'Core = Core:new()')
table.insert(Exporter.injection, Exporter.replicationDependency)
end)
function getModule()
local str = table.concat(Exporter.injection, '\n')
if File.exists('temp.lua') then
File.delete('temp.lua')
end
local tempFile = File.new('temp.lua')
tempFile:write(str)
tempFile:close()
return str
end