This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
YUGATUG's profile picture

program syntax?

Started by YUGATUG, 28 March 2015 - 03:47 PM
YUGATUG #1
Posted 28 March 2015 - 04:47 PM
I want to create a program that will read the text after the program name, so something like this: 'Enderchest List' that will list all the ender chests i have from Ender Storage. How do i make my program find key words after the program name?
HPWebcamAble #2
Posted 28 March 2015 - 05:45 PM
Do you mean the program will read text from a file?

To do that, you'll need the fs API


Oh, you meant capturing arguments when running the program, that explains a lot

Lyqyd covered it pretty well below
Edited on 28 March 2015 - 08:23 PM
Lyqyd #3
Posted 28 March 2015 - 06:14 PM
I think he means that he wants to use command-line arguments to change the behavior of his program. To do so, you need to capture the arguments the shell passes in to your program:


local args = {...}

Notice that we captured the arguments into a table. The shell will split up the string you used to run the program, with space characters as the separator. So, in your example, "enderchest list", the shell would send a table containing "list" at index 1. So to compare against the first argument, you would do something like this:


local args = {...}

if args[1] == "list" then
  listEnderChests()
end
YUGATUG #4
Posted 29 March 2015 - 12:12 AM
Thanks! Great help!