Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
api:shell [2016/02/29 18:45]
payonel removed reference to shell.running as it no longer exists in source
api:shell [2016/07/04 17:40]
payonel [Shell API]
Line 27: Line 27:
   Returns values similar to `pcall` and `coroutine.resume`:​ the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.   Returns values similar to `pcall` and `coroutine.resume`:​ the first returned value is a boolean indicating success or error. In case of errors, the second returned value is a detailed error message. Otherwise the remaining returned values are the values that were returned by the specified program when it terminated.
 - `shell.parse(...):​ table, table`  ​ - `shell.parse(...):​ table, table`  ​
-  Utility methods intended for programs to parse their arguments. Will return two tables, the first one containing any "​normal"​ parameters, the second containing "​options"​. Options are indicated by a leading `-`, and all options must only be a single character, since multiple characters following a single `-` will be interpreted as multiple options. ​For exampleif a program is called like this: +  Utility methods intended for programs to parse their arguments. Will return two tables, the first one containing any "​normal"​ parameters, the second containing "​options"​. Options are indicated by a leading `-`, and all options must only be a single character, since multiple characters following a single `-` will be interpreted as multiple options. ​Options specified with 2 dashes are not split and can have multiple letters. Also2-dash options can be given values by using an equal sign. The following examples all assume the script `program` parses the options using `local args, ops = shell.parse(...)`. 
-  `program -abC -d arg1 arg2`   + 
-  ​And `program` ​does `local args, options ​shell.parse(...)`, then `args` is the table `{"​arg1",​ "​arg2"​}`, and `options` is the table `{a=true,​b=true,​C=true,​d=true}`.+  `program` 
 + 
 +  # `args` ​is `{}` 
 + 
 +  # `ops` is `{}`. 
 + 
 +  `program -abC -d arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `op` is `{a=true,​b=true,​C=true,​d=true}`. 
 + 
 +  `program ​-abC --dog arg1 arg2` 
 + 
 +  # `args` is `{"​arg1"​"​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​dog=true}`. 
 + 
 +  `program -abC --dog=foo arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​dog="​foo"​}`. 
 + 
 +  On this next example, notice the single dash before `dog`, this causes all of the token to be parsed as single chars. 
 + 
 +  `program -abC -dog=foo arg1 arg2` 
 + 
 +  # `args` is `{"​arg1",​ "​arg2"​}` 
 + 
 +  # `ops` is `{a=true,​b=true,​C=true,​d=true,​g=true,​["​="​]=true,​f=true.o=true}`.