93 lines
No EOL
1.9 KiB
Lua
93 lines
No EOL
1.9 KiB
Lua
--tiny lua class
|
|
|
|
|
|
local tdf = require("tdf")
|
|
|
|
local filemt = {}
|
|
|
|
function filemt:close()
|
|
tdf.close(self.handle)
|
|
end
|
|
|
|
function filemt:save()
|
|
tdf.save(self.handle)
|
|
end
|
|
|
|
function filemt:defined(path)
|
|
return tdf.defined(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:getint(path)
|
|
return tdf.getint(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:getfloat(path)
|
|
return tdf.getfloat(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:getstring(path)
|
|
return tdf.getstring(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:getbool(path)
|
|
return tdf.getbool(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:getchar(path)
|
|
local c = tdf.getchar(self.handle, unpack(path))
|
|
return string.byte(c)
|
|
end
|
|
|
|
function filemt:getpointer(path)
|
|
return {tdf.getpointer(self.handle, unpack(path))}
|
|
end
|
|
|
|
function filemt:getclass(path)
|
|
return tdf.getclass(self.handle, unpack(path))
|
|
end
|
|
|
|
function filemt:setint(path, value)
|
|
tdf.setint(self.handle, unpack(path), value)
|
|
end
|
|
|
|
function filemt:setfloat(path, value)
|
|
tdf.setfloat(self.handle, unpack(path), value)
|
|
end
|
|
|
|
function filemt:setstring(path, value)
|
|
tdf.setstring(self.handle, unpack(path), value)
|
|
end
|
|
|
|
function filemt:setblock(path, value)
|
|
tdf.setblock(self.handle, unpack(path), value)
|
|
end
|
|
|
|
function filemt:setbool(path, value)
|
|
tdf.setbool(self.handle, unpack(path), value)
|
|
end
|
|
|
|
function filemt:setchar(path, value)
|
|
tdf.setchar(self.handle, unpack(path), string.char(value))
|
|
end
|
|
|
|
function filemt:setpointer(path, tbl)
|
|
tdf.setpointer(self.handle, unpack(path), unpack(tbl))
|
|
end
|
|
|
|
function filemt:define(names, classname)
|
|
tdf.define(self.handle, names, classname)
|
|
end
|
|
|
|
local function open(filepath)
|
|
local ok, handle = pcall(tdf.read, filepath)
|
|
if not ok then
|
|
error(handle)
|
|
end
|
|
local obj = {handle = handle}
|
|
setmetatable(obj, {__index = filemt})
|
|
return obj
|
|
end
|
|
|
|
return {
|
|
open = open
|
|
} |