Lua strings are sequences of bytes. They can contain any 8-bit value, including embedded zeros. Lua is eight-bit clean: strings can contain any 8-bit character, and all string operations work with the whole string, regardless of its contents. String literals can be delimited by matching single or double quotes.
To run this Lua script, save it to a file (e.g., strings_and_chars.lua) and execute it using the Lua interpreter:
In this Lua version, we use the utf8 library to handle Unicode characters. The utf8.codes function provides an iterator that decodes UTF-8 encoded strings. We also use utf8.codepoint to manually iterate through the string and decode each character.
Note that Lua doesn’t have a built-in concept of “runes”. Instead, we work with Unicode code points directly. The examineCharacter function demonstrates how to compare characters, including non-ASCII ones.