Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
GGELUA
GGELUA2
提交
c2e6d6d7
GGELUA2
项目概览
GGELUA
/
GGELUA2
通知
169
Star
23
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
GGELUA2
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c2e6d6d7
编写于
4月 24, 2022
作者:
baidwwy
🏋
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
class
上级
46b52316
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
6 deletion
+23
-6
ggelua/GGE/class.lua
ggelua/GGE/class.lua
+23
-6
未找到文件。
ggelua/GGE/class.lua
浏览文件 @
c2e6d6d7
-- @Author : GGELUA
-- @Date : 2022-03-07 18:52:00
-- @Last Modified by : baidwwy
-- @Last Modified time : 2022-04-
11 15:41:26
-- @Last Modified time : 2022-04-
21 08:47:27
local
_CLASS
,
_METAS
=
package.loaded
,
{}
local
type
=
type
local
ipairs
=
ipairs
local
pairs
=
pairs
local
getmetatable
=
getmetatable
local
setmetatable
=
setmetatable
local
unpack
=
table.unpack
...
...
@@ -86,14 +86,28 @@ end
local
function
class
(
name
,
...
)
assert
(
type
(
name
)
==
'string'
,
'必须要有类名'
)
assert
(
_CLASS
[
name
]
==
nil
,
name
..
':类名已经存在'
)
local
meta
,
cobj
meta
=
{
if
_CLASS
[
name
]
then
warn
(
string.format
(
'class[%s]被重写'
,
name
))
local
meta
=
_CLASS
[
name
].
__metatable
local
list
=
{}
for
k
in
pairs
(
meta
)
do
if
k
:
sub
(
1
,
2
)
~=
'__'
then
list
[
k
]
=
true
end
end
for
k
in
pairs
(
list
)
do
meta
[
k
]
=
nil
end
meta
.
__super
=
assert_super
{
...
}
return
_CLASS
[
name
]
end
local
meta
=
{
__name
=
name
,
__index
=
class_index
,
__super
=
assert_super
{
...
}
}
meta
.
__metatable
=
meta
--禁止修改
local
cobj
cobj
=
{
--初始化 = false,[name] = false,
创建
=
function
(
...
)
...
...
@@ -112,7 +126,7 @@ local function class(name, ...)
return
obj
,
table.unpack
(
ret
)
end
}
--_METAS[name] = meta
_METAS
[
cobj
]
=
meta
--_METAS[class] = meta
_CLASS
[
name
]
=
cobj
--package.loaded
return
setmetatable
(
...
...
@@ -178,6 +192,9 @@ local function class(name, ...)
-- return
end
meta
[
k
]
=
value
end
,
__pairs
=
function
(
t
)
return
next
,
meta
end
}
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录