setup for luarocks releases
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
local UTF8 = require((...):match("(.-)[^%.]+$") .. "UTF8")
|
||||
|
||||
---@class Renderer
|
||||
---@field backgroundColor Color
|
||||
---@field borderColor Color
|
||||
@@ -463,7 +465,7 @@ end
|
||||
---@return table Array of {text, startIdx, endIdx}
|
||||
function Renderer:wrapLine(element, line, maxWidth)
|
||||
-- UTF-8 support
|
||||
local utf8 = utf8 or require("utf8")
|
||||
local utf8 = UTF8
|
||||
|
||||
if not element.editable then
|
||||
return { { text = line, startIdx = 0, endIdx = utf8.len(line) } }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local utf8 = utf8 or require("utf8")
|
||||
local UTF8 = require((...):match("(.-)[^%.]+$") .. "UTF8")
|
||||
local utf8 = UTF8
|
||||
|
||||
---@class TextEditor
|
||||
---@field editable boolean
|
||||
|
||||
44
modules/UTF8.lua
Normal file
44
modules/UTF8.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
---@class UTF8
|
||||
---Compatibility layer for UTF-8 support across Lua versions
|
||||
---Handles utf8 (Lua 5.3+), lua-utf8 (LuaRocks), and basic fallbacks
|
||||
|
||||
local UTF8 = {}
|
||||
|
||||
-- Try to load UTF-8 library in order of preference:
|
||||
-- 1. Built-in utf8 (Lua 5.3+, LÖVE2D)
|
||||
-- 2. lua-utf8 from LuaRocks (Lua 5.1, 5.2)
|
||||
-- 3. Error if neither available
|
||||
local function loadUTF8()
|
||||
-- Try built-in utf8 first (Lua 5.3+ and LÖVE2D)
|
||||
if utf8 and type(utf8) == "table" and utf8.len then
|
||||
return utf8
|
||||
end
|
||||
|
||||
-- Try lua-utf8 from LuaRocks
|
||||
local ok, luautf8 = pcall(require, "lua-utf8")
|
||||
if ok then
|
||||
return luautf8
|
||||
end
|
||||
|
||||
-- Try standard utf8 module name as fallback
|
||||
ok, luautf8 = pcall(require, "utf8")
|
||||
if ok then
|
||||
return luautf8
|
||||
end
|
||||
|
||||
-- No UTF-8 library available
|
||||
error("No UTF-8 library available. Please install 'luautf8' via LuaRocks: luarocks install luautf8")
|
||||
end
|
||||
|
||||
-- Load the UTF-8 implementation
|
||||
local utf8lib = loadUTF8()
|
||||
|
||||
-- Export all utf8 functions
|
||||
UTF8.char = utf8lib.char
|
||||
UTF8.charpattern = utf8lib.charpattern
|
||||
UTF8.codes = utf8lib.codes
|
||||
UTF8.codepoint = utf8lib.codepoint
|
||||
UTF8.len = utf8lib.len
|
||||
UTF8.offset = utf8lib.offset
|
||||
|
||||
return UTF8
|
||||
Reference in New Issue
Block a user