i basically want to make a virtualbox-based system in cc, basically if LyqydOS tried to run in it, and tried to save a file as "/LyqydOS/data" then it would save as "/emu/LyqydOS/data" if you get what im saying
is there any way to do this?
Craftception
Started by Creeper9207, Jun 27 2015 12:08 AM
8 replies to this topic
#1
Posted 27 June 2015 - 12:08 AM
#2
Posted 27 June 2015 - 12:18 AM
If understand what you're asking correctly, you could modify the fs api to append your base directory to any path trying to be read/written to. However, you'll need to make sure that callers can still access the 'rom' files.
Maybe something like this?
This is, of course, untested.
Maybe something like this?
local baseDir = "/emu/"
local oldFs = {}
for name, func in pairs(_G.fs) do
oldFS[name] = func
end
for name, func in pairs(oldFs) do
_G.fs[name] = function(path, ...)
path = shell.resolve(path)
if oldFS.isReadOnly(path) then
return oldFs[name](path, ...)
end
return oldFs[name](baseDir .. path, ...)
end
end
This is, of course, untested.
#3
Posted 27 June 2015 - 04:30 AM
How would I modify the fs api?
#4
Posted 27 June 2015 - 06:07 AM
That is not needed:
Just use
The fs api table is not read only
you can use
Grim Reaper, on 27 June 2015 - 12:18 AM, said:
for name, func in pairs(_G.fs) do oldFS[name] = func end
local oldFS = _G.fs
Creeper9207, on 27 June 2015 - 04:30 AM, said:
How would I modify the fs api?
you can use
fs.open = function() --somestrangecode xD end
Edited by Luca0208, 27 June 2015 - 06:07 AM.
#5
Posted 27 June 2015 - 06:12 AM
Oh btw Grim, your code would override fs.combine() so this code:
/emu/emu/testdir/fileintestdir
path1 = "testdir" path2 = "fileintestdir" path = fs.combine(path1,path2) fs.open(path,"r") --continuing with codewould open
/emu/emu/testdir/fileintestdir
#6
Posted 27 June 2015 - 02:44 PM
Luca0208, on 27 June 2015 - 06:07 AM, said:
That won't work, because that simply assigns _fs as a pointer to the _G.fs table, which we later change the values of. Sure, you can make the _G.fs table an entirely new table, but then the version of fs io uses won't be overridden.
#7
Posted 27 June 2015 - 02:54 PM
I need something that would essentially run out-of-the-box
#8
Posted 27 June 2015 - 02:58 PM
local baseDir = "/emu/"
local oldFs = {}
for name, func in pairs(_G.fs) do
oldFS[name] = func
end
for name, func in pairs(oldFs) do
_G.fs[name] = function(path, ...)
path = shell.resolve(path)
if oldFS.isReadOnly(path) then
return oldFs[name](path, ...)
end
return oldFs[name](baseDir .. path, ...)
end
end
_G.fs.combine = oldFs.combine
Try this. It's a slightly modified version of Grim's code, it should work. Unless, of course, he got something wrong when he wrote it.
#9
Posted 27 June 2015 - 05:49 PM
Luca0208, on 27 June 2015 - 06:07 AM, said:
That code is needed, I think, because you must make a copy of the original fs api functions. Simply doing
local oldFS = _G.fsmeans that the oldFS table simply points to the _G.fs table. So, by overwriting _G.fs, you overwrite oldFS as well, leaving the original and critical fs api functions nowhere to be found.
Luca0208, on 27 June 2015 - 06:12 AM, said:
Oh btw Grim, your code would override fs.combine() so this code:
/emu/emu/testdir/fileintestdir
path1 = "testdir" path2 = "fileintestdir" path = fs.combine(path1,path2) fs.open(path,"r") --continuing with codewould open
/emu/emu/testdir/fileintestdir
You're absolutely right about this one. I don't use the entirety of the fs api much, so my knowledge of its contents is lacking.
Yami's code should work to correct that.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











