内容简介:1.轻量级,编译后不过200K2.可扩展性3.自动内存管理
1.轻量级,编译后不过200K
2.可扩展性
3.自动内存管理
4.支持面向过程编程和函数式编程
……
lua应用场景
1.游戏开发
2.独立应用脚本
3.web应用脚本
4.扩展和数据库插件
5.安全系统
安装使用
安装问题
1.编译 lua 时,提示
lua.c:80:31: fatal error: readline/readline.h: No such file or directory
linux环境缺少readline库。
到ftp://ftp.gnu.org/gnu/readline/ 下载并进行安装
2.安装完readline后提示
/usr/local/lib/libreadline.so: undefined reference to `tputs' /usr/local/lib/libreadline.so: undefined reference to `tgoto' /usr/local/lib/libreadline.so: undefined reference to `tgetflag' /usr/local/lib/libreadline.so: undefined reference to `UP' /usr/local/lib/libreadline.so: undefined reference to `tgetent' /usr/local/lib/libreadline.so: undefined reference to `tgetnum' /usr/local/lib/libreadline.so: undefined reference to `PC' /usr/local/lib/libreadline.so: undefined reference to `tgetstr' /usr/local/lib/libreadline.so: undefined reference to `BC'
需要安装Ncurses
3.编译Ncurses提示 error: expected ‘)’ before ‘int’
导入环境变量,在进行配置编译,安装,命令如下
export CPPFLAGS="-P" ./configure make make install Ncurses
参考:
https://stackoverflow.com/questions/37475222/ncurses-6-0-compilation-error-error-expected-before-int总结:安装成功安装lua的前提是 linux 上有readline和ncurses库.
Hello World
和 Python 类似,它也可以交互式编程,在命令行输入lua后即可进入:
>print("Hello World") Hello World >
当然也可以将脚本内容写在文件,例如,将上面的内容写在hello.lua:
#!/usr/local/bin/lua print("Hello World")
其中第一行指定了lua解释器路径,执行:
$ chmod +x hello.lua #赋予执行权限 $ ./hello.lua Hello World
这里注意,如果你没有加第一行,shell就不知道用哪个解释器去解释运行,当然你也可以通过下面的方式运行:
$ lua hello.lua
注释
同样地,它至少有两种注释,单行注释使用—:
-- 这里是单行注释 print("hello")
多行注释:
--[[ 多行注释 多行注释 --]] print("yanbinghu.com")
语法
数据类型
- nil—表示无效值
- boolean false和true,lua将nil看成是”假”
- number 双精度类型的实浮点数
- string 字符串
- function 由c或lua编写的函数
- userdata 表示任意存储在变量中的c数据结构
- thread 表示执行的独立线路,用于执行协同程序
- table lua中的表,类似于关联数组
判断类型
可以通过type函数来判断数据类型
print(type(“hello”) ) --string print(type(type)) --function
字符串算数操作
在对一个数字字符串上进行算术操作时,Lua 会尝试将这个数字字符串转成一个数字:
例如:
>print(“2” + “6”) 8
- 字符串连接 ..
>print(“a”..”b”) ab
- 计算字符串长度 #
>print(#“a”) 1
table
Lua 里表的默认初始索引一般以 1 开始
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
以匠心,致设计:网易 UEDC 用户体验设计
网易用户体验设计中心 / 电子工业出版社 / 2018-8 / 95.00元
为什么网易云音乐的体验流畅细腻、富有温度?为什么网易严选App的UI设计让人感到温馨、舒适?为什么网易蜗牛读书App的界面设计让用户爱不释手…… 《以匠心,致设计:网易 UEDC 用户体验设计》是网易用户体验设计团队对自身过去的设计思考的精心总结,最大程度还原了网易产品背后的设计故事,内容涵盖设计基础、设计实践、方法思考、成长指南四章,借助网易产品设计的实际案例具体讲述了设计师日常工作中不可......一起来看看 《以匠心,致设计:网易 UEDC 用户体验设计》 这本书的介绍吧!