mirror of
https://github.com/lunarmodules/lua-iconv.git
synced 2025-06-23 04:34:33 +02:00
Make module usage cleaner, removing all global symbols
The 'module' function was also deprecated in Lua 5.2.0.
This commit is contained in:
parent
0879d77e1a
commit
e9f3a5e377
15
uniopen.lua
15
uniopen.lua
@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
-- Simple (and incomplete) Unicode I/O layer.
|
-- Simple (and incomplete) Unicode I/O layer.
|
||||||
|
|
||||||
module("uniopen", package.seeall)
|
local iconv = require("iconv")
|
||||||
|
|
||||||
require "iconv"
|
local m = { }
|
||||||
|
local mti = { }
|
||||||
|
local mt = { __index = mti }
|
||||||
|
|
||||||
local mt = { __index = _M }
|
function m.open(fname, mode, fromcharset, tocharset)
|
||||||
|
|
||||||
function open(fname, mode, fromcharset, tocharset)
|
|
||||||
assert(mode == "r" or mode == "rb", "Only read modes are supported yet")
|
assert(mode == "r" or mode == "rb", "Only read modes are supported yet")
|
||||||
tocharset = tocharset or "utf8"
|
tocharset = tocharset or "utf8"
|
||||||
local cd = assert(iconv.new(fromcharset, tocharset), "Bad charset")
|
local cd = assert(iconv.new(fromcharset, tocharset), "Bad charset")
|
||||||
@ -20,7 +20,7 @@ function open(fname, mode, fromcharset, tocharset)
|
|||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|
||||||
function read(fp, mod)
|
function mti.read(fp, mod)
|
||||||
assert(fp and fp.fp and fp.cd, "Bad file descriptor")
|
assert(fp and fp.fp and fp.cd, "Bad file descriptor")
|
||||||
local ret = fp.fp:read(mod)
|
local ret = fp.fp:read(mod)
|
||||||
if ret then
|
if ret then
|
||||||
@ -30,8 +30,9 @@ function read(fp, mod)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function close(fp)
|
function mti.close(fp)
|
||||||
assert(fp and fp.fp, "Bad file descriptor")
|
assert(fp and fp.fp, "Bad file descriptor")
|
||||||
fp.fp:close()
|
fp.fp:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return m
|
||||||
|
Loading…
x
Reference in New Issue
Block a user