Module ffi.util

Module for various utility functions.

Functions

realpath (path) Wrapper for C.realpath.
basename (path) Wrapper for C.basename.
dirname (in_path) Wrapper for C.dirname.
copyFile (from, to) Copies file.
joinPath (path1, path2) Joins paths.
purgeDir (dir) Purges directory.
execute (...) Executes child process.
getNonBlockingReadSize (luafile) Returns the length of data that can be read immediately without blocking
utf8charcode (charstring) Gets UTF-8 charcode.
multiByteToUTF8 (str, codepage) Converts multibyte string to utf-8 encoded string on Windows.
isWindows () Returns true if isWindows…
isAndroid () Returns true if Android.
haveSDL2 () Returns true if SDL2
isSDL () Returns true if SDL (can be 1 or 2)
idiv (a, b) Division with integer result.
orderedPairs (t) Equivalent of the pairs() function on tables.
template (str, ...) The util.template function allows for better translations through dynamic positioning of place markers.


Functions

realpath (path)
Wrapper for C.realpath.

Parameters:

  • path
basename (path)
Wrapper for C.basename.

Parameters:

  • path
dirname (in_path)
Wrapper for C.dirname.

Parameters:

  • in_path [[
copyFile (from, to)
Copies file.

Parameters:

  • from
  • to
joinPath (path1, path2)
Joins paths.

NOTE: If path2 is an absolute path, then this function ignores path1 and returns path2 directly.

Parameters:

  • path1
  • path2
purgeDir (dir)
Purges directory.

Parameters:

  • dir
execute (...)
Executes child process.

Parameters:

  • ...
getNonBlockingReadSize (luafile)
Returns the length of data that can be read immediately without blocking

Parameters:

  • luafile returns 0 if not readable yet, otherwise len of available data returns nil when unsupported caller may read (with possible blocking)
utf8charcode (charstring)
Gets UTF-8 charcode.

Parameters:

  • charstring
multiByteToUTF8 (str, codepage)
Converts multibyte string to utf-8 encoded string on Windows.

Parameters:

  • str
  • codepage if codepage is not provided we will query the system codepage
isWindows ()
Returns true if isWindows…
isAndroid ()
Returns true if Android. For now, we just check if the "android" module can be loaded.
haveSDL2 ()
Returns true if SDL2
isSDL ()
Returns true if SDL (can be 1 or 2)
idiv (a, b)
Division with integer result.

Parameters:

  • a
  • b
orderedPairs (t)
Equivalent of the pairs() function on tables. Allows to iterate in order.

Parameters:

  • t
template (str, ...)
The util.template function allows for better translations through dynamic positioning of place markers. The range of place markers runs from %1 to %99, but normally no more than two or three should be required. There are no provisions for escaping place markers.

Parameters:

  • str
  • ...

Usage:

    output = util.template(
        _("Hello %1, welcome to %2."),
        name,
        company
    )
    
     function was inspired by Qt:
    p://qt-project.org/doc/qt-4.8/internationalization.html#use-qstring-arg-for-dynamic-text>
generated by LDoc 1.4.6 Last updated 2017-10-08 14:57:40