Skip to main content

Module string_lib

Module string_lib 

Source
Expand description

Standard library for string operations and pattern-matching.

Port of lstrlib.c (Lua 5.4.7, 1875 lines, 46 functions).

Sections:

  1. Basic string operations (byte, char, find, format, gmatch, gsub, len, lower, match, rep, reverse, sub, upper)
  2. Pattern-matching engine (MatchState + recursive matcher)
  3. String format (string.format)
  4. Pack / unpack (string.pack, string.packsize, string.unpack)
  5. Module registration (luaopen_string)

Constants§

STRING_LIB
Function table for string library.
STRING_META_METHODS
Metamethods to install on the string metatable.

Functions§

arith_add
arith_div
arith_idiv
arith_mod
arith_mul
arith_pow
arith_sub
arith_unm
createmetatable
Create the string metatable and set it as the metatable for all strings.
gmatch
string.gmatch(s, pattern [, init]) — return an iterator for all matches.
gmatch_aux
Continuation function for string.gmatch iterator closure.
luaopen_string
luaopen_string — open the string library.
str_byte
string.byte(s [, i [, j]]) — return numeric codes of characters.
str_char
string.char(...) — return string built from character codes.
str_dump
string.dump(function [, strip]) — serialize a function as binary chunk.
str_find
string.find(s, pattern [, init [, plain]]) — find pattern in s.
str_format
string.format(fmt, ...) — C-style string formatting.
str_gsub
string.gsub(s, pattern, repl [, n]) — global substitution.
str_len
string.len(s) — return byte-length of s.
str_lower
string.lower(s) — return lowercase copy.
str_match
string.match(s, pattern [, init]) — match pattern against s.
str_pack
string.pack(fmt, ...) — pack values into a binary string.
str_packsize
string.packsize(fmt) — return the byte-size the format would produce.
str_rep
string.rep(s, n [, sep]) — return n copies of s separated by sep.
str_reverse
string.reverse(s) — return string with bytes reversed.
str_sub
string.sub(s, i [, j]) — return substring.
str_unpack
string.unpack(fmt, s [, pos]) — unpack binary data from string.
str_upper
string.upper(s) — return uppercase copy.