• 通过lua自带例子学习lua 07 (3135)


    -- Example 31 --[[
    
    Standard Libraries
    
    Lua has standard built-in libraries for common operations in
    math, string, table, input/output & operating system facilities.
    
    External Libraries
    
    Numerous 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.tanh
    
    print(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.upper
    
    print(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.sort
    
    a={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 4
    2 3
    3 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:write
    
    print(io.open("file doesn't exist", "r"))
    
    
    -------- Output ------
    
    nil file doesn't exist: No such file or directory 2
  • 相关阅读:
    python并发编程之深入理解yield from
    python中的多进程编程
    Python并发concurrent、Future类、异步
    【Socket通信】关于Socket通信原理解析及python实现
    深入理解Python元类
    Django RestFrameWork 源码解析
    Django的Restful规范
    小程序colorUI框架初步使用教程
    类似按键精灵的鼠标键盘录制和自动化操作 模拟点击和键入 (KeyMouseGo)
    如何在postgresql中,一句sql完成未有数据记录的insert,再update的操作
  • 原文地址:https://www.cnblogs.com/sdlypyzq/p/3002576.html
Copyright © 2020-2023  润新知