188 posts
Location
Germany
Posted 18 August 2016 - 04:50 PM
I get a Input for shell.run (e.g edit test). How can I move it into a input for os .run? I have changed edit to /rom/programs/edit with shell.resolve. But whats with the Args? In os.run I must write({},"/rom/programs/edit","test"). With one arg thats no Problem. But I dont know, how many args are the Input has? The Input can have two or more args. e.g If I get shell.run(pro first second) I must write os.run({},pro,first,second). How can I move the Args from shell.run to os.run?
3057 posts
Location
United States of America
Posted 18 August 2016 - 04:58 PM
Presumably you have a table of arguments something like this:
local tArgs = {...}
-- tArgs[ 1 ] is edit
-- tArgs[ 2 ] is test
-- tArgs[ 3 ] and so on you want to deal with
os.run( {}, shell.resolve( tArgs[ 1 ] ), (table.unpack or unpack)( tArgs, 2 ) ) -- this will pass all the arguments to os.run
Unpack (or table.unpack, depending on the version) is explained
here.
Varargs, which is what you're working with, are explained more
in the next chapter.