lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Because I got a few requests by mail a few examples:

File operations:
local nixio = require "nixio", require "nixio.util"
local file ="myfile", "w")		-- Open myfile for writing
file:writeall("somedata")				-- Write some buffer into a file
file:seek(5)						-- Seek to offset 5
file:lock("lock", 2)					-- Lock 2 bytes beginning from current offset

FS operations:
local fs = require "nixio.fs"
for entry in fs.dir("/tmp") do print(entry) end	-- Traverse directory
fs.copyr("/tmp", "/tmp/tmp2")				-- Recursive copying

local nixio = require "nixio", require "nixio.util"
local newmd5 = nixio.crypto.hash("md5")
newmd5:update("Lorem ipsum")
print((newmd5:update("some stuff"):final()))

local nixio = require "nixio", require "nixio.util"
-- local mysock = nixio.connect("", 443)	-- IPv6 is supported
local mysock = nixio.connect("", 443)	-- Open TCP connection
local mytlssock = nixio.tls("client"):create(mysock)	-- TLS context and socket
mytlssock:connect()							-- TLS Handshake
mytlssock:writeall("GET / HTTP/1.0\r\n\r\n")		-- High-level write