Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 734f168

Browse files
committed
[[LCB stdlib]] Add syntax for command name/arguments.
Add new syntax to `com.livecode.system`: * `the command name` returns the "name" of the current program (similar to C's argv[0]). * `the command arguments` returns the command-line arguments to the current program (similar to C's argv[n>0]).
1 parent 4ea528c commit 734f168

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

libscript/src/module-system.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
1616
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1717

1818
#include <foundation.h>
19+
#include <foundation-system.h>
1920

2021
/* ================================================================
2122
* System identification
@@ -42,3 +43,19 @@ MCSystemExecGetOperatingSystem (MCStringRef & r_string)
4243

4344
/* UNCHECKED */ MCStringCreateWithCString (t_os, r_string);
4445
}
46+
47+
/* ================================================================
48+
* Command-line information
49+
* ================================================================ */
50+
51+
extern "C" MC_DLLEXPORT void
52+
MCSystemExecGetCommandName (MCStringRef & r_string)
53+
{
54+
/* UNCHECKED */ MCSCommandLineGetName (r_string);
55+
}
56+
57+
extern "C" MC_DLLEXPORT void
58+
MCSystemExecGetCommandArguments (MCProperListRef & r_list)
59+
{
60+
/* UNCHECKED */ MCSCommandLineGetArguments (r_list);
61+
}

libscript/src/system.mlc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,69 @@ begin
9292
MCSystemExecQuitWithStatus(Status)
9393
end syntax
9494

95+
----------------------------------------------------------------
96+
-- Command-line information
97+
----------------------------------------------------------------
98+
99+
public foreign handler MCSystemExecGetCommandName (out CommandName as string) as undefined binds to "<builtin>"
100+
public foreign handler MCSystemExecGetCommandArguments (out CommandArguments as list) as undefined binds to "<builtin>"
101+
102+
/*
103+
Summary: The command name
104+
105+
Example:
106+
-- Program that only succeeds if it's run as the "true"
107+
-- command.
108+
variable tCommand as string
109+
put the command name into tCommand
110+
if tCommand ends with "true" then
111+
quit with status 0
112+
else
113+
quit with status 1
114+
end if
115+
116+
Description:
117+
Evaluates to the name that was used to execute the program, possibly
118+
including path information.
119+
*/
120+
syntax CommandName is expression
121+
"the" "command" "name"
122+
begin
123+
MCSystemExecGetCommandName(output)
124+
end syntax
125+
126+
/*
127+
Summary: The command arguments
128+
129+
Example:
130+
-- Program that only succeeds if it's run as the "true"
131+
-- command.
132+
variable tCommand as string
133+
put the command name into tCommand
134+
if tCommand ends with "true" then
135+
quit with status 0
136+
else
137+
quit with status 1
138+
end if
139+
140+
Description:
141+
142+
Evaluates to a list of command-line arguments passed to the program.
143+
Some arguments may not be passed in if they are "used up" by the
144+
LiveCode run-time environment (for example, the LiveCode IDE will
145+
detect and "use" the `-mmap` argument).
146+
147+
> **Note:** No filename conversion is performed on command line
148+
> arguments, so some processing may be required before using a command
149+
> line argument with any of the file handling syntax provided by the
150+
> `com.livecode.file` module.
151+
*/
152+
syntax CommandArguments is expression
153+
"the" "command" "arguments"
154+
begin
155+
MCSystemExecGetCommandArguments(output)
156+
end syntax
157+
95158
--
96159

97160
end module

0 commit comments

Comments
 (0)