-
Book Overview & Buying
-
Table Of Contents
Mastering FreeSWITCH
By :
We've used a lot of self-written functions. It's time to have a look at them. Let's open the top half of the utils.lua file, in the preceding screenshot.
The first three functions serve mainly to build the fourth function, stamp(), that we use throughout our scripts to do structured logging.
shell() is an example of a typical Lua interaction with an operating system. It executes a command, and returns the output as a string. We use it in stamp() to obtain the result of the command date.
trim() uses Lua native string manipulation, and is equivalent to the chomp() command in Perl, and many similar others in different languages: it deletes the trailing newline in a string, if it exists, and returns the string without the newline.
whichline() comes from the debug package. It returns the current line number in the script, for example, like __line__ in C.
stamp() is our logging workhorse; it takes the string we want to log (our log message), a string (returned by whichline...