From 999a563a3ecb16b52258d3b53b702702a5a2e188 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:25:43 +0200 Subject: [PATCH 1/4] Rename changeableObject.lua to ChangeableObject.lua --- Basalt/objects/{changeableObject.lua => ChangeableObject.lua} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Basalt/objects/{changeableObject.lua => ChangeableObject.lua} (99%) diff --git a/Basalt/objects/changeableObject.lua b/Basalt/objects/ChangeableObject.lua similarity index 99% rename from Basalt/objects/changeableObject.lua rename to Basalt/objects/ChangeableObject.lua index 3ef6dd7..8779d8c 100644 --- a/Basalt/objects/changeableObject.lua +++ b/Basalt/objects/ChangeableObject.lua @@ -37,4 +37,4 @@ return function(name, basalt) object.__index = object return setmetatable(object, base) -end \ No newline at end of file +end From 79a8ec5f3a00251145c2c0d1e6b0639eb4d65f66 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:26:37 +0200 Subject: [PATCH 2/4] Update plugin.lua --- Basalt/plugin.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Basalt/plugin.lua b/Basalt/plugin.lua index 11c850e..373a9fe 100644 --- a/Basalt/plugin.lua +++ b/Basalt/plugin.lua @@ -5,7 +5,7 @@ local dir = fs.getDir(args[2] or "Basalt") local pluginDir = fs.combine(dir, "plugins") if(packaged)then for k,v in pairs(getProject("plugins"))do - local newPlugin = require(v:gsub(".lua", "")) + local newPlugin = v() if(type(newPlugin)=="table")then for a,b in pairs(newPlugin)do if(type(a)=="string")then @@ -53,4 +53,4 @@ return { end return objects end -} \ No newline at end of file +} From 4f46c55f24abfda2a1c970b1fa33a867ce35a866 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:26:55 +0200 Subject: [PATCH 3/4] Delete bigfont.lua --- Basalt/libraries/bigfont.lua | 139 ----------------------------------- 1 file changed, 139 deletions(-) delete mode 100644 Basalt/libraries/bigfont.lua diff --git a/Basalt/libraries/bigfont.lua b/Basalt/libraries/bigfont.lua deleted file mode 100644 index 9d8d14c..0000000 --- a/Basalt/libraries/bigfont.lua +++ /dev/null @@ -1,139 +0,0 @@ -------------------------------------------------------------------------------------- --- Wojbies API 5.0 - Bigfont - functions to write bigger font using drawing sybols -- -------------------------------------------------------------------------------------- --- Copyright (c) 2015-2022 Wojbie (wojbie@wojbie.net) --- Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: --- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. --- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. --- 4. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. --- 5. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. --- NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY NUCLEAR FACILITY. - -local tHex = require("tHex") - -local rawFont = {{"\32\32\32\137\156\148\158\159\148\135\135\144\159\139\32\136\157\32\159\139\32\32\143\32\32\143\32\32\32\32\32\32\32\32\147\148\150\131\148\32\32\32\151\140\148\151\140\147", "\32\32\32\149\132\149\136\156\149\144\32\133\139\159\129\143\159\133\143\159\133\138\32\133\138\32\133\32\32\32\32\32\32\150\150\129\137\156\129\32\32\32\133\131\129\133\131\132", "\32\32\32\130\131\32\130\131\32\32\129\32\32\32\32\130\131\32\130\131\32\32\32\32\143\143\143\32\32\32\32\32\32\130\129\32\130\135\32\32\32\32\131\32\32\131\32\131", "\139\144\32\32\143\148\135\130\144\149\32\149\150\151\149\158\140\129\32\32\32\135\130\144\135\130\144\32\149\32\32\139\32\159\148\32\32\32\32\159\32\144\32\148\32\147\131\132", "\159\135\129\131\143\149\143\138\144\138\32\133\130\149\149\137\155\149\159\143\144\147\130\132\32\149\32\147\130\132\131\159\129\139\151\129\148\32\32\139\131\135\133\32\144\130\151\32", "\32\32\32\32\32\32\130\135\32\130\32\129\32\129\129\131\131\32\130\131\129\140\141\132\32\129\32\32\129\32\32\32\32\32\32\32\131\131\129\32\32\32\32\32\32\32\32\32", "\32\32\32\32\149\32\159\154\133\133\133\144\152\141\132\133\151\129\136\153\32\32\154\32\159\134\129\130\137\144\159\32\144\32\148\32\32\32\32\32\32\32\32\32\32\32\151\129", "\32\32\32\32\133\32\32\32\32\145\145\132\141\140\132\151\129\144\150\146\129\32\32\32\138\144\32\32\159\133\136\131\132\131\151\129\32\144\32\131\131\129\32\144\32\151\129\32", "\32\32\32\32\129\32\32\32\32\130\130\32\32\129\32\129\32\129\130\129\129\32\32\32\32\130\129\130\129\32\32\32\32\32\32\32\32\133\32\32\32\32\32\129\32\129\32\32", "\150\156\148\136\149\32\134\131\148\134\131\148\159\134\149\136\140\129\152\131\32\135\131\149\150\131\148\150\131\148\32\148\32\32\148\32\32\152\129\143\143\144\130\155\32\134\131\148", "\157\129\149\32\149\32\152\131\144\144\131\148\141\140\149\144\32\149\151\131\148\32\150\32\150\131\148\130\156\133\32\144\32\32\144\32\130\155\32\143\143\144\32\152\129\32\134\32", "\130\131\32\131\131\129\131\131\129\130\131\32\32\32\129\130\131\32\130\131\32\32\129\32\130\131\32\130\129\32\32\129\32\32\133\32\32\32\129\32\32\32\130\32\32\32\129\32", "\150\140\150\137\140\148\136\140\132\150\131\132\151\131\148\136\147\129\136\147\129\150\156\145\138\143\149\130\151\32\32\32\149\138\152\129\149\32\32\157\152\149\157\144\149\150\131\148", "\149\143\142\149\32\149\149\32\149\149\32\144\149\32\149\149\32\32\149\32\32\149\32\149\149\32\149\32\149\32\144\32\149\149\130\148\149\32\32\149\32\149\149\130\149\149\32\149", "\130\131\129\129\32\129\131\131\32\130\131\32\131\131\32\131\131\129\129\32\32\130\131\32\129\32\129\130\131\32\130\131\32\129\32\129\131\131\129\129\32\129\129\32\129\130\131\32", "\136\140\132\150\131\148\136\140\132\153\140\129\131\151\129\149\32\149\149\32\149\149\32\149\137\152\129\137\152\129\131\156\133\149\131\32\150\32\32\130\148\32\152\137\144\32\32\32", "\149\32\32\149\159\133\149\32\149\144\32\149\32\149\32\149\32\149\150\151\129\138\155\149\150\130\148\32\149\32\152\129\32\149\32\32\32\150\32\32\149\32\32\32\32\32\32\32", "\129\32\32\130\129\129\129\32\129\130\131\32\32\129\32\130\131\32\32\129\32\129\32\129\129\32\129\32\129\32\131\131\129\130\131\32\32\32\129\130\131\32\32\32\32\140\140\132", "\32\154\32\159\143\32\149\143\32\159\143\32\159\144\149\159\143\32\159\137\145\159\143\144\149\143\32\32\145\32\32\32\145\149\32\144\32\149\32\143\159\32\143\143\32\159\143\32", "\32\32\32\152\140\149\151\32\149\149\32\145\149\130\149\157\140\133\32\149\32\154\143\149\151\32\149\32\149\32\144\32\149\149\153\32\32\149\32\149\133\149\149\32\149\149\32\149", "\32\32\32\130\131\129\131\131\32\130\131\32\130\131\129\130\131\129\32\129\32\140\140\129\129\32\129\32\129\32\137\140\129\130\32\129\32\130\32\129\32\129\129\32\129\130\131\32", "\144\143\32\159\144\144\144\143\32\159\143\144\159\138\32\144\32\144\144\32\144\144\32\144\144\32\144\144\32\144\143\143\144\32\150\129\32\149\32\130\150\32\134\137\134\134\131\148", "\136\143\133\154\141\149\151\32\129\137\140\144\32\149\32\149\32\149\154\159\133\149\148\149\157\153\32\154\143\149\159\134\32\130\148\32\32\149\32\32\151\129\32\32\32\32\134\32", "\133\32\32\32\32\133\129\32\32\131\131\32\32\130\32\130\131\129\32\129\32\130\131\129\129\32\129\140\140\129\131\131\129\32\130\129\32\129\32\130\129\32\32\32\32\32\129\32", "\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32", "\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32", "\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32", "\32\32\32\32\145\32\159\139\32\151\131\132\155\143\132\134\135\145\32\149\32\158\140\129\130\130\32\152\147\155\157\134\32\32\144\144\32\32\32\32\32\32\152\131\155\131\131\129", "\32\32\32\32\149\32\149\32\145\148\131\32\149\32\149\140\157\132\32\148\32\137\155\149\32\32\32\149\154\149\137\142\32\153\153\32\131\131\149\131\131\129\149\135\145\32\32\32", "\32\32\32\32\129\32\130\135\32\131\131\129\134\131\132\32\129\32\32\129\32\131\131\32\32\32\32\130\131\129\32\32\32\32\129\129\32\32\32\32\32\32\130\131\129\32\32\32", "\150\150\32\32\148\32\134\32\32\132\32\32\134\32\32\144\32\144\150\151\149\32\32\32\32\32\32\145\32\32\152\140\144\144\144\32\133\151\129\133\151\129\132\151\129\32\145\32", "\130\129\32\131\151\129\141\32\32\142\32\32\32\32\32\149\32\149\130\149\149\32\143\32\32\32\32\142\132\32\154\143\133\157\153\132\151\150\148\151\158\132\151\150\148\144\130\148", "\32\32\32\140\140\132\32\32\32\32\32\32\32\32\32\151\131\32\32\129\129\32\32\32\32\134\32\32\32\32\32\32\32\129\129\32\129\32\129\129\130\129\129\32\129\130\131\32", "\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\150\151\129\150\131\132\140\143\144\143\141\145\137\140\148\141\141\144\157\142\32\159\140\32\151\134\32\157\141\32", "\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\151\151\32\154\143\132\157\140\32\157\140\32\157\140\32\157\140\32\32\149\32\32\149\32\32\149\32\32\149\32", "\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\131\129\32\134\32\131\131\129\131\131\129\131\131\129\131\131\129\130\131\32\130\131\32\130\131\32\130\131\32", "\151\131\148\152\137\145\155\140\144\152\142\145\153\140\132\153\137\32\154\142\144\155\159\132\150\156\148\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\136\32\151\140\132", "\151\32\149\151\155\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\152\137\144\157\129\149\149\32\149\149\32\149\149\32\149\149\32\149\130\150\32\32\157\129\149\32\149", "\131\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\129\32\130\131\32\133\131\32", "\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\159\159\144\152\140\144\156\143\32\159\141\129\153\140\132\157\141\32\130\145\32\32\147\32\136\153\32\130\146\32", "\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\149\157\134\154\143\132\157\140\133\157\140\133\157\140\133\157\140\133\32\149\32\32\149\32\32\149\32\32\149\32", "\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\130\131\32\134\32\130\131\129\130\131\129\130\131\129\130\131\129\32\129\32\32\129\32\32\129\32\32\129\32", "\159\134\144\137\137\32\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\32\132\32\159\143\32\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\138\32\146\130\144", "\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\131\147\129\138\134\149\149\32\149\149\32\149\149\32\149\149\32\149\154\143\149\32\157\129\154\143\149", "\130\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\129\130\131\129\130\131\129\130\131\129\140\140\129\130\131\32\140\140\129" }, {"000110000110110000110010101000000010000000100101", "000000110110000000000010101000000010000000100101", "000000000000000000000000000000000000000000000000", "100010110100000010000110110000010100000100000110", "000000110000000010110110000110000000000000110000", "000000000000000000000000000000000000000000000000", "000000110110000010000000100000100000000000000010", "000000000110110100010000000010000000000000000100", "000000000000000000000000000000000000000000000000", "010000000000100110000000000000000000000110010000", "000000000000000000000000000010000000010110000000", "000000000000000000000000000000000000000000000000", "011110110000000100100010110000000100000000000000", "000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000", "110000110110000000000000000000010100100010000000", "000010000000000000110110000000000100010010000000", "000000000000000000000000000000000000000000000000", "010110010110100110110110010000000100000110110110", "000000000000000000000110000000000110000000000000", "000000000000000000000000000000000000000000000000", "010100010110110000000000000000110000000010000000", "110110000000000000110000110110100000000010000000", "000000000000000000000000000000000000000000000000", "000100011111000100011111000100011111000100011111", "000000000000100100100100011011011011111111111111", "000000000000000000000000000000000000000000000000", "000100011111000100011111000100011111000100011111", "000000000000100100100100011011011011111111111111", "100100100100100100100100100100100100100100100100", "000000110100110110000010000011110000000000011000", "000000000100000000000010000011000110000000001000", "000000000000000000000000000000000000000000000000", "010000100100000000000000000100000000010010110000", "000000000000000000000000000000110110110110110000", "000000000000000000000000000000000000000000000000", "110110110110110110000000110110110110110110110110", "000000000000000000000110000000000000000000000000", "000000000000000000000000000000000000000000000000", "000000000000110110000110010000000000000000010010", "000010000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000", "110110110110110110110000110110110110000000000000", "000000000000000000000110000000000000000000000000", "000000000000000000000000000000000000000000000000", "110110110110110110110000110000000000000000010000", "000000000000000000000000100000000000000110000110", "000000000000000000000000000000000000000000000000" }} - ---### Genarate fonts using 3x3 chars per a character. (1 character is 6x9 pixels) -local fonts = {} -local firstFont = {} -do - local char = 0 - local height = #rawFont[1] - local length = #rawFont[1][1] - for i = 1, height, 3 do - for j = 1, length, 3 do - local thisChar = string.char(char) - - local temp = {} - temp[1] = rawFont[1][i]:sub(j, j + 2) - temp[2] = rawFont[1][i + 1]:sub(j, j + 2) - temp[3] = rawFont[1][i + 2]:sub(j, j + 2) - - local temp2 = {} - temp2[1] = rawFont[2][i]:sub(j, j + 2) - temp2[2] = rawFont[2][i + 1]:sub(j, j + 2) - temp2[3] = rawFont[2][i + 2]:sub(j, j + 2) - - firstFont[thisChar] = {temp, temp2} - char = char + 1 - end - end - fonts[1] = firstFont -end - -local function generateFontSize(size,yeld) - local inverter = {["0"] = "1", ["1"] = "0"} --:gsub("[01]",inverter) - if size<= #fonts then return true end - for f = #fonts+1, size do - --automagicly make bigger fonts using firstFont and fonts[f-1]. - local nextFont = {} - local lastFont = fonts[f - 1] - for char = 0, 255 do - local thisChar = string.char(char) - --sleep(0) print(f,thisChar) - - local temp = {} - local temp2 = {} - - local templateChar = lastFont[thisChar][1] - local templateBack = lastFont[thisChar][2] - for i = 1, #templateChar do - local line1, line2, line3, back1, back2, back3 = {}, {}, {}, {}, {}, {} - for j = 1, #templateChar[1] do - local currentChar = firstFont[templateChar[i]:sub(j, j)][1] - table.insert(line1, currentChar[1]) - table.insert(line2, currentChar[2]) - table.insert(line3, currentChar[3]) - - local currentBack = firstFont[templateChar[i]:sub(j, j)][2] - if templateBack[i]:sub(j, j) == "1" then - table.insert(back1, (currentBack[1]:gsub("[01]", inverter))) - table.insert(back2, (currentBack[2]:gsub("[01]", inverter))) - table.insert(back3, (currentBack[3]:gsub("[01]", inverter))) - else - table.insert(back1, currentBack[1]) - table.insert(back2, currentBack[2]) - table.insert(back3, currentBack[3]) - end - end - table.insert(temp, table.concat(line1)) - table.insert(temp, table.concat(line2)) - table.insert(temp, table.concat(line3)) - table.insert(temp2, table.concat(back1)) - table.insert(temp2, table.concat(back2)) - table.insert(temp2, table.concat(back3)) - end - - nextFont[thisChar] = {temp, temp2} - if yeld then yeld = "Font"..f.."Yeld"..char os.queueEvent(yeld) os.pullEvent(yeld) end - end - fonts[f] = nextFont - end - return true -end - -local function makeText(nSize, sString, nFC, nBC, bBlit) - if not type(sString) == "string" then error("Not a String",3) end --this should never happend with expects in place. - local cFC = type(nFC) == "string" and nFC:sub(1, 1) or tHex[nFC] or error("Wrong Front Color",3) - local cBC = type(nBC) == "string" and nBC:sub(1, 1) or tHex[nBC] or error("Wrong Back Color",3) - if(fonts[nSize]==nil)then generateFontSize(3,false) end - local font = fonts[nSize] or error("Wrong font size selected",3) - if sString == "" then return {{""}, {""}, {""}} end - - local input = {} - for i in sString:gmatch('.') do table.insert(input, i) end - - local tText = {} - local height = #font[input[1]][1] - - - for nLine = 1, height do - local outLine = {} - for i = 1, #input do - outLine[i] = font[input[i]] and font[input[i]][1][nLine] or "" - end - tText[nLine] = table.concat(outLine) - end - - local tFront = {} - local tBack = {} - local tFrontSub = {["0"] = cFC, ["1"] = cBC} - local tBackSub = {["0"] = cBC, ["1"] = cFC} - - for nLine = 1, height do - local front = {} - local back = {} - for i = 1, #input do - local template = font[input[i]] and font[input[i]][2][nLine] or "" - front[i] = template:gsub("[01]", bBlit and {["0"] = nFC:sub(i, i), ["1"] = nBC:sub(i, i)} or tFrontSub) - back[i] = template:gsub("[01]", bBlit and {["0"] = nBC:sub(i, i), ["1"] = nFC:sub(i, i)} or tBackSub) - end - tFront[nLine] = table.concat(front) - tBack[nLine] = table.concat(back) - end - - return {tText, tFront, tBack} -end - -return makeText \ No newline at end of file From 25701a75d971c0366d77af09a8cd534ef448e865 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:27:04 +0200 Subject: [PATCH 4/4] Delete layout.lua --- Basalt/libraries/layout.lua | 147 ------------------------------------ 1 file changed, 147 deletions(-) delete mode 100644 Basalt/libraries/layout.lua diff --git a/Basalt/libraries/layout.lua b/Basalt/libraries/layout.lua deleted file mode 100644 index ee29437..0000000 --- a/Basalt/libraries/layout.lua +++ /dev/null @@ -1,147 +0,0 @@ -local function newNode(name) - local node = {} - node.___value = nil - node.___name = name - node.___children = {} - node.___props = {} - - function node:value() return self.___value end - function node:setValue(val) self.___value = val end - function node:name() return self.___name end - function node:setName(name) self.___name = name end - function node:children() return self.___children end - function node:numChildren() return #self.___children end - function node:addChild(child) - if self[child:name()] ~= nil then - if type(self[child:name()].name) == "function" then - local tempTable = {} - table.insert(tempTable, self[child:name()]) - self[child:name()] = tempTable - end - table.insert(self[child:name()], child) - else - self[child:name()] = child - end - table.insert(self.___children, child) - end - - function node:properties() return self.___props end - function node:numProperties() return #self.___props end - function node:addProperty(name, value) - local lName = "@" .. name - if self[lName] ~= nil then - if type(self[lName]) == "string" then - local tempTable = {} - table.insert(tempTable, self[lName]) - self[lName] = tempTable - end - table.insert(self[lName], value) - else - self[lName] = value - end - table.insert(self.___props, { name = name, value = self[name] }) - end - - return node -end - -local XmlParser = {}; - -function XmlParser:ToXmlString(value) - value = string.gsub(value, "&", "&"); -- '&' -> "&" - value = string.gsub(value, "<", "<"); -- '<' -> "<" - value = string.gsub(value, ">", ">"); -- '>' -> ">" - value = string.gsub(value, "\"", """); -- '"' -> """ - value = string.gsub(value, "([^%w%&%;%p%\t% ])", - function(c) - return string.format("&#x%X;", string.byte(c)) - end); - return value; -end - -function XmlParser:FromXmlString(value) - value = string.gsub(value, "&#x([%x]+)%;", - function(h) - return string.char(tonumber(h, 16)) - end); - value = string.gsub(value, "&#([0-9]+)%;", - function(h) - return string.char(tonumber(h, 10)) - end); - value = string.gsub(value, """, "\""); - value = string.gsub(value, "'", "'"); - value = string.gsub(value, ">", ">"); - value = string.gsub(value, "<", "<"); - value = string.gsub(value, "&", "&"); - return value; -end - -function XmlParser:ParseArgs(node, s) - string.gsub(s, "(%w+)=([\"'])(.-)%2", function(w, _, a) - node:addProperty(w, self:FromXmlString(a)) - end) -end - -function XmlParser:ParseXmlText(xmlText) - local stack = {} - local top = newNode() - table.insert(stack, top) - local ni, c, label, xarg, empty - local i, j = 1, 1 - while true do - ni, j, c, label, xarg, empty = string.find(xmlText, "<(%/?)([%w_:]+)(.-)(%/?)>", i) - if not ni then break end - local text = string.sub(xmlText, i, ni - 1); - if not string.find(text, "^%s*$") then - local lVal = (top:value() or "") .. self:FromXmlString(text) - stack[#stack]:setValue(lVal) - end - if empty == "/" then -- empty element tag - local lNode = newNode(label) - self:ParseArgs(lNode, xarg) - top:addChild(lNode) - elseif c == "" then -- start tag - local lNode = newNode(label) - self:ParseArgs(lNode, xarg) - table.insert(stack, lNode) - top = lNode - else -- end tag - local toclose = table.remove(stack) -- remove top - - top = stack[#stack] - if #stack < 1 then - error("XmlParser: nothing to close with " .. label) - end - if toclose:name() ~= label then - error("XmlParser: trying to close " .. toclose.name .. " with " .. label) - end - top:addChild(toclose) - end - i = j + 1 - end - local text = string.sub(xmlText, i); - if #stack > 1 then - error("XmlParser: unclosed " .. stack[#stack]:name()) - end - return top -end - -function XmlParser:loadFile(xmlFilename, base) - if not base then - base = system.ResourceDirectory - end - - local path = system.pathForFile(xmlFilename, base) - local hFile, err = io.open(path, "r"); - - if hFile and not err then - local xmlText = hFile:read("*a"); -- read file content - io.close(hFile); - return self:ParseXmlText(xmlText), nil; - else - print(err) - return nil - end -end - -return XmlParser \ No newline at end of file