[转载]lua实例

楼主
[转载]lua实例
[P][B] md5 [Cryptographic Library for Lua][/B] [/P][P]
[/P]文档=============    Refer to luamd5 documentation范例=======--// script example START -----------------------------------------------------package.cpath = "./lib/?.so;./lib/?.dll;./lib/?.dylib;"require "md5"  local key = 'xuxu bacana'  local origin='hello'  local crypt = md5.crypt(origin, key)  local decrypt = md5.decrypt(crypt, key)  print("origin=>"..origin)  print("crypt=>"..crypt)  print("decrypt=>"..decrypt)--// script example STOP -----------------------------------------------------md5的相关信息[P]
[/P]        version     1.1.1        website     http://luaforge.net/projects/md5/        author      Andre Carregal, Tomas Guisasola, Danilo Tuler, Fabio Mascarenhas
1楼
socket:provides easy access to TCP, UDP, DNS, SMTP, FTP, HTTP, MIME and much more.
文档
=============

    Refer to luasocket documentation

范例
=======

    Here is a small TCP Server example

--// script n�1 example START -----------------------------------------------------
package.cpath = "./lib/?.so;./lib/?.dll;./lib/?.dylib;"
require("socket")

    local host = "*"
    local port = 8080
    print("Binding to host '" ..host.. "' and port " ..port.. "...")
    local sock, err = socket.tcp()
    if not sock then error("Error socket tcp() : "..err) end
    sock:setoption("reuseaddr", true)
    local res, err = sock:bind(host, port)
    if not res then error("Error socket bind() : "..err) end
    res, err = sock:listen(5)
    if not res then error("Error socket listen() : "..err) end
    i, p   = sock:getsockname()
    assert(i, p)
    print("Waiting connection from talker on " .. i .. ":" .. p .. "...")
    c = assert(sock:accept())
    print("Socket connected")
    l, e = c:receive(1)
    while not e do
        print(l)
        l, e = c:receive(1)
    end
    print("Socket "..e)
--// script n�2 example STOP -----------------------------------------------------

    Here is a small TCP Client example

--// script n�2 example STOP -----------------------------------------------------
package.cpath = "./lib/?.so;./lib/?.dll;./lib/?.dylib;"
require("socket")

    local tcp = socket.tcp
    local sock, err = socket.tcp()
    if not sock then
        error("Error socket.tcp() : "..err)
    else
        local res, err = sock:connect("127.0.0.1", 8080)
        if not res then
           error("Error sock:connect() : "..err)
        else
            local nb, err = sock:send("hello\r\n")
            print(nb.." characters sent")
        end
    end
--// script n�2 example STOP -----------------------------------------------------


socket的相关信息
        version     2.0.2
        website     http://luaforge.net/projects/luasocket/
        author      Danilo Tuler, Diego Nehab

2楼
gzip [access gzip library functions]
文档
=============

    Refer to luagzip documentation

范例
=======


--// script example START -----------------------------------------------------
package.cpath = "./lib/?.so;./lib/?.dll;./lib/?.dylib;"
require "gzip"

    --// Compress a file
    local ofile = gzip.open("testluazlib.gz", "wb9")
    if (not ofile) then
        print("Failed to open file testluazlib.gz for writing")
    else
        for i = 1, 100 do
            ofile:write(i, "\n")
        end
        print("File testluazlib.gz successfully written")
    end
    ofile:close()
   
    --// Decompress a file
    local ifile = gzip.open("testluazlib.gz")
    if (not ifile) then
        print("Failed to open file testluazlib.gz for reading")
    else
        for i = 1, 100 do
            if (tostring(i) ~= ifile:read("*l")) then
                print("error in file detected : "..tostring(i))
            end
        end
        print("File testluazlib.gz successfully read")
    end
    ifile:close()
--// script example STOP -----------------------------------------------------



gzip的相关信息
        version     not defined
        website     http://mega.ist.utl.pt/~tngd/lua/
        author      Tiago Dionizio

电脑版 Page created in 0.0781 seconds with 4 queries.