综合实战:命令行通讯录管理系统

15.1 项目概述

本章将综合运用本系列所学的知识,从零实现一个完整的命令行通讯录管理系统

功能需求

1
2
3
4
5
6
7
8
通讯录管理系统
├── 添加联系人(姓名、电话、邮箱、分组)
├── 查看所有联系人
├── 搜索联系人(按姓名/电话/分组)
├── 修改联系人信息
├── 删除联系人
├── 数据持久化(文件存储)
└── 分组管理(查看分组、联系人分组统计)

涉及的知识点

  • 表操作:存储联系人数据
  • 函数:模块化组织代码
  • 模块:拆分功能到独立文件
  • 文件 I/O:数据持久化
  • 字符串处理:输入解析、格式化输出
  • 控制结构:菜单循环、条件分支
  • 错误处理:输入验证、文件异常处理
  • 闭包/元表:数据封装

15.2 项目结构

1
2
3
4
5
6
7
8
contact-manager/
├── main.lua # 程序入口
├── modules/
│ ├── contact.lua # 联系人数据操作
│ ├── storage.lua # 文件存储
│ └── ui.lua # 用户交互界面
└── data/
└── contacts.json # 数据文件

数据设计

每个联系人包含以下字段:

1
2
3
4
5
6
7
8
{
id = 1, -- 自动递增 ID
name = "张三", -- 姓名
phone = "13800138000", -- 电话
email = "zhangsan@example.com", -- 邮箱
group = "朋友", -- 分组
created_at = "2026-06-15 08:00:00" -- 创建时间
}

通讯录整体数据结构:

1
2
3
4
5
6
7
8
9
10
11
{
next_id = 6, -- 下一个可用 ID
contacts = { -- 联系人列表
{ id = 1, name = "张三", ... },
{ id = 2, name = "李四", ... },
...
},
groups = { -- 分组信息
"朋友", "家人", "同事"
}
}

15.3 模块实现

modules/storage.lua——数据持久化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
-- storage.lua - 文件存储模块
local storage = {}

-- JSON 编解码(轻量实现,不依赖第三方库)
local function encode_value(v)
local t = type(v)
if t == "string" then
return string.format("%q", v) -- 使用 %q 自动处理转义
elseif t == "number" then
return tostring(v)
elseif t == "boolean" then
return v and "true" or "false"
elseif t == "nil" then
return "null"
elseif t == "table" then
return encode_table(v)
else
return '"' .. tostring(v) .. '"'
end
end

local function encode_table(t)
-- 判断是数组还是字典
local is_array = true
local max_key = 0
for k in pairs(t) do
if type(k) ~= "number" or k <= 0 or math.floor(k) ~= k then
is_array = false
break
end
if k > max_key then max_key = k end
end

-- 检查是否有空洞
if is_array and max_key > 0 then
for i = 1, max_key do
if t[i] == nil then
is_array = false
break
end
end
end

if is_array and max_key > 0 then
local parts = {}
for i = 1, max_key do
table.insert(parts, encode_value(t[i]))
end
return "[" .. table.concat(parts, ",") .. "]"
else
local parts = {}
for k, v in pairs(t) do
local key_str = (type(k) == "string") and string.format("%q", k) or tostring(k)
table.insert(parts, key_str .. ":" .. encode_value(v))
end
return "{" .. table.concat(parts, ",") .. "}"
end
end

function storage.encode(t)
return encode_value(t)
end

-- 简易 JSON 解析(仅支持本项目的简单数据结构)
local function decode_value(str, pos)
pos = pos or 1

-- 跳过空白
while str:sub(pos, pos):match("%s") do
pos = pos + 1
end

local c = str:sub(pos, pos)

if c == "n" then
-- null
return nil, pos + 4
elseif c == "t" then
return true, pos + 4
elseif c == "f" then
return false, pos + 5
elseif c == '"' or c == "'" then
-- 字符串
local end_char = c
pos = pos + 1
local result = ""
while pos <= #str do
local c2 = str:sub(pos, pos)
if c2 == "\\" then
pos = pos + 1
local next_c = str:sub(pos, pos)
if next_c == '"' then result = result .. '"'
elseif next_c == "'" then result = result .. "'"
elseif next_c == "\\" then result = result .. "\\"
elseif next_c == "n" then result = result .. "\n"
elseif next_c == "t" then result = result .. "\t"
elseif next_c == "u" then
-- 简单处理 unicode(实际项目应使用完整实现)
result = result .. "\\u"
else
result = result .. next_c
end
pos = pos + 1
elseif c2 == end_char then
return result, pos + 1
else
result = result .. c2
pos = pos + 1
end
end
return result, pos
elseif c == "-" or c:match("%d") then
-- 数字
local start = pos
if c == "-" then pos = pos + 1 end
while str:sub(pos, pos):match("[%d%.eE]") do
pos = pos + 1
end
local num_str = str:sub(start, pos - 1)
local num = tonumber(num_str)
return num, pos
elseif c == "[" then
-- 数组
local result = {}
pos = pos + 1
while pos <= #str do
while str:sub(pos, pos):match("%s") do pos = pos + 1 end
if str:sub(pos, pos) == "]" then
return result, pos + 1
end
local val, new_pos = decode_value(str, pos)
table.insert(result, val)
pos = new_pos
while str:sub(pos, pos):match("%s") do pos = pos + 1 end
if str:sub(pos, pos) == "," then pos = pos + 1 end
end
elseif c == "{" then
-- 对象
local result = {}
pos = pos + 1
while pos <= #str do
while str:sub(pos, pos):match("%s") do pos = pos + 1 end
if str:sub(pos, pos) == "}" then
return result, pos + 1
end
local key, new_pos = decode_value(str, pos)
pos = new_pos
while str:sub(pos, pos):match("%s") do pos = pos + 1 end
if str:sub(pos, pos) == ":" then pos = pos + 1 end
local val, new_pos2 = decode_value(str, pos)
pos = new_pos2
result[key] = val
while str:sub(pos, pos):match("%s") do pos = pos + 1 end
if str:sub(pos, pos) == "," then pos = pos + 1 end
end
end

return nil, pos
end

function storage.decode(str)
local val, _ = decode_value(str)
return val
end

-- 文件操作
local data_dir = "data"
local data_file = data_dir .. "/contacts.json"

function storage.load()
local f = io.open(data_file, "r")
if not f then
-- 数据文件不存在,返回初始数据
return {
next_id = 1,
contacts = {},
groups = {}
}
end

local content = f:read("*a")
f:close()

if content and #content > 0 then
local ok, result = pcall(storage.decode, content)
if ok and result then
return result
end
end

return {
next_id = 1,
contacts = {},
groups = {}
}
end

function storage.save(data)
-- 确保目录存在
os.execute("if not exist " .. data_dir .. " mkdir " .. data_dir)

local f = io.open(data_file, "w")
if not f then
return false, "无法写入数据文件"
end

local content = storage.encode(data)
f:write(content)
f:close()
return true
end

return storage

modules/contact.lua——联系人操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
-- contact.lua - 联系人数据操作模块
local contact = {}

-- 加载数据
local storage = require("storage")
local data = storage.load()

-- 辅助函数:获取当前时间字符串
local function now_string()
return os.date("%Y-%m-%d %H:%M:%S")
end

-- 辅助函数:从姓名或电话生成邮箱(如果用户未提供)
local function generate_email(name, phone)
return name .. "_" .. phone:sub(-4) .. "@example.com"
end

-- 添加联系人
function contact.add(name, phone, email, group)
-- 参数验证
if not name or #name == 0 then
return false, "姓名不能为空"
end

if not phone or #phone == 0 then
return false, "电话不能为空"
end

-- 检查电话是否重复
for _, c in ipairs(data.contacts) do
if c.phone == phone then
return false, "电话号码已存在: " .. phone
end
end

-- 处理可选项
email = email or ""
group = group or "未分组"

-- 如果未提供邮箱,自动生成
if #email == 0 then
email = generate_email(name, phone)
end

-- 创建联系人
local new_contact = {
id = data.next_id,
name = name,
phone = phone,
email = email,
group = group,
created_at = now_string()
}

table.insert(data.contacts, new_contact)
data.next_id = data.next_id + 1

-- 更新分组信息
if group and #group > 0 then
local found = false
for _, g in ipairs(data.groups) do
if g == group then
found = true
break
end
end
if not found then
table.insert(data.groups, group)
end
end

-- 保存到文件
storage.save(data)

return true, new_contact
end

-- 列出所有联系人
function contact.list(group_filter)
if group_filter and #group_filter > 0 then
local filtered = {}
for _, c in ipairs(data.contacts) do
if c.group == group_filter then
table.insert(filtered, c)
end
end
return filtered
end
return data.contacts
end

-- 搜索联系人
function contact.search(keyword, field)
field = field or "all"
local results = {}

for _, c in ipairs(data.contacts) do
local match = false

if field == "all" then
match = (c.name:find(keyword, 1, true) ~= nil) or
(c.phone:find(keyword, 1, true) ~= nil) or
(c.group:find(keyword, 1, true) ~= nil)
elseif field == "name" then
match = c.name:find(keyword, 1, true) ~= nil
elseif field == "phone" then
match = c.phone:find(keyword, 1, true) ~= nil
elseif field == "group" then
match = c.group:find(keyword, 1, true) ~= nil
end

if match then
table.insert(results, c)
end
end

return results
end

-- 根据 ID 查找联系人
function contact.find_by_id(id)
for _, c in ipairs(data.contacts) do
if c.id == id then
return c
end
end
return nil
end

-- 修改联系人
function contact.update(id, fields)
local c = contact.find_by_id(id)
if not c then
return false, "联系人不存在"
end

if fields.name and #fields.name > 0 then
c.name = fields.name
end

if fields.phone and #fields.phone > 0 then
-- 检查电话是否与其他联系人重复
for _, other in ipairs(data.contacts) do
if other.id ~= id and other.phone == fields.phone then
return false, "电话号码已被其他联系人使用"
end
end
c.phone = fields.phone
end

if fields.email then
c.email = fields.email
end

if fields.group then
c.group = fields.group
-- 更新分组列表
local found = false
for _, g in ipairs(data.groups) do
if g == fields.group then
found = true
break
end
end
if not found then
table.insert(data.groups, fields.group)
end
end

storage.save(data)
return true, c
end

-- 删除联系人
function contact.delete(id)
for i, c in ipairs(data.contacts) do
if c.id == id then
table.remove(data.contacts, i)
storage.save(data)
return true, c
end
end
return false, "联系人不存在"
end

-- 获取分组列表
function contact.get_groups()
return data.groups
end

-- 获取分组统计
function contact.get_group_stats()
local stats = {}

for _, c in ipairs(data.contacts) do
local group = c.group or "未分组"
stats[group] = (stats[group] or 0) + 1
end

return stats
end

-- 获取联系人总数
function contact.count()
return #data.contacts
end

return contact

modules/ui.lua——用户交互

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
-- ui.lua - 用户界面模块
local ui = {}

local contact = require("contact")

-- 辅助:清屏
function ui.clear_screen()
os.execute("cls || clear")
end

-- 辅助:打印分隔线
function ui.separator(char)
char = char or "="
print(string.rep(char, 50))
end

-- 辅助:暂停等待
function ui.pause()
io.write("按 Enter 键继续...")
io.read()
end

-- 辅助:读取用户输入
function ui.input(prompt, default)
io.write(prompt)
local input = io.read()

if input and #input > 0 then
return input
end
return default
end

-- 辅助:读取数字选择
function ui.input_number(prompt, min, max)
while true do
io.write(prompt)
local input = io.read()
local num = tonumber(input)

if num and num >= min and num <= max then
return num
end

print(string.format("请输入 %d 到 %d 之间的数字", min, max))
end
end

-- 格式化输出联系人列表
local function format_contact(c, index)
local idx = index or c.id
print(string.format("%-3d | %-10s | %-15s | %-25s | %-8s",
idx,
c.name or "",
c.phone or "",
c.email or "",
c.group or ""
))
end

local function print_table_header()
ui.separator("-")
print(string.format("%-3s | %-10s | %-15s | %-25s | %-8s",
"ID", "姓名", "电话", "邮箱", "分组"))
ui.separator("-")
end

-- 打印联系人列表
function ui.print_contacts(contacts, title)
ui.clear_screen()
print(title or "联系人列表")
print_table_header()

if #contacts == 0 then
print("暂无联系人")
else
for _, c in ipairs(contacts) do
format_contact(c)
end
end

ui.separator("-")
print(string.format("共 %d 条记录", #contacts))
end

-- 菜单:查看所有联系人
function ui.show_all_contacts()
local contacts = contact.list()
ui.print_contacts(contacts, "所有联系人")
ui.pause()
end

-- 菜单:搜索联系人
function ui.search_contacts()
ui.clear_screen()
print("搜索联系人")
ui.separator("-")
print("1. 按姓名搜索")
print("2. 按电话搜索")
print("3. 按分组搜索")
print("4. 全局搜索")
print("0. 返回")
ui.separator("-")

local choice = ui.input_number("请选择搜索方式: ", 0, 4)
if choice == 0 then return end

local field_map = {["1"] = "name", ["2"] = "phone", ["3"] = "group", ["4"] = "all"}
local keyword = ui.input("请输入搜索关键词: ")

if not keyword or #keyword == 0 then
print("关键词不能为空")
ui.pause()
return
end

local results = contact.search(keyword, field_map[tostring(choice)])
ui.print_contacts(results, "搜索结果")
ui.pause()
end

-- 菜单:添加联系人
function ui.add_contact()
ui.clear_screen()
print("添加联系人")
ui.separator("-")

local name = ui.input("姓名: ")
if not name or #name == 0 then
print("姓名不能为空,取消添加")
ui.pause()
return
end

local phone = ui.input("电话: ")
if not phone or #phone == 0 then
print("电话不能为空,取消添加")
ui.pause()
return
end

local email = ui.input("邮箱(可选): ")
local group = ui.input("分组(可选): ")

local ok, result = contact.add(name, phone, email, group)
if ok then
print(string.format("添加成功!联系人 ID 为 %d", result.id))
else
print("添加失败: " .. result)
end

ui.pause()
end

-- 菜单:修改联系人
function ui.edit_contact()
local id = tonumber(ui.input("请输入要修改的联系人 ID: "))
if not id then
print("无效的 ID")
ui.pause()
return
end

local c = contact.find_by_id(id)
if not c then
print("联系人不存在")
ui.pause()
return
end

print("当前信息:")
format_contact(c)
ui.separator("-")
print("留空表示不修改")

local name = ui.input(string.format("姓名 [%s]: ", c.name), c.name)
local phone = ui.input(string.format("电话 [%s]: ", c.phone), c.phone)
local email = ui.input(string.format("邮箱 [%s]: ", c.email), c.email)
local group = ui.input(string.format("分组 [%s]: ", c.group), c.group)

local ok, result = contact.update(id, {
name = name,
phone = phone,
email = email,
group = group
})

if ok then
print("修改成功!")
format_contact(result)
else
print("修改失败: " .. result)
end

ui.pause()
end

-- 菜单:删除联系人
function ui.delete_contact()
local id = tonumber(ui.input("请输入要删除的联系人 ID: "))
if not id then
print("无效的 ID")
ui.pause()
return
end

local c = contact.find_by_id(id)
if not c then
print("联系人不存在")
ui.pause()
return
end

print("即将删除以下联系人:")
format_contact(c)

local confirm = ui.input("确认删除?(y/n): ")
if confirm ~= "y" and confirm ~= "Y" then
print("已取消")
ui.pause()
return
end

local ok, result = contact.delete(id)
if ok then
print(string.format("已删除联系人: %s (%s)", result.name, result.phone))
else
print("删除失败: " .. result)
end

ui.pause()
end

-- 菜单:分组信息
function ui.show_groups()
ui.clear_screen()
print("分组信息")
ui.separator("-")

local groups = contact.get_groups()
local stats = contact.get_group_stats()

if #groups == 0 then
print("暂无分组")
else
print(string.format("%-15s | %-5s", "分组名称", "人数"))
ui.separator("-")

table.sort(groups)
for _, g in ipairs(groups) do
print(string.format("%-15s | %-5d", g, stats[g] or 0))
end

ui.separator("-")
print(string.format("总计: %d 个分组, %d 位联系人", #groups, contact.count()))
end

ui.pause()
end

-- 菜单:按分组查看
function ui.show_contacts_by_group()
local groups = contact.get_groups()

if #groups == 0 then
print("暂无分组")
ui.pause()
return
end

ui.clear_screen()
print("选择分组")
ui.separator("-")
for i, g in ipairs(groups) do
print(string.format("%d. %s", i, g))
end
print("0. 返回")
ui.separator("-")

local choice = ui.input_number("请选择: ", 0, #groups)
if choice == 0 then return end

local group_name = groups[choice]
local contacts = contact.list(group_name)
ui.print_contacts(contacts, "分组: " .. group_name)
ui.pause()
end

return ui

15.4 程序入口 main.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- main.lua - 通讯录管理系统入口
package.path = package.path .. ";./modules/?.lua"

local ui = require("ui")
local contact = require("contact")

-- 主菜单
local function show_main_menu()
ui.clear_screen()

print("===== 通讯录管理系统 =====")
print()
print(string.format("当前联系人: %d 位", contact.count()))
print()
print("1. 查看所有联系人")
print("2. 搜索联系人")
print("3. 添加联系人")
print("4. 修改联系人")
print("5. 删除联系人")
print("6. 分组信息")
print("7. 按分组查看")
print("0. 退出")
print()
ui.separator("-")
end

-- 主循环
local function main_loop()
while true do
show_main_menu()

local choice = ui.input_number("请选择操作 [0-7]: ", 0, 7)

if choice == 0 then
print("感谢使用通讯录管理系统,再见!")
break
elseif choice == 1 then
ui.show_all_contacts()
elseif choice == 2 then
ui.search_contacts()
elseif choice == 3 then
ui.add_contact()
elseif choice == 4 then
ui.edit_contact()
elseif choice == 5 then
ui.delete_contact()
elseif choice == 6 then
ui.show_groups()
elseif choice == 7 then
ui.show_contacts_by_group()
end
end
end

-- 启动
local ok, err = xpcall(main_loop, function(err)
print("程序出错:", err)
print("堆栈:", debug.traceback())
end)

if not ok then
print("程序异常退出")
io.write("按 Enter 键退出...")
io.read()
end

15.5 运行与测试

创建项目目录

1
2
3
4
5
6
contact-manager/
├── main.lua
├── modules/
│ ├── contact.lua
│ ├── storage.lua
│ └── ui.lua

运行程序

1
lua main.lua

测试流程

  1. 添加几位联系人(不同分组)
  2. 查看所有联系人列表
  3. 按姓名/电话搜索联系人
  4. 修改联系人信息
  5. 查看分组统计
  6. 删除联系人
  7. 退出程序,重新运行,验证数据持久化

15.6 扩展思路

本项目基础功能已完整,可以进一步扩展:

增强搜索

1
2
3
4
5
-- 模糊搜索(支持拼音首字母等)
-- 高级筛选(组合条件)
function contact.advanced_search(filters)
-- filters = {name = "张", group = "朋友", phone_start = "138"}
end

数据导出

1
2
3
4
5
6
7
8
9
10
-- 导出为 CSV
function contact.export_csv(filename)
local f = io.open(filename, "w")
f:write("ID,姓名,电话,邮箱,分组,创建时间\n")
for _, c in ipairs(data.contacts) do
f:write(string.format("%d,%s,%s,%s,%s,%s\n",
c.id, c.name, c.phone, c.email, c.group, c.created_at))
end
f:close()
end

数据统计

1
2
3
4
5
6
7
8
9
-- 显示联系人分布统计
function contact.stats()
return {
total = #data.contacts,
groups = stats,
newest = data.contacts[#data.contacts], -- 最近添加
duplicated_phone = false -- 检查重复电话
}
end

批量导入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- 从 CSV 批量导入联系人
function contact.import_csv(filename)
local f = io.open(filename, "r")
local headers = f:read()
local count = 0

for line in f:lines() do
local fields = parse_csv_line(line)
contact.add(fields[1], fields[2], fields[3], fields[4])
count = count + 1
end

f:close()
return count
end

15.7 本章小结

通过本实战项目,我们完成了:

  • 模块化设计:将功能拆分为 contactstorageui 三个模块
  • 数据持久化:使用 JSON 格式将数据保存到文件
  • CRUD 操作:完整的增删改查功能
  • 搜索功能:多种方式搜索联系人
  • 分组管理:分组统计和筛选
  • 用户交互:友好的命令行菜单界面
  • 错误处理:输入验证、文件异常处理

回顾本系列学到的 Lua 知识

章节 核心知识点 在项目中的应用
01-02 数据类型、语法 项目结构、变量声明
03 变量与作用域 local 局部变量
04 运算符 字符串连接 ..、比较
05 字符串处理 输入解析、格式化输出、string.format
06 控制结构 主循环、菜单判断
07-08 函数 模块函数、回调
09-10 联系人数据结构、table.inserttable.sort
11 元表 可扩展(数据封装、默认值)
12 面向对象 模块封装模式
13 模块 requirepackage.path
14 标准库、文件 I/O、错误处理 文件读写、pcallxpcall

下一步学习方向

  • LuaJIT:了解 Lua 的 JIT 编译器,大幅提升性能
  • OpenResty:用 Lua 开发高性能 Web 应用
  • XLua/ToLua:在 Unity 中使用 Lua 进行游戏开发
  • Lua 设计模式:观察者模式、状态模式等在 Lua 中的实现
  • Lua 与 C/C++ 交互:深入学习 Lua C API

恭喜你完成了 Lua 基础教程的全部 15 章学习!从零开始到独立完成一个完整的项目,你已经掌握了 Lua 的核心知识。继续加油!

ByteFisher
分享编程技术 · 记录钓鱼乐趣
扫码关注
▸ 扫码关注 ◂
Lua基础教程 系列
第 15/15 篇
分享: