当前位置:网站首页>Lua基础
Lua基础
2022-07-24 05:22:00 【真的没事鸭】
Lua声明的变量默认是全局变量,声明局部变量加local前缀,比如local a表示a是一个局部变量
没有被声明过变量都是nil,类似于其他语言的null
支持多重赋值:a,b=1,2
Lua中有number类型:双精度类型,c中int,float,double等都属于lua的number类型
Lua还支持16机制表示方法,还支持科学计数法,支持左移右移操作
字符串
Lua字符串类型(string):用单引号或双引号表示字符串,支持转义字符
字符串的连接操作不是加号而是两个点,比如字符串a,字符串b,将a和b连接就是a..b
Number转换成字符型:c=tostring(10)
字符型转换成number:n=tonumber(“10”),如果转换失败n就是nil
获得字符串长度:在字符串前面加个#,比如#c可以获得c字符串的长度
Lua函数

也可以这样写

Table:
Table数字下标

用下标提取里面的元素,但是lua下标从1开始
Table里面什么都可以存
插入元素:table.insert(a,”d”)在table a的末尾插入d
也可以指定插入位置:table.insert(a,2,”d”)在table a的第二个位置插入d
移除元素:table.insert(a,,2)移除第二个元素,通过也会把移除的这个元素返回出来
Table 字符串下标:

类似于哈希表
打印元素

添加元素

全局表_G
所有的全局变量都在全局表里面
在lua里面只有false和nil代表假,其他的都代表真,比如0也是真
分支判断语句

用then和end表示一个代码块
循环语句
For循环:

初值1,结束值10,也可以再加个参数:步长

这里步长是2
这里面对i是不能进行更改的

当i等于5时退出循环
While循环

do end是一个代码块
不能用n-=1
边栏推荐
- Conversion of world coordinate system, camera coordinate system and image coordinate system
- js星星打分效果
- Read the qualified line of CSV file and write it to another CSV
- Learning rate optimization strategy
- day1-jvm+leetcode
- 简单却好用:使用Keras 2实现基于LSTM的多维时间序列预测
- 使用Qt连接MySql并创建表号、写入数据、删除数据
- Better CV link collection (dynamic update)
- Hit the wall record (continuously updated)
- JDBC elementary learning ------ (learning from Shang Silicon Valley)
猜你喜欢

Statistical learning methods (2nd Edition) Li Hang Chapter 22 summary of unsupervised learning methods mind mapping notes

Hit the wall record (continuously updated)

Unity基础知识及一些基本API的使用
![[principles of database system] Chapter 5 algebra and logic query language: package, extension operator, relational logic, relational algebra and datalog](/img/6a/c30b139823208a2e021135a4bf8d58.png)
[principles of database system] Chapter 5 algebra and logic query language: package, extension operator, relational logic, relational algebra and datalog

HAL_ Delay() delay error about 1ms

Foundation of JUC concurrent programming (7) -- multithread lock

Xshell remote access tool

Openpose Unity 插件部署教程

AD1256

day2-WebSocket+排序
随机推荐
Opencv reads avi video and reports an error: number < Max_ number in function ‘icvExtractPattern
Qt char型转QString型 16进制与char型 转 16进制整型
简单却好用:使用Keras 2实现基于LSTM的多维时间序列预测
Calculation steps of principal component analysis
Qt 使用纯代码画图异常
bat批处理脚本、同时运行多个文件、按照顺序执行的批处理命令及xshell脚本。
机器学习&深度学习 入门资料分享总结
Bat batch script, running multiple files at the same time, batch commands executed in sequence, and xshell script.
Thymeleaf快速入门学习
信号与系统:希尔伯特变换
[activiti] personal task
Foundation of JUC concurrent programming (6) -- lock lock
C语言链表(创建、遍历、释放、查找、删除、插入一个节点、排序,逆序)
Synergy LAN realizes multi host shared keyboard and mouse (AMD, arm)
day4-jvm
data normalization
JUC concurrent programming foundation (9) -- thread pool
用指针访问一维数组
[MYCAT] MYCAT sub database and sub table
Headlong platform operation