--------------------------2.1-类型和值---------------------------------------------
--8个基本类型:nil boolean number string userdata function thread table
--[[
print(type("Hello World")) -->string
print(type(10.4*3)) -->number
print(type(print)) -->function
print(type(type)) -->function
print(type(true)) -->boolean
print(type(nil)) -->nil
print(type(type(x))) -->string
----------------------------------------------------
print(type(a)) -->nil
a=10
print(type(a)) -->number
a="a string"
print(type(a)) -->string
a=print
print(type(a)) -->function
--]]
----------------------------------------------------
--[[
a = "one string";
b = string.gsub(a,"one","another")
print(a) -->one string
print(b) -->another string
--]]
----------------------------------------------------
--转义符--
--[[
\a bell
\b back space --后退
\f form feed --换页
\n newline --换行
\r carriage return --回车
\t horizontal tab --制表
\v vertical tab
\\ backslash --"\"
\" double quote --双引号
\' single quote --单引号
\[ left square bracket --左中括号
\] right square bracket --右中括号
--]]
-----------------------------------------------------
--print("one line\nnext line\n\"inquotes\",'in quotes'")
--[[
运行结果:
one line
next line
"inquotes",'in quotes'
--]]
--print('a backslash inside quotes:\'\\\'') -->a backslash inside quotes:'\'
--print("a simpler way: '\\'") -->a simpler way: '\'
------------------------------------------------------------
--使用[[...]]表示字符串--
page=[[
<HTML>
<HEAD>
<TITLE>An HTML Page</TITLE>
</HEAD>
<BODY>
Lua
a text between double brackets
</BODY>
</HTML>
]]
io.write(page)
--------------------------------------------------------
--[[
print("10"+1) -->11
print("10+1") -->10+1
print("-5.3e-10"*"2") -->-1.06e-009
--print("hello"+1) -->ERROR(cannot convert "hello")
print(10 .. 20) --1020
--]]
---------------------------------------------------------
--[[
line = io.read()
n=tonumber(line)
if n==nil then
error(line .. " is not a valid number")
else
print(n*2)
end
--]]
print(tostring(10)=="10") -->true
print(10 .. "" == "10") -->true
--8个基本类型:nil boolean number string userdata function thread table
--[[
print(type("Hello World")) -->string
print(type(10.4*3)) -->number
print(type(print)) -->function
print(type(type)) -->function
print(type(true)) -->boolean
print(type(nil)) -->nil
print(type(type(x))) -->string
----------------------------------------------------
print(type(a)) -->nil
a=10
print(type(a)) -->number
a="a string"
print(type(a)) -->string
a=print
print(type(a)) -->function
--]]
----------------------------------------------------
--[[
a = "one string";
b = string.gsub(a,"one","another")
print(a) -->one string
print(b) -->another string
--]]
----------------------------------------------------
--转义符--
--[[
\a bell
\b back space --后退
\f form feed --换页
\n newline --换行
\r carriage return --回车
\t horizontal tab --制表
\v vertical tab
\\ backslash --"\"
\" double quote --双引号
\' single quote --单引号
\[ left square bracket --左中括号
\] right square bracket --右中括号
--]]
-----------------------------------------------------
--print("one line\nnext line\n\"inquotes\",'in quotes'")
--[[
运行结果:
one line
next line
"inquotes",'in quotes'
--]]
--print('a backslash inside quotes:\'\\\'') -->a backslash inside quotes:'\'
--print("a simpler way: '\\'") -->a simpler way: '\'
------------------------------------------------------------
--使用[[...]]表示字符串--
page=[[
<HTML>
<HEAD>
<TITLE>An HTML Page</TITLE>
</HEAD>
<BODY>
Lua
a text between double brackets
</BODY>
</HTML>
]]
io.write(page)
--------------------------------------------------------
--[[
print("10"+1) -->11
print("10+1") -->10+1
print("-5.3e-10"*"2") -->-1.06e-009
--print("hello"+1) -->ERROR(cannot convert "hello")
print(10 .. 20) --1020
--]]
---------------------------------------------------------
--[[
line = io.read()
n=tonumber(line)
if n==nil then
error(line .. " is not a valid number")
else
print(n*2)
end
--]]
print(tostring(10)=="10") -->true
print(10 .. "" == "10") -->true