Use the Lua built-in example to learn about Lua 07 (31-35)

Source: Internet
Author: User
-- Example 31 --[[Standard LibrariesLua has standard built-in libraries for common operations inmath, string, table, input/output & operating system facilities.External LibrariesNumerous other libraries have been created: sockets, XML, profiling,logging, unittests, GUI toolkits, web frameworks, and many more.]]

-- Example 32 -- standard libraries-math.

-- Math functions:-- math.abs, math.acos, math.asin, math.atan, math.atan2,-- math.ceil, math.cos, math.cosh, math.deg, math.exp, math.floor,-- math.fmod, math.frexp, math.huge, math.ldexp, math.log, math.log10,-- math.max, math.min, math.modf, math.pi, math.pow, math.rad,-- math.random, math.randomseed, math.sin, math.sinh, math.sqrt,-- math.tan, math.tanhprint(math.sqrt(9), math.pi)-------- Output ------3 3.1415926535898

-- Example 33 -- standard libraries-string.

-- String functions:-- string.byte, string.char, string.dump, string.find, string.format,-- string.gfind, string.gsub, string.len, string.lower, string.match,-- string.rep, string.reverse, string.sub, string.upperprint(string.upper("lower"),string.rep("a",5),string.find("abcde", "cd"))-------- Output ------LOWER aaaaa 3 4

-- Example 34 -- standard libraries-table.

-- Table functions:-- table.concat, table.insert, table.maxn, table.remove, table.sorta={2}table.insert(a,3);table.insert(a,4);table.sort(a,function(v1,v2) return v1 > v2 end)for i,v in ipairs(a) do print(i,v) end-------- Output ------1 42 33 2

-- Example 35 -- standard libraries-input/output.

-- IO functions:-- io.close , io.flush, io.input, io.lines, io.open, io.output, io.popen,-- io.read, io.stderr, io.stdin, io.stdout, io.tmpfile, io.type, io.write,-- file:close, file:flush, file:lines ,file:read,-- file:seek, file:setvbuf, file:writeprint(io.open("file doesn't exist", "r"))-------- Output ------nil file doesn't exist: No such file or directory 2

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.