gpu.copy, unicode lib
This commit is contained in:
parent
5d456c09ba
commit
44aabacc4c
@ -9,6 +9,8 @@ extern char lua_filesystem[];
|
|||||||
extern char lua_init[];
|
extern char lua_init[];
|
||||||
extern char lua_sandbox[];
|
extern char lua_sandbox[];
|
||||||
extern char lua_textgpu[];
|
extern char lua_textgpu[];
|
||||||
|
extern char lua_utf8_utf8data[];
|
||||||
|
extern char lua_utf8_utf8[];
|
||||||
extern char lua_util_color[];
|
extern char lua_util_color[];
|
||||||
extern char lua_util_random[];
|
extern char lua_util_random[];
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,14 +5,15 @@
|
|||||||
# $4 prefix
|
# $4 prefix
|
||||||
|
|
||||||
generate() {
|
generate() {
|
||||||
LUAFILES="$1/*"
|
local LUAFILES="$1/*"
|
||||||
OUTPUTH="$2"
|
local OUTPUTH="$2"
|
||||||
OUTPUTC="$3"
|
local OUTPUTC="$3"
|
||||||
PREFIX="$4"
|
local PREFIX="$4"
|
||||||
|
|
||||||
outname="$(basename "$OUTPUTH")"
|
local outname="$(basename "$OUTPUTH")"
|
||||||
outname="${outname%.*}"
|
outname="${outname%.*}"
|
||||||
guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]')
|
|
||||||
|
local guard=$(echo "$outname" | tr '[:lower:]' '[:upper:]')
|
||||||
guard="$guard""_H"
|
guard="$guard""_H"
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <linux/kd.h>
|
#include <linux/kd.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef LOGGING
|
||||||
void logn (const char *message) {
|
void logn (const char *message) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
@ -58,7 +60,11 @@ void logm (const char *message) {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define logn(m)
|
||||||
|
#define logi(m)
|
||||||
|
#define logm(m)
|
||||||
|
#endif
|
||||||
|
|
||||||
static int l_sleep (lua_State *L) {
|
static int l_sleep (lua_State *L) {
|
||||||
unsigned int t = lua_tonumber(L, 1);
|
unsigned int t = lua_tonumber(L, 1);
|
||||||
|
@ -18,6 +18,8 @@ void setup_modules(lua_State *L) {
|
|||||||
pushstuple(L, "textgpu", lua_textgpu);
|
pushstuple(L, "textgpu", lua_textgpu);
|
||||||
pushstuple(L, "color", lua_util_color);
|
pushstuple(L, "color", lua_util_color);
|
||||||
pushstuple(L, "random", lua_util_random);
|
pushstuple(L, "random", lua_util_random);
|
||||||
|
pushstuple(L, "utf8data", lua_utf8_utf8data);
|
||||||
|
pushstuple(L, "utf8", lua_utf8_utf8);
|
||||||
|
|
||||||
lua_setglobal(L, "moduleCode");
|
lua_setglobal(L, "moduleCode");
|
||||||
}
|
}
|
@ -6,14 +6,18 @@ function computer.prepare( ... )
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local signalQueue = {}
|
||||||
|
|
||||||
function api.pushSignal(...)
|
function api.pushSignal(...)
|
||||||
--FIXME: ASAP: Implement
|
signalQueue[#signalQueue + 1] = {...}
|
||||||
end
|
end
|
||||||
|
|
||||||
function api.pullSignal(timeout)
|
function api.pullSignal(timeout)
|
||||||
|
if signalQueue[1] then return table.remove(signalQueue, 1) end
|
||||||
if type(timeout) == "number" then
|
if type(timeout) == "number" then
|
||||||
native.sleep(timeout * 1000000);
|
native.sleep(timeout * 1000000);
|
||||||
end
|
end
|
||||||
|
if signalQueue[1] then return table.remove(signalQueue, 1) end
|
||||||
--print(debug.traceback())
|
--print(debug.traceback())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ deadhooks = {}
|
|||||||
|
|
||||||
local function loadModule(name)
|
local function loadModule(name)
|
||||||
print("LuPI L1 INIT > Load module > " .. name)
|
print("LuPI L1 INIT > Load module > " .. name)
|
||||||
|
io.flush()
|
||||||
--TODO: PRERELEASE: Module sandboxing, preferably secure-ish
|
--TODO: PRERELEASE: Module sandboxing, preferably secure-ish
|
||||||
--TODO: ASAP: Handle load errors
|
--TODO: ASAP: Handle load errors
|
||||||
if not moduleCode[name] then
|
if not moduleCode[name] then
|
||||||
@ -30,6 +31,7 @@ local function loadModule(name)
|
|||||||
local code, reason = load(moduleCode[name], "=Module "..name)
|
local code, reason = load(moduleCode[name], "=Module "..name)
|
||||||
if not code then
|
if not code then
|
||||||
print("Failed loading module " .. name .. ": " .. reason)
|
print("Failed loading module " .. name .. ": " .. reason)
|
||||||
|
io.flush()
|
||||||
else
|
else
|
||||||
modules[name] = code()
|
modules[name] = code()
|
||||||
end
|
end
|
||||||
@ -40,6 +42,8 @@ function main()
|
|||||||
--Utils
|
--Utils
|
||||||
loadModule("random")
|
loadModule("random")
|
||||||
loadModule("color")
|
loadModule("color")
|
||||||
|
loadModule("utf8data")
|
||||||
|
loadModule("utf8")
|
||||||
|
|
||||||
--Core
|
--Core
|
||||||
loadModule("component")
|
loadModule("component")
|
||||||
|
@ -160,6 +160,24 @@ sandbox = {
|
|||||||
len = utf8.len,
|
len = utf8.len,
|
||||||
offset = utf8.offset
|
offset = utf8.offset
|
||||||
},
|
},
|
||||||
|
unicode = {
|
||||||
|
char = utf8.char,
|
||||||
|
charWidth = function(c)
|
||||||
|
checkArg(1, c, "string")
|
||||||
|
return modules.utf8.utf8charbytes(c)
|
||||||
|
end,
|
||||||
|
isWide = function(c)
|
||||||
|
checkArg(1, c, "string")
|
||||||
|
return modules.utf8.utf8charbytes(c) > 1
|
||||||
|
end,
|
||||||
|
len = utf8.len,
|
||||||
|
lower = modules.utf8.lower,
|
||||||
|
reverse = modules.utf8.reverse,
|
||||||
|
sub = modules.utf8.sub,
|
||||||
|
upper = modules.utf8.upper,
|
||||||
|
wlen = utf8.len, --How is it different from len?
|
||||||
|
--wtrunc?
|
||||||
|
},
|
||||||
checkArg = checkArg,
|
checkArg = checkArg,
|
||||||
og = _G
|
og = _G
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,36 @@ local mapping = {
|
|||||||
["7"] = 0xFFFFFF,
|
["7"] = 0xFFFFFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--[[local nw = io.write
|
||||||
|
io.write = function(...)
|
||||||
|
nw(...)
|
||||||
|
io.flush()
|
||||||
|
native.sleep(20000)
|
||||||
|
end]]--
|
||||||
|
|
||||||
local background = "0"
|
local background = "0"
|
||||||
local foreground = "0"
|
local foreground = "0"
|
||||||
|
|
||||||
|
local tbuffer = {}
|
||||||
|
local bbuffer = {}
|
||||||
|
local fbuffer = {}
|
||||||
|
|
||||||
|
local function prepareBuffers(w, h)
|
||||||
|
local tbline = (" "):rep(w)
|
||||||
|
local bbline = ("0"):rep(w)
|
||||||
|
local fbline = ("7"):rep(w)
|
||||||
|
for i=1, h do
|
||||||
|
tbuffer[i] = tbline
|
||||||
|
bbuffer[i] = bbline
|
||||||
|
fbuffer[i] = fbline
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local usub = modules.utf8.sub
|
||||||
|
local function insertString(main, sub, at)
|
||||||
|
return usub(main, 1, at - 1) .. sub .. usub(main, at + utf8.len(sub))
|
||||||
|
end
|
||||||
|
|
||||||
function textgpu.start()
|
function textgpu.start()
|
||||||
local gpu = {}
|
local gpu = {}
|
||||||
function gpu.bind() return false, "This is static bound gpu" end
|
function gpu.bind() return false, "This is static bound gpu" end
|
||||||
@ -24,8 +51,8 @@ function textgpu.start()
|
|||||||
if isPaletteIndex then
|
if isPaletteIndex then
|
||||||
return --TODO: Maybe?
|
return --TODO: Maybe?
|
||||||
end
|
end
|
||||||
background = modules.color.nearest(color, mapping)
|
background = tostring(math.floor(modules.color.nearest(color, mapping)))
|
||||||
io.write("\x1b[4" .. math.floor(background) .. "m")
|
io.write("\x1b[4" .. background .. "m")
|
||||||
io.flush()
|
io.flush()
|
||||||
end
|
end
|
||||||
function gpu.setForeground(color, isPaletteIndex)
|
function gpu.setForeground(color, isPaletteIndex)
|
||||||
@ -34,8 +61,8 @@ function textgpu.start()
|
|||||||
if isPaletteIndex then
|
if isPaletteIndex then
|
||||||
return --TODO: Maybe?
|
return --TODO: Maybe?
|
||||||
end
|
end
|
||||||
foreground = modules.color.nearest(color, mapping)
|
foreground = tostring(math.floor(modules.color.nearest(color, mapping)))
|
||||||
io.write("\x1b[3" .. math.floor(foreground) .. "m")
|
io.write("\x1b[3" .. foreground .. "m")
|
||||||
io.flush()
|
io.flush()
|
||||||
end
|
end
|
||||||
function gpu.getBackground()
|
function gpu.getBackground()
|
||||||
@ -84,6 +111,9 @@ function textgpu.start()
|
|||||||
x = math.floor(x)
|
x = math.floor(x)
|
||||||
y = math.floor(y)
|
y = math.floor(y)
|
||||||
if not vertical then
|
if not vertical then
|
||||||
|
tbuffer[y] = insertString(tbuffer[y], value, x)
|
||||||
|
bbuffer[y] = insertString(bbuffer[y], background:rep(utf8.len(value)), x)
|
||||||
|
fbuffer[y] = insertString(fbuffer[y], foreground:rep(utf8.len(value)), x)
|
||||||
io.write("\x1b[" .. y .. ";" .. x .. "H" .. value)
|
io.write("\x1b[" .. y .. ";" .. x .. "H" .. value)
|
||||||
else
|
else
|
||||||
io.write("\x1b[" .. y .. ";" .. x .. "H")
|
io.write("\x1b[" .. y .. ";" .. x .. "H")
|
||||||
@ -94,15 +124,68 @@ function textgpu.start()
|
|||||||
io.flush()
|
io.flush()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
function gpu.copy(x, y, w, h, tx, ty)
|
function gpu.copy(x, y, w, h, tx, ty) --TODO: Check(check X multiple times)
|
||||||
checkArg(1, x, "number")
|
checkArg(1, x, "number")
|
||||||
checkArg(2, y, "number")
|
checkArg(2, y, "number")
|
||||||
checkArg(3, w, "number")
|
checkArg(3, w, "number")
|
||||||
checkArg(4, h, "number")
|
checkArg(4, h, "number")
|
||||||
checkArg(5, tx, "number")
|
checkArg(5, tx, "number")
|
||||||
checkArg(6, ty, "number")
|
checkArg(6, ty, "number")
|
||||||
--FIXME: ASAP: Implement
|
local ttbuf = {}
|
||||||
return false
|
local btbuf = {}
|
||||||
|
local ftbuf = {}
|
||||||
|
for i=1, h do
|
||||||
|
ttbuf[i] = tbuffer[y + i - 1] and tbuffer[y + i - 1]:sub(x, x + w - 1) or (" "):rep(w)
|
||||||
|
btbuf[i] = bbuffer[y + i - 1] and bbuffer[y + i - 1]:sub(x, x + w - 1) or background:rep(w)
|
||||||
|
ftbuf[i] = fbuffer[y + i - 1] and fbuffer[y + i - 1]:sub(x, x + w - 1) or foreground:rep(w)
|
||||||
|
end
|
||||||
|
local bg = background
|
||||||
|
local fg = foreground
|
||||||
|
|
||||||
|
for i=1, h do
|
||||||
|
local line, linex
|
||||||
|
local write = false
|
||||||
|
for j=1, w do
|
||||||
|
if btbuf[i]:sub(j,j) ~= bg then
|
||||||
|
bg = btbuf[i]:sub(j,j)
|
||||||
|
io.write("\x1b[4" .. bg .. "m")
|
||||||
|
write = true
|
||||||
|
end
|
||||||
|
if ftbuf[i]:sub(j,j) ~= fg then
|
||||||
|
fg = ftbuf[i]:sub(j,j)
|
||||||
|
io.write("\x1b[3" .. fg .. "m")
|
||||||
|
write = true
|
||||||
|
end
|
||||||
|
if not line then linex = j end
|
||||||
|
line = (line or "") .. ttbuf[i]:sub(j,j)
|
||||||
|
if write then
|
||||||
|
local wx = (tx + linex)|0
|
||||||
|
local wy = (ty + y + i - 1)|0
|
||||||
|
io.write("\x1b[" .. wy .. ";" .. wx .. "H" .. line)
|
||||||
|
tbuffer[wy] = insertString(tbuffer[wy], line, wx)
|
||||||
|
bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx)
|
||||||
|
fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
|
||||||
|
line = nil
|
||||||
|
linex = nil
|
||||||
|
write = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if line then
|
||||||
|
local wx = (tx + linex)|0
|
||||||
|
local wy = (ty + y + i - 1)|0
|
||||||
|
io.write("\x1b[" .. wy .. ";" .. wx .. "H" .. line)
|
||||||
|
tbuffer[wy] = insertString(tbuffer[wy], line, wx)
|
||||||
|
bbuffer[wy] = insertString(bbuffer[wy], bg:rep(utf8.len(line)), wx)
|
||||||
|
fbuffer[wy] = insertString(fbuffer[wy], fg:rep(utf8.len(line)), wx)
|
||||||
|
line = nil
|
||||||
|
linex = nil
|
||||||
|
write = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
io.write("\x1b[4" .. background .. "m")
|
||||||
|
io.write("\x1b[3" .. foreground .. "m")
|
||||||
|
io.flush()
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
function gpu.fill(x, y, w, h, ch)
|
function gpu.fill(x, y, w, h, ch)
|
||||||
checkArg(1, x, "number")
|
checkArg(1, x, "number")
|
||||||
@ -118,6 +201,8 @@ function textgpu.start()
|
|||||||
end
|
end
|
||||||
|
|
||||||
io.write("\x1b[?25l") --Disable cursor
|
io.write("\x1b[?25l") --Disable cursor
|
||||||
|
local w, h = gpu.getResolution()
|
||||||
|
prepareBuffers(w, h)
|
||||||
gpu.setForeground(0xFFFFFF)
|
gpu.setForeground(0xFFFFFF)
|
||||||
gpu.setBackground(0x000000)
|
gpu.setBackground(0x000000)
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
--
|
--
|
||||||
|
|
||||||
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
|
local strbyte, strlen, strsub, type = string.byte, string.len, string.sub, type
|
||||||
|
local utf8 = {}
|
||||||
|
|
||||||
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
-- returns the number of bytes used by the UTF-8 character at byte i in s
|
||||||
-- also doubles as a UTF-8 character validator
|
-- also doubles as a UTF-8 character validator
|
||||||
@ -154,6 +155,8 @@ local function utf8charbytes(s, i)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
utf8.charbytes = utf8charbytes
|
||||||
|
|
||||||
-- returns the number of characters in a UTF-8 string
|
-- returns the number of characters in a UTF-8 string
|
||||||
local function utf8len(s)
|
local function utf8len(s)
|
||||||
-- argument checking
|
-- argument checking
|
||||||
@ -173,10 +176,7 @@ local function utf8len(s)
|
|||||||
return len
|
return len
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install in the string library
|
utf8.len = utf8len
|
||||||
if not string.utf8len then
|
|
||||||
string.utf8len = utf8len
|
|
||||||
end
|
|
||||||
|
|
||||||
-- functions identically to string.sub except that i and j are UTF-8 characters
|
-- functions identically to string.sub except that i and j are UTF-8 characters
|
||||||
-- instead of bytes
|
-- instead of bytes
|
||||||
@ -230,10 +230,7 @@ local function utf8sub(s, i, j)
|
|||||||
return strsub(s, startByte, endByte)
|
return strsub(s, startByte, endByte)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install in the string library
|
utf8.sub = utf8sub
|
||||||
if not string.utf8sub then
|
|
||||||
string.utf8sub = utf8sub
|
|
||||||
end
|
|
||||||
|
|
||||||
-- replace UTF-8 characters based on a mapping table
|
-- replace UTF-8 characters based on a mapping table
|
||||||
local function utf8replace(s, mapping)
|
local function utf8replace(s, mapping)
|
||||||
@ -264,23 +261,17 @@ end
|
|||||||
|
|
||||||
-- identical to string.upper except it knows about unicode simple case conversions
|
-- identical to string.upper except it knows about unicode simple case conversions
|
||||||
local function utf8upper(s)
|
local function utf8upper(s)
|
||||||
return utf8replace(s, utf8_lc_uc)
|
return utf8replace(s, modules.utf8data.lc_uc)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install in the string library
|
utf8.upper = utf8upper
|
||||||
if not string.utf8upper and utf8_lc_uc then
|
|
||||||
string.utf8upper = utf8upper
|
|
||||||
end
|
|
||||||
|
|
||||||
-- identical to string.lower except it knows about unicode simple case conversions
|
-- identical to string.lower except it knows about unicode simple case conversions
|
||||||
local function utf8lower(s)
|
local function utf8lower(s)
|
||||||
return utf8replace(s, utf8_uc_lc)
|
return utf8replace(s, modules.utf8data.uc_lc)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install in the string library
|
utf8.lower = utf8lower
|
||||||
if not string.utf8lower and utf8_uc_lc then
|
|
||||||
string.utf8lower = utf8lower
|
|
||||||
end
|
|
||||||
|
|
||||||
-- identical to string.reverse except that it supports UTF-8
|
-- identical to string.reverse except that it supports UTF-8
|
||||||
local function utf8reverse(s)
|
local function utf8reverse(s)
|
||||||
@ -311,7 +302,6 @@ local function utf8reverse(s)
|
|||||||
return newstr
|
return newstr
|
||||||
end
|
end
|
||||||
|
|
||||||
-- install in the string library
|
utf8.reverse = utf8reverse
|
||||||
if not string.utf8reverse then
|
|
||||||
string.utf8reverse = utf8reverse
|
return utf8
|
||||||
end
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
utf8_lc_uc = {
|
local lc_uc = {
|
||||||
["a"] = "A",
|
["a"] = "A",
|
||||||
["b"] = "B",
|
["b"] = "B",
|
||||||
["c"] = "C",
|
["c"] = "C",
|
||||||
@ -933,7 +933,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
utf8_uc_lc = {
|
local uc_lc = {
|
||||||
["A"] = "a",
|
["A"] = "a",
|
||||||
["B"] = "b",
|
["B"] = "b",
|
||||||
["C"] = "c",
|
["C"] = "c",
|
||||||
@ -1858,3 +1858,4 @@ utf8_uc_lc = {
|
|||||||
["𐐧"] = "𐑏",
|
["𐐧"] = "𐑏",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {uc_lc = uc_lc, lc_uc = lc_uc}
|
||||||
|
Loading…
Reference in New Issue
Block a user