Posted 10 November 2013 - 04:56 AM
Most of my programs are small, and so I typically find myself scripting several previously used programs together for higher purposes… and the issue I'm having is that I need to run a subroutine with a variable number of arguments. shell.run will only accept strings as arguments, so I can't give it the list from the fs API directly (I tried), toString() doesn't seem to exist, and in an atmosphere of hopelessness, I tried stringing (heh) the table together into one gigantic string. This also failed.
Program 1: pt
Program 2: ptAll
The only difference for the first version of ptAll was that none of that string junk was in there, and i just tried to pass the table directly.
As far as the problem that this creates goes, there's a simple solution in [A] running pt multiple times and editing it so it would look less annoying to do so, or , rewriting a similar function into the body of ptAll. This is less about the current issue than it is about the countless future issues resulting from not knowing how to pass variable arguments to a subroutine.
Thanks.
Program 1: pt
local Args = { ... }
fs.makeDir("/Jfunctions")
for n=1,#Args do
if not fs.exists("/Jfunctions/" .. Args[n]) then
fs.copy("disk/" .. Args[n] , "/Jfunctions/" .. Args[n])
else
Args[n] = "EXISTS: " .. Args[n]
end
end
print("Functions ported:")
for n=1,#Args do
print(" " .. Args[n])
end
Program 2: ptAll
local passTable = fs.list("/disk")
local passString = ""
for n=1, #passTable do
passString = passString .. passTable[n]
end
shell.run("pt" , passString)
The only difference for the first version of ptAll was that none of that string junk was in there, and i just tried to pass the table directly.
As far as the problem that this creates goes, there's a simple solution in [A] running pt multiple times and editing it so it would look less annoying to do so, or , rewriting a similar function into the body of ptAll. This is less about the current issue than it is about the countless future issues resulting from not knowing how to pass variable arguments to a subroutine.
Thanks.