NAME

suplib - Lua support library of miscellaneous functions


SYNOPSIS

  -----------------------
  -- load table functions
  dofile( 'suplib/tables.lua' )
  -- copy a table 
  copy = table_copy( table, deep_copy )
  -----------------------
  -- load path functions
  dofile( 'suplib/paths.lua' )
  -- split paths
  dirname, basename = splitpath( path )
  -----------------------
  -- load string functions
  dofile( 'suplib/strings.lua' )


FUNCTIONS

Table Manipulation

These functions are available in the tables.lua file.

table_copy
  copy = table_copy( table, [deep_copy] )

Create a copy of the passed table. If the optional parameter deep_copy is false (the default) a shallow copy will be made (i.e., elements which are tables will be copied by reference).

If deep is true, elements which are tables are copied by value a deep copy will be made. However, table_copy does not check for recursive tables, so will go into an infinite loop if a table somehow references itself.

Path Functions

These functions are available in the paths.lua file.

splitpath
  dirname, basename = splitpath( path )

This returns the leading directories and the last element in a path. The leading directory will be nil if there is no directory and an empty string if the path is the root path. E.g.

   a : dirname = nil ; basename = "a";
  /a : dirname = ""  ; basename = "a";

String Manipulation

These functions are available in the strings.lua file.

str_interp
  interpolated_string = str_interp( string, vars )

Interpolate variables into strings. Variables are first searched for in the passed (optional) table, then in the environmental variables. Variables may be of the form $VAR or ${VAR}, where VAR is a string which must begin with either a letter or an underscore _; the remaining characters may be letters, numbers, or underscores.

This implementation isn't quite correct as it makes two passes over the string to handle the different syntaxes.


COPYRIGHT AND LICENSE

This software is copyright the Smithsonian Astrophysical Observatory and is released under the GNU General Public License. You may find a copy at http://www.fsf.org/copyleft/gpl.html.


AUTHOR

Diab Jerius <djerius@cfa.harvard.edu>