Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Emo_Tiny
ZFramework
提交
09934371
Z
ZFramework
项目概览
Emo_Tiny
/
ZFramework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
ZFramework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
09934371
编写于
8月 16, 2021
作者:
Emo_Tiny
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Lua框架】lua继承框架提交
上级
9f5317a3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
137 addition
and
11 deletion
+137
-11
Assets/Script/Xlua/LuaScript/LuaClass.lua
Assets/Script/Xlua/LuaScript/LuaClass.lua
+137
-11
未找到文件。
Assets/Script/Xlua/LuaScript/LuaClass.lua
浏览文件 @
09934371
...
...
@@ -20,11 +20,7 @@ local _luaClass =
DumpObject
=
_DumpObject
}
local
_mtBaseClass
=
{
__call
=
function
(
self
,
...
)
return
self
:
New
()
end
,
__tostring
=
_Tostring
}
--实例化
local
function
_Instantiate
(
self
,
...
)
...
...
@@ -68,9 +64,9 @@ local function _IsA(thing,kind)
return
_registry
.
class
[
thing
].
__type
end
elseif
_registry
.
object
[
thing
]
then
return
_regist
e
ry
.
object
[
thing
].
__type
==
kind
return
_registry
.
object
[
thing
].
__type
==
kind
else
return
_regist
e
ry
.
object
[
thing
].
__type
return
_registry
.
object
[
thing
].
__type
end
end
...
...
@@ -106,7 +102,137 @@ local function _Extends(self,name ,flags)
return
setmetatable
(
class
,
self
)
end
function
_CreateClass
(
name
,
flags
)
--抽象继承(虚继承),产生的子类不予许被实例化
local
function
_AbstractExtends
(
self
)
local
c
=
self
:
_Extends
()
_registry
.
class
[
c
].
__abstract
=
true
return
c
end
--终结继承,产生的子类不允许被继承
local
function
_FinalExtends
(
self
)
local
c
=
self
:
Extends
()
_registry
.
class
[
c
].
__final
=
true
return
c
end
--调用父类的方法
local
function
_CallSuperClassFunction
(
self
,
f
,
...
)
local
superClass
=
getmetatable
(
self
)
--获取原表
if
not
superClass
then
return
nil
end
local
super
=
superClass
local
s
=
self
if
_IsA
(
self
,
"object"
)
then
super
=
_registry
.
class
[
superClass
.
__index
].
__superClass
s
=
superClass
.
__index
end
while
super
and
(
s
[
f
]
==
super
[
f
]
or
(
super
.
__invoking
)
~=
nil
and
super
.
__invoking
[
self
]
~=
nil
and
super
.
__invoking
[
self
][
super
[
f
]])
do
s
=
super
super
=
_registry
.
class
[
class
].
__superClass
end
if
not
super
then
return
nil
end
local
method
=
super
[
f
]
if
super
.
__invoking
==
nil
then
super
.
__invoking
=
setmetatable
({},{
__mode
=
"k"
})
end
if
super
.
__invoking
[
self
]
==
nil
then
super
.
__invoking
[
self
]
=
{}
end
super
.
__invoking
[
self
][
method
]
=
true
local
result
=
method
(
self
,
...
)
super
.
__invoking
[
self
][
method
]
=
nil
return
result
end
--安全调用方式
local
function
_CallOverrideFunction
(
self
,
f
,
...
)
local
success
,
ret
=
xpcall
(
self
[
f
],
debug.traceback
(),
self
,
...
)
if
not
success
then
logerror
(
string.format
(
"Error occured during trigger function '%s' error msg '%s'"
,
f
,
ret
))
end
return
success
,
ret
end
--获取类型
local
function
_GetType
(
self
)
if
_IsA
(
self
)
==
"class"
then
return
self
elseif
_IsA
(
self
)
==
"object"
then
return
getmetatable
(
self
).
__index
else
return
nil
end
end
--获取父类
local
function
_GetSuperClass
(
self
)
local
super
=
nil
if
_IsA
(
self
)
==
"class"
then
super
=
getmetatable
(
self
)
elseif
_IsA
(
self
)
==
"object"
then
super
=
_GetType
(
self
)
super
=
super
.
__index
end
return
(
super
~=
_mtBaseClass
and
super
or
nil
)
end
--获取子类(只有类才能获取子类,对象不能)
local
function
_GetSubClasses
(
self
)
assert
(
_IsA
(
self
,
"class"
),
"GetSubClasses() must be called from class"
)
return
_registry
.
class
[
self
].
__subClass
or
{}
end
--类或对象的字符串化
local
function
_ToString
(
self
)
local
is
=
_IsA
(
self
)
if
is
then
local
name
=
nil
if
is
==
"class"
then
name
=
_registry
.
class
[
self
].
__name
elseif
is
==
"object"
then
name
=
_registry
.
class
[
_registry
.
object
[
self
].
__index
].
__name
end
return
(
"%s: %s"
):
format
(
is
,
name
)
else
return
tostring
(
self
)
end
end
--对象或者类的类型判断(即判断self 是不是参数class的类型),如果是,返回true,不是返回false,如果没有填class类型,则直接返回self的类型
local
function
_TypeOf
(
self
,
class
,
shallow
)
if
class
then
assert
(
_IsA
(
self
,
"class"
),
"When given, Argument must be a class"
)
local
target
=
self
:
GetClass
()
repeat
if
target
==
class
then
return
true
end
target
=
target
:
GetSuperClass
()
until
(
not
target
or
shallow
)
return
false
else
return
self
:
GetClass
()
end
end
local
_mtBaseClass
=
{
__call
=
function
(
self
,
...
)
return
self
:
New
()
end
,
__tostring
=
_Tostring
}
--内部的创建类的方法
local
function
_CreateClass
(
name
,
flags
)
local
newClass
=
{}
newClass
.
__index
=
newClass
...
...
@@ -123,11 +249,11 @@ function _CreateClass(name,flags)
newClass
.
New
=
_Instantiate
newClass
.
Extends
=
_Extends
newClass
.
AbstractExtends
=
AbstractExtends
newClass
.
FinalExtends
=
FinalExtends
newClass
.
AbstractExtends
=
_
AbstractExtends
newClass
.
FinalExtends
=
_
FinalExtends
newClass
.
__call
=
_mtBaseClass
.
__call
-- 提供Class()方式创建实例
newClass
.
super
=
_CallSuperClassFunction
newClass
.
SafeOverrideCall
=
_CallOverride
d
Function
newClass
.
SafeOverrideCall
=
_CallOverrideFunction
newClass
.
GetClass
=
_GetType
newClass
.
GetSuperClass
=
_GetSuperClass
newClass
.
GetSubClasses
=
_GetSubClasses
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录