Slog54_lua_表、模块和包

  • ArthurSlog
  • SLog-54
  • Year·1
  • Guangzhou·China
  • Aug 30 2018

三观拼不过五官 之前五官是没法提高的 但三观能够动 因此咱们宣扬三观 如今五官也能够动了 并且提高的效益比三观来的直接和明显 因此那些坚守三观的人更要宣扬三观了 由于他们当他们没法提高五官的时候 惟一能作的 就是高举三观打压五官了html


开发环境MacOS(High Sierra 10.13.5)

须要的信息和信息源:

开始编码

  • lua的表是一种数据结构,同时还能够做为模块和包,其余的程序能够引用这些写好的模块和包,以提升效率
  • 完整代码:

~/Desktop/lua_learningload/lua_table/table_1.luagit

-- 文件名为 table_1.lua
-- 定义一个名为 table_1 的模块
table_1 = {}
 
-- 定义一个常量
table_1.constant = "This is a constant value"
 
-- 定义一个函数
function table_1.f1()
    io.write("This is a public function!\n")
end
 
local function f2()
    print("This is a privacy function!")
end
 
function table_1.f3()
    f2()
end
 
return table_1

~/Desktop/lua_learningload/lua_table/run.luagithub

-- run.lua 文件
-- table_1 模块为上文提到到 table_1.lua
-- 别名变量 m
local t = require("table_1")
 
print(t.constant)
 
t.f1()
t.f3()
  • 切换之当前文件路径下
cd ~/Desktop/lua_learningload/lua_table/
  • 执行程序
lua ./run.lua
  • 执行结果:
This is a constant value
This is a public function!
This is a privacy function!
  • 至此,咱们编写了一个lua模块,也叫作lua包(其实就是一个lua表),掌握了对lua包导入的操做。

欢迎关注个人微信公众号 ArthurSlog

关注微信公众号“ArthurSlog”

若是你喜欢个人文章 欢迎点赞 留言

谢谢

相关文章
相关标签/搜索