forked from chudongjingling/open_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf778a8
commit 834dd8c
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Week={ | ||
{date="monday",chinese="星期一"}, | ||
{date="tuesday",chinese="星期二"}, | ||
{date="wednesday",chinese="星期三"}, | ||
{date="thursday",chinese="星期四"}, | ||
{date="firday",chinese="星期五"}, | ||
{date="saturday",chinese="星期六"}, | ||
{date="sunday",chinese="星期天"}, | ||
} | ||
--克隆表格 | ||
function Clone(tab) | ||
if type(tab) == table then | ||
local r = {} | ||
for k,v in pairs(tab) do | ||
if type(v) == table then | ||
Clone(v) | ||
else | ||
r[k] = v | ||
end | ||
end | ||
return r | ||
else | ||
return tab | ||
end | ||
end | ||
--创建星期数据 | ||
function Week.Creat(self,...) | ||
local x = {...} | ||
local r = {} | ||
for k,v in pairs(self) do | ||
if type(v) == "function" then | ||
r[k] = v | ||
end | ||
end | ||
if not ... then return end | ||
for i,v in pairs(x) do | ||
r[v] = Clone(self[v]) | ||
end | ||
return r | ||
end | ||
--选择星期几数据,然后输出 | ||
function Week.Check(self,weeknum) | ||
return self[weeknum] | ||
end | ||
--删除星期几,可多个 | ||
function Week.Remove(self,...) | ||
if not ... then return end | ||
weeknum = {...} | ||
for i,v in ipairs(weeknum) do | ||
self[v] = nil | ||
end | ||
end | ||
--增加,可多个 | ||
function Week.Add(self,...) | ||
if not ... then return end | ||
weeknum = {...} | ||
for i,v in ipairs(weeknum) do | ||
self[v] = Clone(Week[v]) | ||
end | ||
end | ||
function Week.print(self) | ||
for k,v in pairs(self) do | ||
if type(k) == "number" then | ||
print(v.date.." 中文:"..v.chinese) | ||
end | ||
end | ||
print("\n") | ||
end | ||
new = Week:Creat(1,5,6) | ||
new:print() | ||
new:Add(4,5) | ||
new:print() | ||
new:Remove(1) | ||
new:print() |