function main()
local es = fs
allowed = {"rom", "disk[1-6]"}
function cover(file)
file = es.combine(file, "")
file = file:gsub("%.%.", "")
permitted = false
for _, v in pairs(allowed) do
if (string.find(file, v)) then
permitted = true
end
end
if (not (permitted)) then
file = "q/"..file
end
return file
end
function uncover(file)
file = es.combine(file, "")
file = string.gsub(file, "^q/", "")
return file
end
if (not es.exists("q")) then
es.makeDir("q")
end
files = es.list("/")
for k, v in pairs(files) do
if (not (v == "start") and not (v == "q")) then
if (not (es.exists(cover(v)))) then
es.copy(v, cover(v))
end
if (not (es.isReadOnly(v)) and not (v == "q")) then
es.delete(v)
end
end
end
local vfs = {}
function vfs.list(path)
r = es.list(cover(path))
if (path == "") then
r[#r + 1] = "rom"
end
for k, v in pairs(r) do
r[k] = uncover(v)
end
return r
end
function vfs.exists(path)
return es.exists(cover(path))
end
function vfs.isDir(path)
return es.isDir(cover(path))
end
function vfs.isReadOnly(path)
return es.isReadOnly(cover(path))
end
function vfs.getDrive(path)
return es.getDrive(cover(path))
end
function vfs.getSize(path)
return es.getSize(cover(path))
end
function vfs.getFreeSpace(path)
return es.getFreeSpace(cover(path))
end
function vfs.makeDir(path)
es.makeDir(cover(path))
end
function vfs.move(fromPath, toPath)
es.move(cover(fromPath), cover(toPath))
end
function vfs.copy(fromPath, toPath)
es.copy(cover(fromPath), cover(toPath))
end
function vfs.delete(path)
es.delete(cover(path))
end
function vfs.open(path, mode)
return es.open(cover(path), mode)
end
function vfs.find(wildcard)
value = es.find(cover(wildcard))
for k, v in pairs(value) do
value[k] = uncover(v)
end
return value
end
vfs.complete = es.complete
vfs.combine = es.combine
vfs.getName = es.getName
fs = vfs
end
main()
#1
Posted 06 November 2015 - 01:03 AM
#2
Posted 06 November 2015 - 02:56 PM
Alternatively, you could make a alias through shell for each of the files you move.
Edited by valithor, 06 November 2015 - 02:57 PM.
#3
Posted 06 November 2015 - 09:18 PM
#4
Posted 06 November 2015 - 09:38 PM
Ok, I tested it, and it only seems to freeze shell, and nothing else. If I use lua to manually overwrite it, then exit lua, the shell freezes. It also happens if I make shell.resolve() return the value of blah.resolve() where blah = shell.
#5
Posted 07 November 2015 - 01:07 AM
blah = shell shell.resolve = blah.resolvebecause that doesn't copy the table, it just adds a "pointer" for that table.
#6
Posted 07 November 2015 - 02:47 AM
function shell.resolve(name) return blah.resolve(name) end
#7
Posted 07 November 2015 - 02:51 AM
ViperLordX, on 07 November 2015 - 02:47 AM, said:
function shell.resolve(name) return blah.resolve(name) end
What he meant by that was, are you doing this to copy the table:
blah = shell
The second part really wasn't needed to ask what he was asking.
Edited by valithor, 07 November 2015 - 02:52 AM.
#8
Posted 07 November 2015 - 02:52 AM
#9
Posted 07 November 2015 - 02:55 AM
ViperLordX, on 07 November 2015 - 02:52 AM, said:
The reason it is crashing then is due to the way lua tables work. When you do "blah = shell" you are not making a new table with the same contents as shell, you are creating a variable that points to the same table as the shell variable points to. So, in short there is 1 table, and the function you overwrote shell.resolveProgram with, is just calling itself over and over (CC limits recursion to 255 times, which eventually causes a crash).
#10
Posted 07 November 2015 - 02:55 AM
#11
Posted 07 November 2015 - 02:57 AM
ViperLordX, on 07 November 2015 - 02:55 AM, said:
Right now I am starting minecraft in order to play around with it and help you find a answer to your original problem, but in order to overcome the problem you are having right now is fairly easy.
Instead of copying the entire table, just copy the single function you are going to overwrite:
local oldResolveProgram = shell.resolveProgram shell.resolveProgram = function(...) return oldResolveProgram(...) end
Edited by valithor, 07 November 2015 - 07:52 PM.
#12
Posted 07 November 2015 - 03:04 AM
local oldShell = {}
for k, v in pairs( shell )
oldShell[ k ] = v
end
shell.resolveProgram = function( ... )
return oldShell.resolveProgram( ... )
end
Edit: Clarification on this issue:
Variables pointing to tables really contain a pointer to the table.
This can be demonstrated with the following:
local t = {foo="bar"}
print( t.foo )
local _t = t
_t.foo = "foo"
print( t.foo )
As you can see, even though we assigned _t.foo a variable instead of t.foo, t.foo was also changed. This is because, in reality, both of these variables are simply labels - and they label the same table.
Edited by KingofGamesYami, 07 November 2015 - 03:08 AM.
#13
Posted 07 November 2015 - 03:08 AM
local oldResolveProgram = shell.resolveProgram
shell.resolveProgram = function(path)
if oldResolveProgram(path) ~= nil then --# checking if it is nil without the "q/" added on. Essentially if the path is for rom, or a disk
return oldResolveProgram(path) --# returning it sense it isn't nil
else
return oldResolveProgram("q/"..path) --# returning the "q/" path
end
end
Edited by valithor, 07 November 2015 - 05:56 PM.
#14
Posted 07 November 2015 - 05:01 AM
#15
Posted 07 November 2015 - 06:18 AM
local function contains(table, value)
for k, v in pairs(table) do
if (v == value) then
return true;
end
end
return false;
end
function main()
local es = {}
for k, v in pairs(fs) do
es[k] = v
end
allowed = {"rom", "disk[1-6]"}
function cover(file)
file = es.combine(file, "")
file = string.gsub(file, "%.%.", "")
permitted = false
for _, v in pairs(allowed) do
if (string.find(file, v)) then
permitted = true
end
end
if (not (permitted)) then
file = "q/"..file
end
return file
end
function uncover(file)
file = es.combine(file, "")
file = string.gsub(file, "^q/", "")
return file
end
if (not es.exists("q")) then
es.makeDir("q")
end
files = es.list("/")
for k, v in pairs(files) do
if (not (v == "start") and not (v == "q")) then
if (not (es.exists(cover(v)))) then
es.copy(v, cover(v))
end
if (not (es.isReadOnly(v)) and not (v == "q")) then
es.delete(v)
end
end
end
local vfs = {}
function vfs.list(path)
r = es.list(cover(path))
if (path == "") then
r[#r + 1] = "rom"
end
for k, v in pairs(r) do
r[k] = uncover(v)
end
return r
end
function vfs.exists(path)
return es.exists(cover(path))
end
function vfs.isDir(path)
return es.isDir(cover(path))
end
function vfs.isReadOnly(path)
return es.isReadOnly(cover(path))
end
function vfs.getDrive(path)
return es.getDrive(cover(path))
end
function vfs.getSize(path)
return es.getSize(cover(path))
end
function vfs.getFreeSpace(path)
return es.getFreeSpace(cover(path))
end
function vfs.makeDir(path)
es.makeDir(cover(path))
end
function vfs.move(fromPath, toPath)
es.move(cover(fromPath), cover(toPath))
end
function vfs.copy(fromPath, toPath)
es.copy(cover(fromPath), cover(toPath))
end
function vfs.delete(path)
es.delete(cover(path))
end
function vfs.open(path, mode)
return es.open(cover(path), mode)
end
function vfs.find(wildcard)
value = es.find(cover(wildcard))
for k, v in pairs(value) do
value[k] = uncover(v)
end
return value
end
vfs.complete = es.complete
vfs.combine = es.combine
vfs.getName = es.getName
fs = vfs
local hell = {}
function hell.resolve(name)
return hell.resolve(cover(name))
end
function hell.resolveProgram(name)
return hell.resolveProgram(cover(name))
end
setmetatable(hell, {__index = shell})
shell = hell
end
main()
#16
Posted 07 November 2015 - 05:58 PM
Also, when you do eventually switch over to the one I gave you, you will realize you are getting a error on line 65 of edit. In which case you will need to overwrite io.open in the same way you overwrote fs.open.
local oldResolveProgram = shell.resolveProgram
shell.resolveProgram = function(path)
if oldResolveProgram(path) ~= nil then --# checking if it is nil without the "q/" added on. Essentially if the path is for rom, or a disk
return oldResolveProgram(path) --# returning it sense it isn't nil
else
return oldResolveProgram("q/"..path) --# returning the "q/" path
end
end
local oldIoOpen = io.open
io.open = function(path,mode)
return oldIoOpen(cover(path),mode)
end
#18
Posted 07 November 2015 - 06:12 PM
#19
Posted 07 November 2015 - 06:22 PM
#20
Posted 07 November 2015 - 06:45 PM
KingofGamesYami, on 07 November 2015 - 06:10 PM, said:
Lyqyd, on 07 November 2015 - 06:12 PM, said:
Apparently overwriting the fs api did not change the io api. It might be how he overwrote it, but when I was testing the program in a emulator the fs.exists check on line 63 of the edit program was returning true, but line 65 was erroring with attempt to call nil, aka io.opening the file that fs.exist said exist was returning nil. I came to the conclusion that io.open was still using the unmodified version of fs.open, which made no sense to me, but doing the overwrite i posted fixed it.
Put shortly. I thought the exact same as both of you, but it doesn't work without making that modification from my tests, and yes I do understand how the io api works internally.
Edited by valithor, 07 November 2015 - 06:51 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











