Lua的初探学习
来源:互联网 发布:风火轮软件 编辑:程序博客网 时间:2024/06/05 00:16
Lua语言开发 lua.org
**LuaInterface**
通过LuaInterface完成Lua和C#之间的互相调用
lua解析工具
1.ulua ulua.org
2.Nlua nlua.org
3.UniLua
4.sLua
lua安装
A.Luaforwindows
B.luaer.cn lua开发者
C.luaforge.net
1.安装luaforwindows
2.使用SciTE.exe 编写代码
lua语言(不需要以;结尾)
1.字符串用"" 或 ‘’ 均可表示 如: print("hello world",‘hello world’)
2.变量不要定义类型,直接赋值 如:age=100 name="Jane" isMan=false
3.单行注释: -- 多行注释: --[[ 注释内容 ]]--
4.nil表示空,等同C#中的null
5.lua没有整数类型,只有小数类型
6.lua的五种变量类型:
①空数据
②boolean布尔类型
③string字符串类型
④number小数类型
⑤table表类型
7.可以用type()直接获得一个变量的类型
8.table: myTable={34,134,1344,1354,6}
myTable[1]=34
lua的索引都从1开始
9.lua中所有默认定义的变量都是全局变量
局部变量的定义需在变量前加local local name="law"
10.运算符
①算数运算符 + - * / % (lua中没有++ -- 这样的运算符)
②关系运算符 <= < > >= ==
③逻辑运算符 and or not 分别表示 与 或 非(类似于C#的 && || !)
and = && or = || not = !
11.if逻辑
1.if 条件 then
执行逻辑
end
2.if 条件 then
执行逻辑
else
执行逻辑
end
3.if 条件 then
执行逻辑
elseif 条件 then
执行逻辑
else
执行逻辑
end
如:
hp = 60
if hp<50 then
print("血量少于50")
elseif hp<0 then
print("血量少于0")
else
print("血量大于50")
end
12.while循环
while 条件 do
执行逻辑
end
13.repeat循环
repeat
执行逻辑
until 条件
(当条件满足时跳出循环)
14.for循环
for index = [start],[end] do
执行逻辑
end
(break结束循环,但没有C#中continue语法)
如:for index=1,100 do
print(index)
15.函数定义
function 方法名(参数一,参数二)
执行逻辑
end
如:function Plus(num1,num2)
return num1+num2
end
16.lua内置的常用函数(自行查找lua开发文档)
①数学处理的math相关函数
②字符串处理的string相关函数
③表处理的table相关函数
④文件操作的io相关函数
如:
print(math.abs(-100))
print(math.max(1,2,3,5,54,5))
17.string字符串
.. 表示字符串的相加
tostring() 把一个数字转化为字符串
tonumber() 把一个字符串转化为数字
如:
one = "abc"
two = "def"
english = one..two
print(english)
18.table表:键值对
表的长度=table.getn(表名)
赋值方法:
①纯数字键
myTable = {12,535,1,41,58,4,8}
②非纯数字键
--定义一个空表
myTable ={}
myTable.name = "表的第一个值"
mytable["age"] = "表的第二个值"
myTable.num = 3
遍历方法:
①纯数字键遍历
for index=1,table.getn(表名) do
运行逻辑
end
②所有表遍历
for index,value in pairs(表名)do
运行逻辑
print(index,value)
end
*****通过表来实现面向对象*************
Enemy={} --声明怪物对象
local this = Enemy --声明this为怪物对象
--声明对象属性
this.name="BigBoss"
this.hp =100
--声明对象中的方法
①this.SayHello = function()
print("Hello,My name is"..this.name)
end
②function Enemy.attack()
this.SayHello
print("我在打你!")
end
**LuaInterface**
通过LuaInterface完成Lua和C#之间的互相调用
lua解析工具
1.ulua ulua.org
2.Nlua nlua.org
3.UniLua
4.sLua
lua安装
A.Luaforwindows
B.luaer.cn lua开发者
C.luaforge.net
1.安装luaforwindows
2.使用SciTE.exe 编写代码
lua语言(不需要以;结尾)
1.字符串用"" 或 ‘’ 均可表示 如: print("hello world",‘hello world’)
2.变量不要定义类型,直接赋值 如:age=100 name="Jane" isMan=false
3.单行注释: -- 多行注释: --[[ 注释内容 ]]--
4.nil表示空,等同C#中的null
5.lua没有整数类型,只有小数类型
6.lua的五种变量类型:
①空数据
②boolean布尔类型
③string字符串类型
④number小数类型
⑤table表类型
7.可以用type()直接获得一个变量的类型
8.table: myTable={34,134,1344,1354,6}
myTable[1]=34
lua的索引都从1开始
9.lua中所有默认定义的变量都是全局变量
局部变量的定义需在变量前加local local name="law"
10.运算符
①算数运算符 + - * / % (lua中没有++ -- 这样的运算符)
②关系运算符 <= < > >= ==
③逻辑运算符 and or not 分别表示 与 或 非(类似于C#的 && || !)
and = && or = || not = !
11.if逻辑
1.if 条件 then
执行逻辑
end
2.if 条件 then
执行逻辑
else
执行逻辑
end
3.if 条件 then
执行逻辑
elseif 条件 then
执行逻辑
else
执行逻辑
end
如:
hp = 60
if hp<50 then
print("血量少于50")
elseif hp<0 then
print("血量少于0")
else
print("血量大于50")
end
12.while循环
while 条件 do
执行逻辑
end
13.repeat循环
repeat
执行逻辑
until 条件
(当条件满足时跳出循环)
14.for循环
for index = [start],[end] do
执行逻辑
end
(break结束循环,但没有C#中continue语法)
如:for index=1,100 do
print(index)
15.函数定义
function 方法名(参数一,参数二)
执行逻辑
end
如:function Plus(num1,num2)
return num1+num2
end
16.lua内置的常用函数(自行查找lua开发文档)
①数学处理的math相关函数
②字符串处理的string相关函数
③表处理的table相关函数
④文件操作的io相关函数
如:
print(math.abs(-100))
print(math.max(1,2,3,5,54,5))
17.string字符串
.. 表示字符串的相加
tostring() 把一个数字转化为字符串
tonumber() 把一个字符串转化为数字
如:
one = "abc"
two = "def"
english = one..two
print(english)
18.table表:键值对
表的长度=table.getn(表名)
赋值方法:
①纯数字键
myTable = {12,535,1,41,58,4,8}
②非纯数字键
--定义一个空表
myTable ={}
myTable.name = "表的第一个值"
mytable["age"] = "表的第二个值"
myTable.num = 3
遍历方法:
①纯数字键遍历
for index=1,table.getn(表名) do
运行逻辑
end
②所有表遍历
for index,value in pairs(表名)do
运行逻辑
print(index,value)
end
*****通过表来实现面向对象*************
Enemy={} --声明怪物对象
local this = Enemy --声明this为怪物对象
--声明对象属性
this.name="BigBoss"
this.hp =100
--声明对象中的方法
①this.SayHello = function()
print("Hello,My name is"..this.name)
end
②function Enemy.attack()
this.SayHello
print("我在打你!")
end
19.通过LuaInterface完成Lua和C#之间的互相调用
0 0
- Lua的初探学习
- lua学习初探【一】
- lua学习初探【二】
- lua脚本的初探
- Lua学习笔记--Lua调用C初探
- Lua学习笔记--函数初探
- Lua学习第二课_初探lua和lua语法
- Lua语言学习之初探索
- LuaJava学习笔记[1]初探Lua
- Lua 初探
- Lua初探
- lua初探
- Android的学习初探
- DELPHI中集成LUA脚本学习笔记1_初探LUA
- lua函数的学习
- lua的学习笔记
- lua 学习的博客
- Lua的学习
- OpenCV249和VS2010配置
- 网易2017实习生笔试编程题-魔力手环
- spark 数据倾斜解决方案 (二)聚合源数据以及过滤导致倾斜的key
- cocos2d默认创建的HelloWorld是竖屏
- 深度学习中的激活函数导引
- Lua的初探学习
- 创建SVN版本库
- 妙用ES6解构和扩展运算符让你的代码更优雅
- 从MVC和三层架构说到ssh整合开发(上)
- 牛客网-循环单词
- scrapy中spider
- loadrunner回放时报Error -26377(web_reg_save_param)
- H5本地化存储
- 2001 计算两点间的距离