lua基础语法

简单的语法,自己留个学习笔记而已

if(0)
then
	print("0 is true")
end

a = 1

if(a)
then
	print("1 is false")
else
	print("a is true")
end

a = 100
if(a == 50)
then
	print("the value of a is 50")
elseif(a == 100)
then	
	print("the value of a is 100")
else
	print("the value of a is not matched")
end

-- test loop of 'for'

days = {'sunday','monday','tuesday','wednesday','thursday','friday','saturday'}
for i,v in ipairs(days) do print(i,v) end

-- test loop of 'repeat'
a = 10
repeat
	print('the value of a is ',a)
	a = a + 1
until(a > 15)

-- test for function in lua
myprint = function(param)
	print("this is print fun ###",param,"###")
end

function add (num1,num2,functionprint)
	result = num1 + num2
	-- call function from passed
	functionprint(result)
end

myprint(100)

add(10,20,myprint)

-- test for the number of args is not sure
function average(...)
	result = 0
	local arg = {...}
	for i,v in ipairs(arg) 
	do
		result = result + v
	end
	print('the number of arg is'..#arg..'size')
	return result/#arg
end

print("the average is ",average(10,5,6,20,2))


运行结果如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值