lua学习笔记(1)-基本语法
==============变量类型
nil
number(实数) 1 2 3.14 7.65e8
string "hello world" "\n"
boolean(true false) true false
function
*userdata and threads
table
(1)默认key初始化
t = {a, "hello", b, "world"}
(2)自定义key初始化
t = {n1 = a, n2 = "hello", n3 = b, n4 = "world"}
t.n1 or t[1] or t["n1"]
(3)元素添加赋值
Data = {}
Data.name = "Thardwick"
Data.class = "Barbarian"
Data.str = math.random(3, 18)
Data.dex = math.random(3, 18)
Data[1]
Data.name
Data.["name"]
多维tab
widget = {}
widget.name = {"can opener", "Scissors"}
widget.cost = {"$12.75", "$8.99"}
===============运算符
(实数)算数运算符(字符串转数字)
+
-
*
/
^
字符串运算符(数值转字符串0)
..
关系运算符
==
~=
<
>
<=
>=
逻辑运算符
and
or
not
赋值
a= "hello" .. "world"
n += 1
a, b = b, a
x, y = 1, 2, 3
x, y, z = 1, 2
a, b = func()
=====================if
if xxx then
xxxx
elseif xxx then
xxx
else
xxx
end
======================loop
for index = 1, 10, 1/-1 do
print(index)
end
index = 1
while index < 10 do
print(index)
index = index + 1
end
index = 1
repeat
print(index)
index = index + 1
until index > 10
======================function
function max(a, b, c)
local x = a + b
return sum, c
end
res1, res2 = foo(1, )
function print_args(...)
if arg.n <= 0 then0
return
end
for index = 1, arg.n do
print("arg", index, ":", arg[index])
end
end
function get_min(tab)
str = "min = math.min("
for index, value in ipaies(tab) do
str = string.format("%s%d%s", str, value, ",")
end
str = string.sub(str, 1, string.len(str) -1 )
str = string.format(str, "%s%s", str, ")")
loadstring(str)
return min
end
lua学习笔记(1)-基本语法的更多相关文章
- lua学习笔记1--基础语法
print("打印日志");--单行注释 --[[ 多行注释 --]] a = --变量的类型,是由变量储存的数据决定 数据类型: number:数值类型,可以存储整数和小数 bo ...
- [转]LUA 学习笔记
Lua 学习笔记 入门级 一.环境配置 方式一: 1.资源下载http://www.lua.org/download.html 2.用src中的源码创建了一个工程,注释调luac.c中main函数,生 ...
- Lua 学习笔记(一)
Lua学习笔记 1.lua的优势 a.可扩张性 b.简单 c.高效率 d.和平台无关 2.注释 a.单行注释 -- b.多行注释 --[[ --]] 3.类型和 ...
- Lua学习笔记:面向对象
Lua学习笔记:面向对象 https://blog.csdn.net/liutianshx2012/article/details/41921077 Lua 中只存在表(Table)这么唯一一种数据结 ...
- Lua学习笔记6:C++和Lua的相互调用
曾经一直用C++写代码.话说近期刚换工作.项目组中的是cocos2dx-lua,各种被虐的非常慘啊有木有. 新建cocos2dx-lua项目.打开class能够发现,事实上就是C++项 ...
- Lua学习笔记4. coroutine协同程序和文件I/O、错误处理
Lua学习笔记4. coroutine协同程序和文件I/O.错误处理 coroutine Lua 的协同程序coroutine和线程比较类似,有独立的堆栈.局部变量.独立的指针指令,同时又能共享全局变 ...
- (转)Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境
Lua学习笔记1:Windows7下使用VS2015搭建Lua开发环境(一)注意:工程必须添加两个宏:“配置属性”/“C或C++”/“预处理器”/“预处理器定义”,添加两个宏:_CRT_SECURE_ ...
- python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样
python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样,IDLE shell编辑器,快捷键:ALT+p,上一个历史输入内容,ALT+n 下一个历史输入 ...
- ASP.NET MVC 学习笔记-2.Razor语法 ASP.NET MVC 学习笔记-1.ASP.NET MVC 基础 反射的具体应用 策略模式的具体应用 责任链模式的具体应用 ServiceStack.Redis订阅发布服务的调用 C#读取XML文件的基类实现
ASP.NET MVC 学习笔记-2.Razor语法 1. 表达式 表达式必须跟在“@”符号之后, 2. 代码块 代码块必须位于“@{}”中,并且每行代码必须以“: ...
随机推荐
- uva 123 Searching Quickly
Searching Quickly Background Searching and sorting are part of the theory and practice of computer ...
- windows系统部署discuz并和javaweb账号连通同步
一.Discuz安装说明 1.安装wamp集成环境 (1)下载wampserver集成环境 网址:(http://wampserver-64bit.en.softonic.com)或百度搜索下载 (2 ...
- Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃
在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java. ...
- java 使用pem密钥进行RSA加解密
1.使用openssl生成私钥和公钥 openssl下载地址:http://www.openssl.org/source openssl生成私钥命令: genrsa -out rsa_private ...
- 在Win8上安装pyinstaller打包python成为可执行文件
首先我使用的电脑系统是: Windows-8-6.2.9200 Python的版本是: 2.7.8 默认已安装python2.7且设置好了环境变量. 仅为个人记录,非教程. 首先先安装pip: 首先先 ...
- Monthly Expense(二分) 分类: 二分查找 2015-06-06 00:31 10人阅读 评论(0) 收藏
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- HDOJ-1002 A + B Problem II (非负大整数相加)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h ...
- win7 Visual Studio 2008 安装程序时出现“ 加载安装组件时遇到问题。取消安装。”处理方法
win7 Visual Studio 2008 安装程序时出现“ 加载安装组件时遇到问题.取消安装.”处理方法 vs2008试用期到期,卸载.重新安装都会出现“ 加载安装组件时遇到问题.取消安装.”无 ...
- 解决ZBarSDK 中文出现乱码
使用ZBarSDK进行二维码解释时出现乱码是因为ZBarSDK在解释时使用的字符集不对,需在ZBarSDK的源码中更正. 1.可以到http://sourceforge.net/p/zbar/_lis ...
- PHP - Mysql数据库备份类
使用方法: require_once("backdata.class.php"); $link =@mysql_connect("localhost",&quo ...