我的第一个lua程序之声明变量和逻辑运算符

来源:互联网 发布:通达信均线公式源码 编辑:程序博客网 时间:2024/05/17 08:08
--注释:我的第一个lua程序print("test")io.write("Hello world, from ",_VERSION,"!\n")local a=12  --声明局部变量local d , f = 5 ,10 --declaration of d and f as local variables. d , f = 5, 10;      --声明全局变量d, f = 10           --[[declaration of d and f as global variables.                         Here value of f is nil --]]print ("d=",d);function add(a,b)  local c=a+b;  return c;end--http://www.yiibai.com/lua/lua_data_types.htmlfunction printType()  print(type("What is my type"))   --> string  t=10  print(type(5.8*t))               --> number  print(type(true))                --> boolean  print(type(print))               --> function  print(type(type))                --> function  print(type(nil))                 --> nil  print(type(type(ABC)))           --> stringend--逻辑运算符测试--http://www.yiibai.com/lua/lua_logical_operators.htmlfunction lua_logical_operators()a = 5b = 20if ( a and b )then   print("Line 1 - Condition is true" )endif ( a or b )then   print("Line 2 - Condition is true" )end--lets change the value ofa and ba = 0b = 10if ( a and b )then   print("Line 3 - Condition is true" )else   print("Line 3 - Condition is not true" )endif ( not( a and b) )then   print("Line 4 - Condition is true" )else   print("Line 3 - Condition is not true" )endend-- Variable definition:local a, b-- Initializationa = 10b = 30print("value of a:", a)print("value of b:", b)-- Swapping of variablesb, a = a, bprint("value of a:", a)print("value of b:", b)f = 70.0/3.0print("value of f", f)print("add result c=", add(a,b))printType();a = "Hello "b = "World"print("链接字符串 a with b is ", a..b )print("Length of b is=",#b ) --去字符串长度print("Length of b is=",#"Test" )lua_logical_operators();

0 0
原创粉丝点击