Created
July 31, 2016 01:17
-
-
Save CoderPuppy/02a16a055082bc861c3f5c36e01768a7 to your computer and use it in GitHub Desktop.
Actual VFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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