forked from Tencent/UnLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnLua.lua
More file actions
96 lines (83 loc) · 1.82 KB
/
UnLua.lua
File metadata and controls
96 lines (83 loc) · 1.82 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
local rawget = rawget
local rawset = rawset
local type = type
local getmetatable = getmetatable
local setmetatable = setmetatable
local require = require
local str_sub = string.sub
local GetUProperty = GetUProperty
local SetUProperty = SetUProperty
local RegisterClass = RegisterClass
local RegisterEnum = RegisterEnum
local print = UEPrint
_NotExist = _NotExist or {}
local NotExist = _NotExist
local function Index(t, k)
local mt = getmetatable(t)
local super = mt
while super do
local v = rawget(super, k)
if v ~= nil and not rawequal(v, NotExist) then
rawset(t, k, v)
return v
end
super = rawget(super, "Super")
end
local p = mt[k]
if p ~= nil then
if type(p) == "userdata" then
return GetUProperty(t, p)
elseif type(p) == "function" then
rawset(t, k, p)
elseif rawequal(p, NotExist) then
return nil
end
else
rawset(mt, k, NotExist)
end
return p
end
local function NewIndex(t, k, v)
local mt = getmetatable(t)
local p = mt[k]
if type(p) == "userdata" then
return SetUProperty(t, p, v)
end
rawset(t, k, v)
end
local function Class(super_name)
local super_class = nil
if super_name ~= nil then
super_class = require(super_name)
end
local new_class = {}
new_class.__index = Index
new_class.__newindex = NewIndex
new_class.Super = super_class
return new_class
end
local function global_index(t, k)
if type(k) == "string" then
local s = str_sub(k, 1, 1)
if s == "U" or s == "A" or s == "F" then
RegisterClass(k)
elseif s == "E" then
RegisterEnum(k)
end
end
return rawget(t, k)
end
if WITH_UE4_NAMESPACE then
print("WITH_UE4_NAMESPACE==true");
else
local global_mt = {}
global_mt.__index = global_index
setmetatable(_G, global_mt)
UE4 = _G
UE = _G
print("WITH_UE4_NAMESPACE==false");
end
_G.print = print
_G.Index = Index
_G.NewIndex = NewIndex
_G.Class = Class