From a66e92f05faf9d08ca599abed99df0583bed90f4 Mon Sep 17 00:00:00 2001 From: xucongandxuchong <2592419242@qq.com> Date: Tue, 21 Apr 2020 22:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E8=A8=80=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 +++++++++--- ...6\350\260\203\345\207\275\346\225\260.lua" | 14 +++++++ ...r\350\277\255\344\273\243\345\231\250.lua" | 41 +++++++++++++++++++ "feature/\350\241\250.lua" | 6 +++ 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 "feature/\345\260\276\350\260\203\345\207\275\346\225\260.lua" create mode 100644 "feature/\346\263\233\345\236\213for\350\277\255\344\273\243\345\231\250.lua" create mode 100644 "feature/\350\241\250.lua" diff --git a/README.md b/README.md index 80a5ea5..e79b24a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,21 @@ -# 语言特性 -# 数据结构 -# 算法 -# 设计模式 -# 工具库 +## 简介 +存放lua之行的精选代码,代码按照语言特性、数据结构、算法、设计模式、工具类库分类。 + +## 语言特性 +表 +泛型for迭代器 +尾调函数 + +## 数据结构 + +## 算法 + +## 设计模式 + +## 工具库 + +## 其他 +作者:许聪 +CSDN:https://blog.csdn.net/xucongyoushan +gitee:https://gitee.com/solifree +github:https://github.com/xucongandxuchong diff --git "a/feature/\345\260\276\350\260\203\345\207\275\346\225\260.lua" "b/feature/\345\260\276\350\260\203\345\207\275\346\225\260.lua" new file mode 100644 index 0000000..8bc8afc --- /dev/null +++ "b/feature/\345\260\276\350\260\203\345\207\275\346\225\260.lua" @@ -0,0 +1,14 @@ +--[[ + β + ؽǵõ֮Ϊβ + ȴջռ䵯ǰٵβӶͺùֵջ +--]] +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)) diff --git "a/feature/\346\263\233\345\236\213for\350\277\255\344\273\243\345\231\250.lua" "b/feature/\346\263\233\345\236\213for\350\277\255\344\273\243\345\231\250.lua" new file mode 100644 index 0000000..f0d629b --- /dev/null +++ "b/feature/\346\263\233\345\236\213for\350\277\255\344\273\243\345\231\250.lua" @@ -0,0 +1,41 @@ +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 -- nilfor + 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 diff --git "a/feature/\350\241\250.lua" "b/feature/\350\241\250.lua" new file mode 100644 index 0000000..e389286 --- /dev/null +++ "b/feature/\350\241\250.lua" @@ -0,0 +1,6 @@ +-- 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)) -- GitLab