plugins/data: small cleanups (nw)

This commit is contained in:
cracyc 2019-11-29 10:17:34 -06:00
parent 35a1da30f1
commit b32f90e5a9
3 changed files with 20 additions and 12 deletions

View File

@ -236,9 +236,9 @@ local convert_text =
}
local function convert_char(str)
str = str:gsub("@([a-zA-Z%-]+)", function(s) if convert_text[s] then return utf8.char(convert_text[s] + 0xe000) end return s end)
str = str:gsub("_(.)", function(s) if default_text[s] then return utf8.char(default_text[s] + 0xe000) end return s end)
str = str:gsub("%^(.)", function(s) if expand_text[s] then return utf8.char(expand_text[s] + 0xe000) end return s end)
str = str:gsub("@(%g+)", function(s) if convert_text[s] then return utf8.char(convert_text[s] + 0xe000) end return s end)
str = str:gsub("_(%g)", function(s) if default_text[s] then return utf8.char(default_text[s] + 0xe000) end return s end)
str = str:gsub("%^(%g)", function(s) if expand_text[s] then return utf8.char(expand_text[s] + 0xe000) end return s end)
return str
end

View File

@ -2,7 +2,11 @@ local dat = {}
local info, ver
local datread = require("data/load_dat")
do
local convert = require("data/button_char")
local buttonchar
local function convert(str)
if not buttonchar then buttonchar = require("data/button_char") end
return buttonchar(str)
end
datread, ver = datread.open("command.dat", "# Version:", convert)
end

View File

@ -1,14 +1,11 @@
local datfile = {}
local db = require("data/database")
function datfile.open(file, vertag, fixupcb)
if not db then
return nil
end
local function readret(file)
local function read(tag1, tag2, set)
local data
local stmt = db.prepare("SELECT f.data FROM \"" .. file .. "_idx\" AS fi, \"" .. file .. [["
AS f WHERE fi.type = ? AND fi.val = ? AND fi.romset = ? AND f.rowid = fi.data]])
AS f WHERE fi.type = ? AND fi.val = ? AND fi.romset = ? AND f.rowid = fi.data]])
db.check("reading " .. tag1 .. " - " .. tag2 .. " - " .. set)
stmt:bind_values(tag1, tag2, set)
if stmt:step() == db.ROW then
@ -17,7 +14,14 @@ function datfile.open(file, vertag, fixupcb)
stmt:finalize()
return data
end
return read
end
function datfile.open(file, vertag, fixupcb)
if not db then
return nil
end
local ver, dbver
local filepath
local fh
@ -60,7 +64,7 @@ function datfile.open(file, vertag, fixupcb)
if vertag then
for line in fh:lines() do
local match = line:match(vertag .. "%s*([^%s]+)")
local match = line:match(vertag .. "%s*(%S+)")
if match then
ver = match
break
@ -106,7 +110,7 @@ function datfile.open(file, vertag, fixupcb)
if not spos then
return nil
end
npos, epos = buffer:find("[\n\r]$[%w]*[\n\r]+", epos)
npos, epos = buffer:find("[\n\r]$%w*[\n\r]+", epos)
if not npos then
return nil
end
@ -164,7 +168,7 @@ function datfile.open(file, vertag, fixupcb)
end
fh:close()
return read, ver
return readret(file), ver
end
return datfile