OC-MultICE/modules/net/fgetd.lua

36 lines
663 B
Lua

function fgetd_w(evPP,nid,pth)
local c,S = "",false
if pth:sub(-1) == "/" then
local ft=flist(pth)
if ft then
for k,v in ipairs(ft) do c=c..v.."\n" end S=true
else
c="failed to open dir"
end
else
local f=io.open(pth)
if f then
c=f:read("*a")
f:close()
S=true
else
c="failed to open file"
end
end
print(c)
for i = 1, c:len(), 2048 do
ns(nid,evPP,c:sub(i,i+2047))
C.yield()
end
ns(nid,evPP,".")
return S
end
function fgetd(evPP,preP)
while true do
if ev[1] == "net_msg" and ev[3] == evPP then -- f,p,m
print("[fget] "..TS(ev[4])..": "..tostring(fgetd_w(ev[3],ev[2],preP.."/"..ev[4])))
end
C.yield()
end
end