用的是Lunar封装

学习笔记, 是直接从pil(http://www.lua.org/pil/index.html)文档里翻译

第一部分:

1.从lua交互状态退出的方法
^+D, ^+Z, os.exit()

2.lua可连续运行两个文件, 如:
lua -la -lb
其中, l是连接符, 不可少. a,b是两个不同的文件, 这个对于测试和debug特别有效

3.dofile可用于立即执行文件

4.全局变量不需要声明,赋值时即同时声明, 所以应该在初始化时进行赋值
如果要删除全局变量, 用nil删除; 而如果只是局部使用某变量,应该声明成局部量local

5.lua中的关键字不能以数字开头, 只能以字母和下划线开头, 组成元素可以是字母, 数字和下划线

6.保留字不能用作关键字(废话, 几乎所有语言皆如此),lua是严格区分大小写的

7.块注释用--[[ 语句 ]], 行注释用-- , 无效的块注释:
----[[
--]]

8.lua的命令行用法:
lua [options] [script [args]]
如:
lua -e "print(math.sin(12))", -e选项表示直接执行后面的语句

9.lua -i -l a.lua -e "x = 10"
含义:
-i表示进入交互式, -l表示装入a.lua文件, 而-e则表示执行其后的语句. 所以连起来就是执行a.lua, 执行x=10, 然后进入交互状态

10.通过: lua -i -e "_PROMPT='lua>'"的方式可以改变lua交互状态下的提示符

11.lua的命令行参数用法:

prompt> lua -e "sin=math.sin" script a b

lua collects the arguments as follows:
    arg[-3] = "lua"
    arg[-2] = "-e"
    arg[-1] = "sin=math.sin"
    arg[0] = "script"
    arg[1] = "a"
    arg[2] = "b"

arg是它的命令行参数表


Lua学习笔记之 Type and Values

LUA学习笔记3 - Compilation, Execution, and Errors
http://www.luaer.cn
 
LUA学习笔记2-Iterators and the Generic for
http://www.luaer.cn
 
LUA学习笔记1-Functions
http://www.luaer.cn

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-01
  • 2022-01-05
  • 2021-08-21
  • 2021-04-29
  • 2022-02-05
  • 2022-12-23
相关资源
相似解决方案