/usr/share/doc/monotone/html/Additional-Lua-Functions.html is in monotone-doc 1.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | <html lang="en">
<head>
<title>Additional Lua Functions - monotone documentation</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="monotone documentation">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Lua-Reference.html#Lua-Reference" title="Lua Reference">
<link rel="prev" href="Hooks.html#Hooks" title="Hooks">
<link rel="next" href="Implementation-Differences.html#Implementation-Differences" title="Implementation Differences">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="texinfo.css">
</head>
<body>
<div class="node">
<a name="Additional-Lua-Functions"></a>
<p>
Next: <a rel="next" accesskey="n" href="Implementation-Differences.html#Implementation-Differences">Implementation Differences</a>,
Previous: <a rel="previous" accesskey="p" href="Hooks.html#Hooks">Hooks</a>,
Up: <a rel="up" accesskey="u" href="Lua-Reference.html#Lua-Reference">Lua Reference</a>
<hr>
</div>
<h3 class="section">6.2 Additional Lua Functions</h3>
<p>This section documents the additional Lua functions made available to
hook and user command writers.
<dl>
<dt><code>alias_command(</code><var>original</var><code>, </code><var>alias</var><code>)</code><a name="index-alias_005fcommand_0028_0040var_007boriginal_007d_002c-_0040var_007balias_007d_0029-315"></a><dd>
This function adds a new alias for a monotone command. <var>original</var>
must be an existing montone command, <var>alias</var> is the new alias.
<br><dt><code>change_workspace(</code><var>directory</var><code>)</code><a name="index-change_005fworkspace_0028_0040var_007bdirectory_007d_0029-316"></a><dd>
Change to workspace <var>directory</var>, which may be absolute or
relative to the directory that was current when monotone was started.
<p>Throws an error if <var>directory</var> does not exist or is not a
workspace (does not contain <samp><span class="file">_MTN</span></samp>).
<p>After calling <code>change_workspace</code>, the next operation should read
the workspace options. <samp><span class="command"><a href="mtn_005fautomate.html#mtn_005fautomate">mtn_automate</a></span></samp> does this; other Lua
functions do not.
<br><dt><code>existonpath(</code><var>command</var><code>)</code><a name="index-existonpath_0028_0040var_007bcommand_007d_0029-317"></a><dd>
Return 0 if <var>command</var> (a string) exists on <code>$PATH</code> and is
executable, -1 otherwise.
<p>For example, <code>existonpath("xxdiff")</code> returns 0 if the
program xxdiff is available.
<p>On Windows, this function automatically appends “.exe” to the
program name if it is not present. In the previous example,
<code>existonpath</code> would search for “xxdiff.exe”.
<br><dt><code>get_confdir()</code><a name="index-get_005fconfdir_0028_0029-318"></a><dd>
Returns the path to the configuration directory; see <samp><span class="option"><a href="_002d_002dconfdir.html#g_t_002d_002dconfdir">--confdir</a></span></samp>.
<br><dt><code>get_ostype()</code><a name="index-get_005fostype_0028_0029-319"></a><dd>
Returns the operating system flavor as a string.
<br><dt><code>guess_binary_file_contents(</code><var>filespec</var><code>)</code><a name="index-guess_005fbinary_005ffile_005fcontents_0028_0040var_007bfilespec_007d_0029-320"></a><dd>
Returns true if the file contains one or more of the following
bytes:
<pre class="smallexample"> 0x00 thru 0x06
0x0E thru 0x1f
0x7f
</pre>
<!-- see file_io.cc guess_binary -->
<br><dt><code>guess_terminal_width()</code><a name="index-guess_005fterminal_005fwidth_0028_0029-321"></a><dd>
Returns the size of the terminal window as number or a sane default
(80) if the information cannot be retrieved.
<br><dt><code>include(</code><var>scriptfile</var><code>)</code><a name="index-include_0028_0040var_007bscriptfile_007d_0029-322"></a><dd>
This function tries to load and execute the Lua script contained in
<var>scriptfile</var>. It returns true for success and false if there is an
error.
<p>This is the same as Lua <code>loadfile</code>.
<br><dt><code>includedir(</code><var>scriptpath</var><code>)</code><a name="index-includedir_0028_0040var_007bscriptpath_007d_0029-323"></a><dd>
This function loads and executes in alphabetical order all the scripts
contained in the directory <var>scriptpath</var>.
<p>If one of the scripts has an error, the function doesn't process the
remaining scripts.
<p>There is no useful return value.
<br><dt><code>includedirpattern(</code><var>scriptpath</var><code>, </code><var>pattern</var><code>)</code><a name="index-includedirpattern_0028_0040var_007bscriptpath_007d_002c-_0040var_007bpattern_007d_0029-324"></a><dd>
This function loads and executes in alphabetical order all the scripts
contained into the directory <var>scriptpath</var> that match <var>pattern</var>
(a glob pattern).
<p>If one of the scripts has an error, the functions doesn't process the
remaining scripts.
<p>There is no useful return value.
<br><dt><code>is_executable(</code><var>file</var><code>)</code><a name="index-is_005fexecutable_0028_0040var_007bfile_007d_0029-325"></a><dd>
This function returns true if <var>file</var> is executable, false
otherwise. On Windows this function always returns false.
<br><dt><code>kill(</code><var>pid</var><code> [, </code><var>signal</var><code>])</code><a name="index-kill_0028_0040var_007bpid_007d-_005b_002c-_0040var_007bsignal_007d_005d_0029-326"></a><dd>
This function calls the kill() C library function on POSIX systems and
TerminateProcess on Win32 (in that case <var>pid</var> is the process
handle). If the optional <var>signal</var> parameter is missing, SIGTERM
will be used.
<p>Returns 0 on success, -1 on error.
<br><dt><code>make_executable(</code><var>file</var><code>)</code><a name="index-make_005fexecutable_0028_0040var_007bfile_007d_0029-327"></a><dd>
This function marks <var>file</var> as executable. On Windows this has no
effect.
<br><dt><code>globish.match(</code><var>glob</var><code>, </code><var>string</var><code>)</code><a name="index-globish_002ematch_0028_0040var_007bglob_007d_002c-_0040var_007bstring_007d_0029-328"></a><dd>
Returns <code>true</code> if <var>glob</var> matches <var>str</var>, return <code>false</code> otherwise.
<br><dt><code>mkstemp(</code><var>template</var><code>)</code><a name="index-mkstemp_0028_0040var_007btemplate_007d_0029-329"></a><dd>
Returns a unique name for a writeable temporary file. Note that it
does not create the file.
<p><var>template</var> should be a string that consists of contiguous, legal file
and path name characters followed by six 'X's.
<p><code>mkstemp</code> replaces the 'X's by an alpha-numeric sequence
that is unique in the directory given in <var>template</var>.
<p>Subsequent calls to <code>mkstemp</code> within the same process
each yield different file names.
<p>Unlike other implementations, monotone mkstemp allows <var>template</var>
to contain a complete path, not only a filename, allowing users to
create temporary files outside the current directory.
<p><strong>Important notice:</strong><br>
To create a temporary file, you should use the <code>temp_file</code>
function, unless you need to run monotone with the <samp><span class="option">--no-builtin-rcfiles</span></samp>
option. <code>temp_file()</code> builds on <code>mkstemp()</code> and creates a
file in the standard TMP/TEMP directories.
For the definition of <code>temp_file()</code>, see <a href="Default-hooks.html#Default-hooks">Default hooks</a>.
<p><a name="mtn_005fautomate"></a><br><dt><code>mtn_automate(</code><var>command</var> <var>args...</var><code> )</code><a name="index-mtn_005fautomate_0028_0040var_007bcommand_007d-_0040var_007bargs_002e_002e_002e_007d-_0029-330"></a><dd>
<code>mtn_automate</code> calls the monotone <samp><span class="command">automate</span></samp>
<var>command</var>, with <var>args...</var> (may include options). The result of
the call is a pair consisting of a boolean (<code>true</code> on success),
and a string containing the <code>stdout</code> output from
<samp><span class="command">automate </span><var>command</var></samp>.
<p>This function is not for use in ordinary Lua hooks, but rather for Lua
based commands as defined by the Lua function <a href="register_005fcommand.html#register_005fcommand">register_command</a>.
<p>Note that keyboard interaction is disabled, just as if <samp><span class="option">--non-interactive</span></samp>
is specified. Actions which require operations on password-encrypted private
keys will therefor fail unless the <code><a href="get_005fpassphrase.html#get_005fpassphrase">get_passphrase</a></code> hook is set up locally.
<p><a name="parse_005fbasic_005fio"></a><br><dt><code>parse_basic_io(</code><var>data</var><code>)</code><a name="index-parse_005fbasic_005fio_0028_0040var_007bdata_007d_0029-331"></a><dd>
Parse the string <var>data</var>, which should be in <code>basic_io</code>
format. Returns nil if it can't parse the string; otherwise
returns a table, with each entry in the table corresponding to one
<code>basic_io</code> line, consisting of a <code>name</code> element and a
<code>values</code> element.
<p>For example, given this as input:
<pre class="smallexample"> thingy "foo" "bar"
thingy "baz"
spork
frob "oops"
</pre>
<p>The output table will be:
<pre class="smallexample"> {
1 = { name = "thingy", values = { 1 = "foo", 2 = "bar" } },
2 = { name = "thingy", values = { 1 = "baz" } },
3 = { name = "spork", values = { } },
4 = { name = "frob", values = { 1 = "oops" } }
}
</pre>
<br><dt><code>regex.search(</code><var>regexp</var><code>, </code><var>string</var><code>)</code><a name="index-regex_002esearch_0028_0040var_007bregexp_007d_002c-_0040var_007bstring_007d_0029-332"></a><dd>
Returns <code>true</code> if a match for <var>regexp</var> is found in <var>str</var>,
<code>false</code> otherwise. See <a href="Regexps.html#Regexps">Regexps</a>, for the syntax of
<var>regexp</var>.
<p><a name="register_005fcommand"></a><br><dt><code>register_command(</code><var>name</var><code>, </code><var>params</var><code>, </code><var>abstract</var><code>, </code><var>description</var><code>, </code><var>function</var><code>)</code><a name="index-register_005fcommand_0028_0040var_007bname_007d_002c-_0040var_007bparams_007d_002c-_0040var_007babstract_007d_002c-_0040var_007bdescription_007d_002c-_0040var_007bfunction_007d_0029-333"></a><dd>
Add a command named <var>name</var> to the user command group in monotone.
When the user issues the registered command, monotone will call the
lua <var>function</var> name supplied. That function would then normally
use <code><a href="mtn_005fautomate.html#mtn_005fautomate">mtn_automate</a></code> calls to service the
request. <var>params</var> is a string with the list of parameters for the
command, <var>abstract</var> gives a brief description, <var>description</var> a
longer description. <var>params</var>, <var>abstract</var>, <var>description</var>
are output by <samp><span class="command">mtn help</span></samp>.
<br><dt><code>server_request_sync(</code><var>what</var><code>, </code><var>address</var><code>, </code><var>include</var><code>, </code><var>exclude</var><code>)</code><a name="index-server_005frequest_005fsync_0028_0040var_007bwhat_007d_002c-_0040var_007baddress_007d_002c-_0040var_007binclude_007d_002c-_0040var_007bexclude_007d_0029-334"></a><dd>
Initiate a netsync connection to the server at <var>address</var>, with the
given <var>include</var> and <var>exclude</var> branch patterns. <var>what</var> is
one of <samp><span class="option">sync</span></samp>, <samp><span class="option">push</span></samp>, or <samp><span class="option">pull</span></samp>, indicating
netsync operation.
<p>When called by a monotone instance which is not running the <samp><span class="option">serve</span></samp>
command, this function has no effect.
<br><dt><code>server_set_listening(</code><var>boolean</var><code>)</code><a name="index-server_005fset_005flistening_0028_0040var_007bboolean_007d_0029-335"></a><dd>
If the argument is <var>false</var>, make the server not listen for incoming
connections, and exit when all existing connections have closed.
<p>If the argument is <var>true</var>, cancel an earlier call with <var>false</var> given.
<br><dt><code>sleep(</code><var>seconds</var><code>)</code><a name="index-sleep_0028_0040var_007bseconds_007d_0029-336"></a><dd>
Makes the calling process sleep for the specified number of seconds.
<br><dt><code>spawn(</code><var>executable</var><code> [, </code><var>args ...</var><code>])</code><a name="index-spawn_0028_0040var_007bexecutable_007d-_005b_002c-_0040var_007bargs-_002e_002e_002e_007d_005d_0029-337"></a><dd>
Starts the named executable with the given arguments. Returns the
process PID on POSIX systems, the process handle on Win32 or -1 if
there was an error.
<p>Calls fork/execvp on POSIX, CreateProcess on Win32.
<p><strong>Important notice:</strong><br>
To spawn a process and wait for its completion, use the <code>execute()</code>
function, unless you need to run monotone with the <samp><span class="option">--no-builtin-rcfiles</span></samp>
option. <code>execute()</code> builds on <code>spawn()</code> and <code>wait()</code>
in a standardized way.
<br><dt><code>spawn_pipe(</code><var>executable</var><code> [, </code><var>args ...</var><code>])</code><a name="index-spawn_005fpipe_0028_0040var_007bexecutable_007d-_005b_002c-_0040var_007bargs-_002e_002e_002e_007d_005d_0029-338"></a><dd>
Like spawn(), but returns three values, where the first two are the
subprocess' standard input and standard output, and the last is the
process PID on POSIX systems, the process handle on Win32 or -1 if
there was an error.
<br><dt><code>spawn_redirected(</code><var>infile</var><code>, </code><var>outfile</var><code>, </code><var>errfile</var><code>, </code><var>executable</var><code> [, </code><var>args ...</var><code>])</code><a name="index-spawn_005fredirected_0028_0040var_007binfile_007d_002c-_0040var_007boutfile_007d_002c-_0040var_007berrfile_007d_002c-_0040var_007bexecutable_007d-_005b_002c-_0040var_007bargs-_002e_002e_002e_007d_005d_0029-339"></a><dd>
Like spawn(), but with standard input, standard output and standard
error redirected to the given files.
<br><dt><code>wait(</code><var>pid</var><code>)</code><a name="index-wait_0028_0040var_007bpid_007d_0029-340"></a><dd>
Wait until the process with given PID (process handle on Win32) exits.
Returns two values: a result value and the exit code of the waited-for
process.
<p>The exit code is meaningful only if the result value is 0.
</dl>
</body></html>
|