Jump to content




Craftception


  • You cannot reply to this topic
8 replies to this topic

#1 Creeper9207

  • Members
  • 211 posts

Posted 27 June 2015 - 12:08 AM

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?

#2 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

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?
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 Creeper9207

  • Members
  • 211 posts

Posted 27 June 2015 - 04:30 AM

How would I modify the fs api?

#4 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 27 June 2015 - 06:07 AM

That is not needed:

View PostGrim Reaper, on 27 June 2015 - 12:18 AM, said:

for name, func in pairs(_G.fs) do
	oldFS[name] = func
end
Just use
local oldFS = _G.fs

View PostCreeper9207, on 27 June 2015 - 04:30 AM, said:

How would I modify the fs api?
The fs api table is not read only
you can use
fs.open = function()
  --somestrangecode xD
end

Edited by Luca0208, 27 June 2015 - 06:07 AM.


#5 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 27 June 2015 - 06:12 AM

Oh btw Grim, your code would override fs.combine() so this code:
path1 = "testdir"
path2 = "fileintestdir"
path = fs.combine(path1,path2)
fs.open(path,"r")
--continuing with code
would open
/emu/emu/testdir/fileintestdir

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 27 June 2015 - 02:44 PM

View PostLuca0208, on 27 June 2015 - 06:07 AM, said:

That is not needed:

View PostGrim Reaper, on 27 June 2015 - 12:18 AM, said:

for name, func in pairs(_G.fs) do
	oldFS[name] = func
end
Just use
local oldFS = _G.fs

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 Creeper9207

  • Members
  • 211 posts

Posted 27 June 2015 - 02:54 PM

I need something that would essentially run out-of-the-box

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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 Grim Reaper

  • Members
  • 503 posts
  • LocationSeattle, WA

Posted 27 June 2015 - 05:49 PM

View PostLuca0208, on 27 June 2015 - 06:07 AM, said:

That is not needed:

View PostGrim Reaper, on 27 June 2015 - 12:18 AM, said:

for name, func in pairs(_G.fs) do
	oldFS[name] = func
end
Just use
local oldFS = _G.fs

That code is needed, I think, because you must make a copy of the original fs api functions. Simply doing
local oldFS = _G.fs
means 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.

View PostLuca0208, on 27 June 2015 - 06:12 AM, said:

Oh btw Grim, your code would override fs.combine() so this code:
path1 = "testdir"
path2 = "fileintestdir"
path = fs.combine(path1,path2)
fs.open(path,"r")
--continuing with code
would 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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users