[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] luamem: mmap, buffer (filter)
- From: Nodir Temirhodzhaev <nvtem@...>
- Date: Thu, 2 Dec 2004 21:25:55 -0800 (PST)
http://lua-users.org/files/wiki_insecure/users/tnodir/
Examples:
-- :: File Map (LuaSys required) ::
if sys then
local f = assert(sys.handle():create"fmap")
f:seek(31); f:write" "
do
local map = assert(mem.map(f, "w"))
map[0] = "Mapped file..."
mem.free(map)
end
f:close()
os.remove"fmap"
end
-- :: Buffer ::
local buf = assert(mem.buffer())
local s = "append string to buffer"
buf:write(s)
if string.len(s) ~= buf:seek()
or s ~= buf:getstring() then
error"buffer:write"
end
mem.free(buf)
-- :: Buffer Filter ::
local stream = {
data = "characters\nnewline\nnext";
read = function(self)
local data = self.data
self.data = nil
return data
end;
write = function(self, data)
self.data = data
return true
end
}
local buf = assert(mem.buffer())
buf:input(stream)
while true do
local l = buf:read"*l"
if not l then break end
print('>', l)
end
buf:output(stream)
local s = "auto-flush"
buf:write(s)
buf:flush()
assert(stream.data == s)
mem.free(buf)
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo