Love Frames
repository·master·Indexed 41 days ago
https://github.com/linux-man/loveframesA GUI library designed for the LÖVE game engine, including utf8.lua, a pure-Lua 5.3 regex library compatible with Lua 5.1 and LuaJIT that provides UTF-8 support as a drop-in replacement for the standard Lua string library.
What's inside Love Frames
- Love Frames is a GUI (Graphical User Interface) library designed specifically for the LÖVE game engine. It provides tools for building user interfaces within LÖVE-based applications.
Install utf8.lua
masterTo install
utf8.lua, download the repository directly into your project folder. Note that there are currently no rockspecs available for package managers.Because the default Lua 5.3
utf8module takes precedence, you should use the full module path (e.g.,.utf8) when requiring the library to ensure you are using this UTF-8 enabled version.local utf8 = require('.utf8'):init()Use utf8.lua as a drop-in replacement for the string library
masterYou can integrate
utf8.luainto your application in two ways:- Monkey-patching the global string library: This replaces the standard Lua
stringfunctions with UTF-8 aware versions globally. - Using the
utf8object directly: This keeps the standard library intact and allows you to call UTF-8 functions via theutf8instance.
The library exports all vanilla string functions under the
utf8.rawsub-object.-- Option 1: Global monkey-patching local utf8 = require('.utf8'):init() for k,v in pairs(utf8) do string[k] = v end -- Option 2: Direct usage via the utf8 object local utf8 = require('.utf8'):init() local str = "пыщпыщ ололоо я водитель нло" utf8.gsub(str, "ло+", "보라") -- Accessing vanilla (non-UTF8) functions utf8.raw.gsub(str, "ло+", "보라")- Monkey-patching the global string library: This replaces the standard Lua
Configure utf8.lua customization and caching
masterThe library is highly modular and allows for customization of its back-ends and performance settings. Customization must be performed before calling
:init().Key configuration options include:
utf8.config.cache: Provide a custom cache object (e.g.,my_smart_cache) to precompile and store regexes.utf8.config.loadstring: Customize how strings are loaded/compiled.
If you change configuration after calling
:init(), changes might apply to some parts of the library, but modules will require a reload to reflect the new settings.local utf8 = require('.utf8') utf8.config = { cache = my_smart_cache, } utf8:init()Validate UTF-8 strings
masterWhile
utf8.luaprovides most functions from the Lua 5.3 UTF-8 module, it does not includeutf8.len. To validate strings, use the following methods:utf8.validate(str, byte_pos): Validates the string starting from a specific byte position.utf8.validator: An iterator for validating strings.