Module lousy.util
lousy.util library
Utility functions for lousy.
Functions
lousy.util.escape (text)
Escape a string from XML characters.
Parameters
-
textType: stringThe text to escape.
Return Values
-
stringA string with all XML characters escaped.
lousy.util.unescape (text)
Unescape a string from XML entities.
Parameters
-
textType: strngThe text to un-escape.
Return Values
-
stringA string with all the XML entities un-escaped.
lousy.util.mkdir (dir)
Create a directory.
Parameters
-
dirType: stringThe directory.
Return Values
-
numberThe status code returned by
mkdir
; 0 indicates success.
lousy.util.eval (s)
Evaluate Lua code.
Parameters
-
sType: stringThe string of Lua code to evaluate.
Return Values
-
any typeThe return value of Lua code.
lousy.util.checkfile (path)
Check if a file is a Lua valid file.
This is done by loading the content and compiling it with loadfile()
.
Parameters
-
pathType: stringThe file path.
Return Values
-
function or nilA function if the file was loaded successfully, and a string with the error otherwise.
lousy.util.table.difference (t, other)
Return the difference of one table against another.
Parameters
-
tType: tableThe original table.
-
otherType: tableThe table to perform the difference against.
Return Values
-
any typeAll elements in the first table that are not in the other table.
lousy.util.table.join (args)
Join all tables given as parameters. This will iterate all tables and insert all their keys into a new table.
Parameters
-
argsType: {table}A list of tables to join.
Return Values
-
tableA new table containing all keys from the arguments.
lousy.util.table.hasitem (t, item)
Check if a table has an item and return its key.
Parameters
-
tType: tableThe table.
-
itemType: any typeThe item to look for in values of the table.
Return Values
-
any typeThe key where the item is found, or
nil
if not found.
lousy.util.table.keys (t)
Get a sorted table with all integer keys from a table.
Parameters
-
tType: tableThe table for which the keys to get.
Return Values
-
tableA table with keys.
lousy.util.table.reverse (t)
Reverse a table.
Parameters
-
tType: tableThe table to reverse.
Return Values
-
tableThe reversed table.
lousy.util.table.clone (t)
Clone a table.
Parameters
-
tType: tableThe table to clone.
Return Values
-
tableA clone of
t
.
lousy.util.table.copy (t)
Clone table and set metatable.
Parameters
-
tType: tableThe table to clone.
Return Values
-
tableA clone of
t
witht
's metatable.
lousy.util.table.isclone (a, b)
Check if two tables are identical.
Parameters
-
aType: tableThe first table.
-
bType: tableThe second table.
Return Values
-
boolean
true
if both tables are identical.
lousy.util.table.values (t)
Clone a table with all values as array items.
Parameters
-
tType: tableThe table to clone.
Return Values
-
tableAll values in
t
.
lousy.util.table.toarray (t)
Convert a table to an array by removing all keys that are not sequential numbers.
Parameters
-
tType: tableThe table to convert.
Return Values
-
tableA new table with all non-number keys removed.
lousy.util.table.filter_array (t, pred)
Filters an array with a predicate function. Element indices are shifted down to fill gaps.
Parameters
-
tType: tableThe array to filter.
-
predType: functionThe predicate function: called with (key, value); return
true
to keep element,false
to remove.
Return Values
-
tableThe filtered array.
lousy.util.os.exists (f)
Check if a file exists and is readable.
Parameters
-
fType: stringThe file path.
Return Values
-
boolean
true
if the file exists and is readable.
lousy.util.string.split (s, pattern, ret)
Python like string split (source: lua wiki).
Parameters
-
sType: stringThe string to split.
-
patternType: stringThe split pattern (I.e. "%s+" to split text by one or more whitespace characters).
-
retType: tableOptionalThe table to insert the split items in to or a new table if
nil
.
Return Values
-
tableA table of the string split by the pattern.
lousy.util.string.prev_glyph (s, o)
Find glyph backward (used in readline.lua).
Parameters
-
sType: stringThe string to be searched.
-
oType: numberThe starting offset to search a glyph backward.
Return Values
-
numberstring Offset and glyph if found, otherwise nil.
lousy.util.string.next_glyph (s, o)
Find glyph forward (used in readline.lua).
Parameters
-
sType: stringThe string to be searched.
-
oType: numberThe starting offset to search a glyph forward.
Return Values
-
numberstring Offset and glyph if found, otherwise nil.
lousy.util.find_config (f)
Search and return the filepath of a file in the current working directory, the luakit configuration directory, or the system luakit configuration directory.
Parameters
-
fType: stringThe relative filepath.
Return Values
-
stringThe first valid filepath or an error.
lousy.util.find_data (f)
Search and return the filepath of a file in the current working directory, the luakit data directory, or the luakit installation directory.
Parameters
-
fType: stringThe relative filepath.
Return Values
-
stringThe first valid filepath or an error.
lousy.util.find_cache (f)
Search and return the filepath of a file in the current working directory or the luakit cache directory.
Parameters
-
fType: stringThe relative filepath.
Return Values
-
stringThe first valid filepath or an error.
lousy.util.find_resource (f)
Search for and return the filepath of a file in luakit's resource directories.
Parameters
-
fType: stringThe relative filepath.
Return Values
-
stringThe first valid filepath or an error.
lousy.util.recursive_remove (wi)
Recursively traverse widget tree and return all widgets.
Parameters
-
wiType: widgetThe widget.
lousy.util.ntos (num, sigs)
Convert a number to string independent from locale.
Parameters
-
numType: numberA number.
-
sigsType: numberSignifigant figures (if float).
Return Values
-
stringThe string representation of the number.
lousy.util.sql_escape (s)
Escape values for SQL queries. In sqlite3: "A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal." Read: http://sqlite.org/lang_expr.html.
Parameters
-
sType: stringA string.
Return Values
-
stringThe escaped string.
lousy.util.lua_escape (s)
Escape values for lua patterns.
Escapes the magic characters ^$()%.[]*+-?)
by prepending a
%
.
Parameters
-
sType: stringA string.
Return Values
-
stringThe escaped pattern.
lousy.util.get_etc_hosts (force)
Get all hostnames in /etc/hosts
.
Parameters
-
forceType: booleanForce re-load of
/etc/hosts
.
Return Values
-
{string}Table of all hostnames in
/etc/hosts
.
Attribution
Copyright
- 2010 Mason Larobina
- 2008 Julien Danjou