# # # patch "monotone.texi" # from [11d4354e74d72c3e6184e7c6946bf5e163d40922] # to [331fedc2723427644981ae1a926e942a32b73453] # # patch "std_hooks.lua" # from [db92c325500faefec65894da62cda13cbdc84856] # to [27557425818f1ccb7202d587cc70769931f716cd] # ============================================================ --- monotone.texi 11d4354e74d72c3e6184e7c6946bf5e163d40922 +++ monotone.texi 331fedc2723427644981ae1a926e942a32b73453 @@ -9156,6 +9156,79 @@ @section Automation @end table address@hidden mtn automate lua @var{function_name} address@hidden + address@hidden @strong address@hidden Arguments: + +A valid Lua function name and zero or more function arguments. Note that string +arguments need to be wrapped in another pair of quotes, i.e. @code{"foo"} or address@hidden'foo'} will not work, but @code{"'foo'"} or @code{'"foo"'} will. + +Complex types are also supported, anything which can be evaluated as valid +Lua expression can be given as input, including nested tables and functions, +like f.e. @address@hidden,true,@{['func'] = function(...) return ... end @address@hidden + address@hidden Added in: + +8.2 + address@hidden Purpose: + +Call Lua functions, like monotone hooks, in the monotone context, f.e. to +retrieve user defaults like keys, passwords, ignorable files and more. + address@hidden Output format: + +A string dump of the return value of the function, in Lua code. The Lua types address@hidden, @code{thread}, @code{userdata} and @code{lightuserdata} are not +serialized, but set to @code{nil} in the dump. + +Please note that @code{nil} values in tables are not printed since Lua does not +distinguish between unset and not existing entries in a table like other +programming languages do. + address@hidden Sample output: + +A single string return value: + address@hidden +[1] = "Output"; address@hidden verbatim + +Two numeric return values: + address@hidden +[1] = 3; +[2] = 4.4; address@hidden verbatim + +A nested table: + address@hidden +[1] = { + ["bar"] = { + [1] = 1; + [2] = 2; + [3] = 3; + }; +}; address@hidden verbatim + +A callback function: + address@hidden +[1] = nil --[[ function ]]--; address@hidden verbatim + address@hidden Error conditions: + +This command prints an error message and exists with status 1 if the function +does not exist, one or more function arguments could not be evaluated or the +function could not be called for another reason. + address@hidden table + @end ftable @page @@ -10186,6 +10259,21 @@ @subsection Validation Hooks @end ftable address@hidden Meta Hooks + +Monotone allows the execution of arbitrary Lua hooks and functions through a +special generalized "meta hook". See @command{automate lua} for more information. + address@hidden @code address@hidden hook_wrapper (@var{func_name}, @var{...}) + +This hook is explicitely called on every execution of @command{automate lua}. +It takes a function name and zero or more string function arguments which are +internally evaluated into Lua code. It returns a dump of the return value of +the called function in Lua code on success. + address@hidden ftable + @page @node Additional Lua Functions, , Hooks, Hook Reference @section Additional Lua Functions ============================================================ --- std_hooks.lua db92c325500faefec65894da62cda13cbdc84856 +++ std_hooks.lua 27557425818f1ccb7202d587cc70769931f716cd @@ -1160,13 +1160,15 @@ dump._string = function(s) return dump = {} dump.depth = 0 dump._string = function(s) return string.format("%q", s) end -dump._number = function(n) return tonumber(n) end +dump._number = function(n) return tostring(n) end dump._boolean = function(b) if (b) then return "true" end return "false" end -dump._userdata = function(u) return "" end -dump._function = function(f) return "" end +dump._userdata = function(u) return "nil --[[ userdata ]]--" end +-- if we really need to return / serialize functions we could do it +-- like address@hidden did here: http://lua-users.org/wiki/TablePersistence +dump._function = function(f) return "nil --[[ function ]]--" end dump._nil = function(n) return "nil" end -dump._thread = function(t) return "" end -dump._lightuserdata = function(l) return "" end +dump._thread = function(t) return "nil --[[ thread ]]--" end +dump._lightuserdata = function(l) return "nil --[[ lightuserdata ]]--" end dump._table = function(t) local buf = ''