This section documents the additional Lua functions made available to hook and user command writers.
alias_command(
original,
alias)
change_workspace(
directory)
Throws an error if directory does not exist or is not a workspace (does not contain _MTN).
After calling change_workspace
, the next operation should read
the workspace options. mtn_automate does this; other Lua
functions do not.
existonpath(
command)
$PATH
and is
executable, -1 otherwise.
For example, existonpath("xxdiff")
returns 0 if the
program xxdiff is available.
On Windows, this function automatically appends “.exe” to the
program name if it is not present. In the previous example,
existonpath
would search for “xxdiff.exe”.
get_confdir()
get_ostype()
guess_binary_file_contents(
filespec)
0x00 thru 0x06 0x0E thru 0x1f 0x7f
guess_terminal_width()
include(
scriptfile)
This is the same as Lua loadfile
.
includedir(
scriptpath)
If one of the scripts has an error, the function doesn't process the remaining scripts.
There is no useful return value.
includedirpattern(
scriptpath,
pattern)
If one of the scripts has an error, the functions doesn't process the remaining scripts.
There is no useful return value.
is_executable(
file)
kill(
pid [,
signal])
Returns 0 on success, -1 on error.
make_executable(
file)
globish.match(
glob,
string)
true
if glob matches str, return false
otherwise.
mkstemp(
template)
template should be a string that consists of contiguous, legal file and path name characters followed by six 'X's.
mkstemp
replaces the 'X's by an alpha-numeric sequence
that is unique in the directory given in template.
Subsequent calls to mkstemp
within the same process
each yield different file names.
Unlike other implementations, monotone mkstemp allows template to contain a complete path, not only a filename, allowing users to create temporary files outside the current directory.
Important notice:
To create a temporary file, you should use the temp_file
function, unless you need to run monotone with the --no-builtin-rcfiles
option. temp_file()
builds on mkstemp()
and creates a
file in the standard TMP/TEMP directories.
For the definition of temp_file()
, see Default hooks.
mtn_automate(
command args... )
mtn_automate
calls the monotone automate
command, with args... (may include options). The result of
the call is a pair consisting of a boolean (true
on success),
and a string containing the stdout
output from
automate command.
This function is not for use in ordinary Lua hooks, but rather for Lua based commands as defined by the Lua function register_command.
Note that keyboard interaction is disabled, just as if --non-interactive
is specified. Actions which require operations on password-encrypted private
keys will therefor fail unless the get_passphrase
hook is set up locally.
parse_basic_io(
data)
basic_io
format. Returns nil if it can't parse the string; otherwise
returns a table, with each entry in the table corresponding to one
basic_io
line, consisting of a name
element and a
values
element.
For example, given this as input:
thingy "foo" "bar" thingy "baz" spork frob "oops"
The output table will be:
{ 1 = { name = "thingy", values = { 1 = "foo", 2 = "bar" } }, 2 = { name = "thingy", values = { 1 = "baz" } }, 3 = { name = "spork", values = { } }, 4 = { name = "frob", values = { 1 = "oops" } } }
regex.search(
regexp,
string)
true
if a match for regexp is found in str,
false
otherwise. See Regexps, for the syntax of
regexp.
register_command(
name,
params,
abstract,
description,
function)
mtn_automate
calls to service the
request. params is a string with the list of parameters for the
command, abstract gives a brief description, description a
longer description. params, abstract, description
are output by mtn help.
server_request_sync(
what,
address,
include,
exclude)
When called by a monotone instance which is not running the serve
command, this function has no effect.
server_set_listening(
boolean)
If the argument is true, cancel an earlier call with false given.
sleep(
seconds)
spawn(
executable [,
args ...])
Calls fork/execvp on POSIX, CreateProcess on Win32.
Important notice:
To spawn a process and wait for its completion, use the execute()
function, unless you need to run monotone with the --no-builtin-rcfiles
option. execute()
builds on spawn()
and wait()
in a standardized way.
spawn_pipe(
executable [,
args ...])
spawn_redirected(
infile,
outfile,
errfile,
executable [,
args ...])
wait(
pid)
The exit code is meaningful only if the result value is 0.