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
63 lines (53 loc) · 1.13 KB
/
UnLua.lua
File metadata and controls
63 lines (53 loc) · 1.13 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
local rawget = rawget
local rawset = rawset
local type = type
local getmetatable = getmetatable
local require = require
local GetUProperty = GetUProperty
local SetUProperty = SetUProperty
local 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
_G.Class = Class