Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
Created July 31, 2016 01:17
Show Gist options
  • Save CoderPuppy/02a16a055082bc861c3f5c36e01768a7 to your computer and use it in GitHub Desktop.
Save CoderPuppy/02a16a055082bc861c3f5c36e01768a7 to your computer and use it in GitHub Desktop.
Actual VFS
local VFS = {
['test'] = 'hello?\nwho\'s there?';
}
VFS_ENV.fs = setmetatable({}, { __index = fs })
function VFS_ENV.fs.open(path, mode)
local handle = {}
if mode == 'r' then
if VFS[path] then
local data = VFS[path]
function handle.readLine()
if #data > 0 then
local line, rest = data:match '^([^\n\r]*)[\n\r](.*)$'
if line then
data = rest
return line
else
return data
end
end
end
function handle.readAll()
if #data > 0 then
local t = data
data = ''
return t
end
end
else
return fs.open(path, mode)
end
elseif mode == 'rb' then
if VFS[path] then
local data = VFS[path]
function handle.read()
if #data > 0 then
local t = data:sub(1, 1):byte()
data = data:sub(2)
return t
end
end
else
return fs.open(path, mode)
end
end
return handle
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment