diff options
author | unknown <Pixel@.(none)> | 2010-01-05 22:22:01 -0800 |
---|---|---|
committer | unknown <Pixel@.(none)> | 2010-01-05 22:22:01 -0800 |
commit | 628ed8138210d0f67cc35835f6fba96fcc7d932f (patch) | |
tree | 0357420e905b42533170ad2d71961373d82c7803 /dalos-luahandle.lua | |
parent | 36624b05efae3fa82280a945fa2eb1dedc84e0b0 (diff) | |
parent | 69836d15333d9d48aecf3e0aef139c7eacf59214 (diff) |
Merge branch 'master' of ssh+git://git.grumpycoder.net/pub/repo.git/Dalos
Diffstat (limited to 'dalos-luahandle.lua')
-rw-r--r-- | dalos-luahandle.lua | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/dalos-luahandle.lua b/dalos-luahandle.lua new file mode 100644 index 0000000..d3615fc --- /dev/null +++ b/dalos-luahandle.lua @@ -0,0 +1,52 @@ +dalosp.luahandle = { + create = function (tab) + local obj = { + offset = 0, + canread = function (self) return true end, + canwrite = function (self) return false end, + canseek = function (self) return true end, + canwatch = function (self) return false end, + tell = function (self) return self.offset end, + getsize = function (self) return self.size end, + getmodif = function (self) return 0 end, + flush = function (self) return true end, + seek = function (self, offset, wheel) + if wheel == SEEK_SET then + self.offset = offset + elseif wheel == SEEK_CUR then + self.offset = self.offset + offset + elseif wheel == SEEK_END then + self.offset = self.size + offset + else + error "Unknown wheel" + end + if self.offset < 0 then self.offset = 0 end + if self.offset >= self.size then self.offset = self.size end + if self.do_seek then self:do_seek() end + return self.offset + end, + read = function (self, userdata, count) + count = math.min(count, self.size - self.offset) + + if count == 0 then + if self.got_eof then self.lh:close() end + self.got_eof = true + return 0 + end + + self.got_eof = false + + local r, t = self:do_read(count, userdata) + self.offset = self.offset + r + if self.post_read then self:post_read(r) end + return r, t + end, + } + for k, v in pairs(tab) do obj[k] = v end + local newh = HandleLua(obj) + obj.lh = newh + return newh + end, +} + +dalos.luahandle = dalosp.luahandle.create |