forked from thisdp/dgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdgsExportedFunction.lua
72 lines (64 loc) · 1.89 KB
/
dgsExportedFunction.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
dgsExportedFunctionName = {}
dgsResName = getResourceName(getThisResource())
local metafile = xmlLoadFile("meta.xml")
local nodes = xmlNodeGetChildren(metafile)
local dgsHead = [[
--Check Error Message Above
if not dgsImportHead then
local getResourceRootElement = getResourceRootElement
local call = call
local getResourceFromName = getResourceFromName
local tostring = tostring
local outputDebugString = outputDebugString
local DGSCallMT = {}
dgsImportHead = {}
dgsImportHead.dgsName = "]]..dgsResName..[["
dgsImportHead.dgsResource = getResourceFromName(dgsImportHead.dgsName)
dgsRoot = getResourceRootElement(dgsImportHead.dgsResource)
function DGSCallMT:__index(k)
if type(k) ~= 'string' then k = tostring(k) end
self[k] = function(...)
assert(dgsImportHead,"DGS is not running")
if type(dgsImportHead.dgsResource) == 'userdata' and getResourceRootElement(dgsImportHead.dgsResource) then
return call(dgsImportHead.dgsResource, k, ...)
else
dgsImportHead = nil
return nil
end
end
return self[k]
end
DGS = setmetatable({}, DGSCallMT)
function unloadDGSFunction()
end
end
]]
for k,v in ipairs(nodes) do
if xmlNodeGetName(v) == "export" then
local func = xmlNodeGetAttribute(v,"function")
local typ = xmlNodeGetAttribute(v,"type")
if typ == "client" or typ == "shared" then
dgsExportedFunctionName[func] = func
end
end
end
function dgsGetExportedFunctionName(name)
if name then
return dgsExportedFunctionName[name]
else
return dgsExportedFunctionName
end
end
function dgsImportFunction(name,nameAs)
if not name then
local allCode = dgsHead
for k,v in pairs(dgsExportedFunctionName) do
allCode = allCode.."\n "..k.." = DGS."..k..";"
end
return allCode
else
assert(dgsExportedFunctionName[name],"Bad Argument @dgsImportFunction at argument 1, the function is undefined")
nameAs = nameAs or name
return nameAs.." = DGS."..name..";"
end
end