Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
独孤过
Lua
提交
a66e92f0
L
Lua
项目概览
独孤过
/
Lua
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
Lua
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a66e92f0
编写于
4月 21, 2020
作者:
独孤过
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
语言特性
上级
6bf443e4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
82 addition
and
5 deletion
+82
-5
README.md
README.md
+21
-5
feature/尾调函数.lua
feature/尾调函数.lua
+14
-0
feature/泛型for迭代器.lua
feature/泛型for迭代器.lua
+41
-0
feature/表.lua
feature/表.lua
+6
-0
未找到文件。
README.md
浏览文件 @
a66e92f0
# 语言特性
# 数据结构
# 算法
# 设计模式
# 工具库
## 简介
存放lua之行的精选代码,代码按照语言特性、数据结构、算法、设计模式、工具类库分类。
## 语言特性
表
泛型for迭代器
尾调函数
## 数据结构
## 算法
## 设计模式
## 工具库
## 其他
作者:许聪
CSDN:https://blog.csdn.net/xucongyoushan
gitee:https://gitee.com/solifree
github:https://github.com/xucongandxuchong
feature/尾调函数.lua
0 → 100644
浏览文件 @
a66e92f0
--[[
函数的尾调用
函数返回结果是调用单个函数,称之为尾调函数
先从栈空间弹出当前函数,再调用尾调函数,从而降低函数调用过持的栈消耗
--]]
function
factorial
(
n
,
temp
)
temp
=
temp
or
1
if
n
<=
1
then
return
temp
end
return
factorial
(
n
-
1
,
temp
*
n
)
end
print
(
factorial
(
5
))
feature/泛型for迭代器.lua
0 → 100644
浏览文件 @
a66e92f0
local
week_day
=
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
}
-- 定义迭代器
local
function
ipairs
(
table
)
-- 定义迭代函数
local
ipairs
=
function
(
table
,
index
)
index
=
index
+
1
local
value
=
table
[
index
]
if
not
value
then
index
=
nil
end
return
index
,
value
-- 返回nil,结束泛型for
end
return
ipairs
,
table
,
0
end
for
k
,
v
in
ipairs
(
week_day
)
do
print
(
k
..
": "
..
v
)
end
-- 定义迭代器
local
function
pairs
(
table
)
-- 定义迭代函数
local
pairs
=
function
(
table
,
key
)
key
=
next
(
table
,
key
)
return
key
,
table
[
key
]
end
return
pairs
,
table
,
nil
-- 返回迭代函数、遍历集合、初始键
end
for
k
,
v
in
pairs
(
week_day
)
do
print
(
k
..
": "
..
v
)
end
feature/表.lua
0 → 100644
浏览文件 @
a66e92f0
-- table.move(src, f, e, t[, dest])
-- 此函数只复制源数组指定范围的元素至目的数组的指定位置,并不会移除源数组指定范围的元素
local
src
=
{
1
,
2
,
3
}
local
dest
=
{}
_G
.
table
.
move
(
src
,
1
,
#
src
,
1
,
dest
)
print
(
next
(
src
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录