Lua4z
A binary distribution of Lua for z/OS, with batteries

Module iconv

POSIX iconv binding for Lua.

Converts strings from one codeset to another. For more information, see the original Lua-iconv documentation.

For implementation-specific details of each function, see the corresponding z/OS C runtime library functions.

Functions

iconv (converter, string) Converts a string from one codeset to another.
new (to, from) Create a conversion descriptor that you can then use with the iconv function to convert a string from one codeset to another.
open (to, from) A synonym for the new function.

Functions

iconv (converter, string)
Converts a string from one codeset to another.

This function calls the C runtime library function iconv().

Parameters:

  • converter A conversion descriptor created previously by the iconv function.
  • string string The string that you want to convert.

Returns:

    Two arguments: the converted string and an error code. The error code has one of the following values:
    iconv error codes
    Error code Description
    nil No error. Conversion was successful.
    iconv.ERROR_NO_MEMORY Failed to allocate enough memory in the conversion process.
    iconv.ERROR_INVALID An invalid character was found in the input sequence.
    iconv.ERROR_INCOMPLETE An incomplete character was found in the input sequence.
    iconv.ERROR_FINALIZED Trying to use an already-finalized converter. This usually means that the user was tweaking the garbage collector private methods.
    iconv.ERROR_UNKNOWN There was an unknown error.

See also:

Usage:

     -- Assumes that you have created a conversion descriptor named converter
     local before = "Transliterate me"
     local after = converter:iconv(before)
new (to, from)
Create a conversion descriptor that you can then use with the iconv function to convert a string from one codeset to another.

For a list of supported codesets, see the IBM documentation.

Parameters:

  • to string A string that specifies the codeset that you want to convert from.

    To enable character transliteration, append the string "//TRANSLIT" to the value of this parameter.

    To ignore invalid characters in the input string to the iconv function, append the string "//IGNORE" to the value of this parameter.

  • from string A string that specifies the codeset that you want to convert to.

Returns:

    A conversion descriptor that describes a conversion between two codesets, or nil on error.

See also:

Usage:

     local iconv = require("iconv")
     -- Specify codesets
     local from = "IBM-1047"
     local to = "ISO8859-1"
     -- Create conversion descriptor with transliteration option
     local converter = iconv.new(to .. "//TRANSLIT", from) 
open (to, from)
A synonym for the new function.