diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a0ad5ed --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf + +[*.md] +indent_size = 4 + +[Makefile] +indent_style = tab + +[*.lua] +indent_size = 4 + diff --git a/.github/workflows/pr_check.yaml b/.github/workflows/pr_check.yaml new file mode 100644 index 0000000..1792cd6 --- /dev/null +++ b/.github/workflows/pr_check.yaml @@ -0,0 +1,15 @@ +on: + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Lua Linting + uses: lunarmodules/luacheck@v1 + with: + args: ./src + diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..206ca97 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,67 @@ +std = { + globals = { + "love", + "G", + "localize", + "generate_card_ui", + "UIBox_button", + "Moveable", + "Event", + "card_generate_uibox_ability_table", + "Card", + "ease_discard", + "ease_hands_played", + "ease_dollars", + "Back", + "Game", + "mods", + "LOGGERS", + "START_TIME", + "inject", + "injectHead", + "injectTail", + "os", + "UIBox", + "is_loaded", + "buildPaths", + "current_game_code", + "escaped_function_body", + "escaped_modified_function_code", + "original_testFunction", + "testFunction", + "error", + "select", + "rawget", + "loc_parse_string", + "create_playing_card", + "playing_card_joker_effects" + }, + read_globals = { + "string", + "math", + "pairs", + "ipairs", + "table", + "tonumber", + "tostring", + "setmetatable", + "getmetatable", + "next", + "type", + "assert", + "pcall", + "require", + "pseudorandom", + "pseudorandom_element", + "pseudoseed", + "create_option_cycle", + "create_badge", + "create_UIBox_generic_options", + "create_tabs", + "setfenv", + "load", + "getfenv" + } +} + +unused_args = false diff --git a/src/assets.lua b/src/assets.lua index 92bc82c..1327cff 100644 --- a/src/assets.lua +++ b/src/assets.lua @@ -23,7 +23,7 @@ local function getAtli(modId, textureScaling) local atliPath = "mods/" .. modId .. "/assets/textures/"..textureScaling.."x" local dir = love.filesystem.getDirectoryItems(atliPath) for i, path in ipairs(dir) do - local filename, extension = string.match(path, "([^/]+)%.(.+)$") + local filename, _ = string.match(path, "([^/]+)%.(.+)$") local name = modId .. "_" .. filename local image = love.graphics.newImage(atliPath.."/"..path, {mipmaps = true, dpiscale = textureScaling}) local assetType = assetTypes[string.match(filename, "(.+)_")] diff --git a/src/balamod.lua b/src/balamod.lua index 6412ad2..ce1d640 100644 --- a/src/balamod.lua +++ b/src/balamod.lua @@ -7,7 +7,7 @@ local utils = require('utils') local tar = require('tar') local https = require('https') -logger = logging.getLogger('balamod') +local logger = logging.getLogger('balamod') mods = {} local apis = { logging = logging, @@ -68,8 +68,7 @@ end local function request(url) logger:debug('Request made with url: ', url) - local code - local response + local code, response, headers code, response, headers = https.request(url, {headers = {['User-Agent'] = 'Balamod-Client'}}) if (code == 301 or code == 302) and headers.location then -- follow redirects if necessary @@ -764,7 +763,7 @@ mods["dev_console"] = { else G.consumeables:emplace(c1) end - + G.CONTROLLER:save_cardarea_focus('jokers') G.CONTROLLER:recall_cardarea_focus('jokers') return true @@ -1235,4 +1234,4 @@ return { toggleMod = toggleMod, sortMods = sortMods, callModCallbacksIfExists = callModCallbacksIfExists, -} \ No newline at end of file +} diff --git a/src/balamod_back.lua b/src/balamod_back.lua index c0be040..ac4dd3f 100644 --- a/src/balamod_back.lua +++ b/src/balamod_back.lua @@ -1,8 +1,8 @@ -local back_apply_to_run = back_apply_to_run or Back.apply_to_run +local back_apply_to_run = back_apply_to_run or Back.apply_to_run -- luacheck: ignore function Back:apply_to_run() if self.effect.config.cards then G.GAME.starting_params.cards = self.effect.config.cards end - back_apply_to_run(self) -end \ No newline at end of file + back_apply_to_run(self) -- luacheck: ignore +end diff --git a/src/balamod_card.lua b/src/balamod_card.lua index 48e37b4..218f8bc 100644 --- a/src/balamod_card.lua +++ b/src/balamod_card.lua @@ -1,23 +1,22 @@ local joker = require('joker') local seal = require('seal') -local assets = require('assets') local logging = require('logging') -local logger = logging.getLogger('card') +local logger = logging.getLogger('card') -- luacheck: ignore local consumable = require("consumable") -- references to original patched functions -local card_calculate_joker = card_calculate_joker or Card.calculate_joker -local card_generate_uibox_ability_table = card_generate_uibox_ability_table or Card.generate_UIBox_ability_table -local card_set_sprites = card_set_sprites or Card.set_sprites -local card_calculate_seal = card_calculate_seal or Card.calculate_seal -local card_get_end_of_round_effect = card_get_end_of_round_effect or Card.get_end_of_round_effect -local card_eval_card = eval_card -local card_open = card_open or Card.open -local card_calculate_dollar_bonus = Card.calculate_dollar_bonus -local card_add_to_deck = Card.add_to_deck -local card_remove_from_deck = Card.remove_from_deck -local card_use_consumeable = Card.use_consumeable -local card_can_use_consumeable = Card.can_use_consumeable +local card_calculate_joker = card_calculate_joker or Card.calculate_joker -- luacheck: ignore +local card_generate_uibox_ability_table = card_generate_uibox_ability_table or Card.generate_UIBox_ability_table -- luacheck: ignore +local card_set_sprites = card_set_sprites or Card.set_sprites -- luacheck: ignore +local card_calculate_seal = card_calculate_seal or Card.calculate_seal -- luacheck: ignore +local card_get_end_of_round_effect = card_get_end_of_round_effect or Card.get_end_of_round_effect -- luacheck: ignore +local card_eval_card = eval_card -- luacheck: ignore +local card_open = card_open or Card.open -- luacheck: ignore +local card_calculate_dollar_bonus = Card.calculate_dollar_bonus -- luacheck: ignore +local card_add_to_deck = Card.add_to_deck -- luacheck: ignore +local card_remove_from_deck = Card.remove_from_deck -- luacheck: ignore +local card_use_consumeable = Card.use_consumeable -- luacheck: ignore +local card_can_use_consumeable = Card.can_use_consumeable -- luacheck: ignore function Card:calculate_joker(context) diff --git a/src/balamod_game.lua b/src/balamod_game.lua index f390718..7f97ab5 100644 --- a/src/balamod_game.lua +++ b/src/balamod_game.lua @@ -3,8 +3,8 @@ local logging = require('logging') local logger = logging.getLogger('game') local balamod = require('balamod') -local game_set_render_settings = game_set_render_settings or Game.set_render_settings -local game_start_run = game_start_run or Game.start_run +local game_set_render_settings = game_set_render_settings or Game.set_render_settings -- luacheck: ignore +local game_start_run = game_start_run or Game.start_run -- luacheck: ignore function Game:set_render_settings() game_set_render_settings(self) diff --git a/src/balamod_love.lua b/src/balamod_love.lua index 7b40a3c..c20e4e8 100644 --- a/src/balamod_love.lua +++ b/src/balamod_love.lua @@ -6,8 +6,8 @@ local game_love_mousepressed = love.mousepressed local game_love_mousereleased = love.mousereleased local game_love_mousemoved = love.mousemoved local game_love_wheelmoved = love.wheelmoved -local game_love_textinput = love.textinput -local game_love_resize = love.resize +local game_love_textinput = love.textinput -- luacheck: ignore +local game_love_resize = love.resize -- luacheck: ignore local game_love_quit = love.quit local game_love_load = love.load local game_love_gamepad_pressed = love.gamepadpressed @@ -21,6 +21,8 @@ local utils = require('utils') local logger = logging.getLogger('love') local localization = require('localization') +local status, message + function love.load(args) local status, message = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_game_load", true, args) if not status then @@ -69,7 +71,7 @@ function love.update(dt) end end - local status, result = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_post_update", false, dt) + status, result = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_post_update", false, dt) if not status then logger:warn("Failed on_post_update for mods: ", result) end @@ -227,7 +229,14 @@ end function love.joystickaxis(joystick, axis, value) local cancel_event = false - local status, result = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_joystick_axis", false, joystick, axis, value) + local status, result = pcall( + balamod.callModCallbacksIfExists, + balamod.mods, "on_joystick_axis", + false, + joystick, + axis, + value + ) if not status then logger:warn("Failed on_joystick_axis for mods: ", result) else diff --git a/src/balamod_misc_functions.lua b/src/balamod_misc_functions.lua index a4df03d..3ad1d40 100644 --- a/src/balamod_misc_functions.lua +++ b/src/balamod_misc_functions.lua @@ -1,9 +1,8 @@ local localization = require('localization') local consumable = require("consumable") -local utils = require("utils") -local misc_functions_init_localization = misc_functions_init_localization or init_localization -local misc_generate_card_ui = generate_card_ui +local misc_functions_init_localization = misc_functions_init_localization or init_localization -- luacheck: ignore +local misc_generate_card_ui = generate_card_ui -- luacheck: ignore function init_localization() localization.inject() diff --git a/src/challenge.lua b/src/challenge.lua index bb9f8af..83b4d62 100644 --- a/src/challenge.lua +++ b/src/challenge.lua @@ -1,10 +1,9 @@ local _MODULE = {} _MODULE._VERSION = "1.0.0" -local balamod = require("balamod") local logging = require("logging") local logger = logging.getLogger("challenge") -local utils = require("utils") +-- local utils = require("utils") _MODULE.logger = logger local challenges = {} @@ -39,23 +38,23 @@ local allModifiers = { "hand_size", } -local function isIdInTable(id, theTable) - for _, value in ipairs(theTable) do - if value.id == id then - return true - end - end - return false -end +-- local function isIdInTable(id, theTable) +-- for _, value in ipairs(theTable) do +-- if value.id == id then +-- return true +-- end +-- end +-- return false +-- end -local function isValueForIdInTable(id, value, theTable) - for _, v in ipairs(theTable) do - if v.id == id and v.value == value then - return true - end - end - return false -end +-- local function isValueForIdInTable(id, value, theTable) +-- for _, v in ipairs(theTable) do +-- if v.id == id and v.value == value then +-- return true +-- end +-- end +-- return false +-- end local function validateChallengeId(challengeId) if challengeId == nil then diff --git a/src/deck.lua b/src/deck.lua index 89b0366..5b88356 100644 --- a/src/deck.lua +++ b/src/deck.lua @@ -2,7 +2,7 @@ local utils = require("utils") local logging = require("logging") -local logger = logging.getLogger("deck") +local logger = logging.getLogger("deck") -- luacheck: ignore local math = require("math") @@ -11,7 +11,7 @@ _MODULE._VERSION = "1.0.0" local decks = {} local GAME_BACKS = utils.copyTable(G.P_CENTER_POOLS.Back, true) -- copy the original table -local function getNextOrder() +local function getNextOrder() -- luacheck: ignore local latestOrder = utils.reduce( G.P_CENTER_POOLS.Back, function(acc, deck) @@ -24,7 +24,7 @@ end local function computeDeckOrders() local latestOrder = utils.reduce( - GAME_BACKS + GAME_BACKS, function(acc, deck) return math.max(acc, deck.order or 1) end, @@ -41,7 +41,12 @@ local function add(deck_id, deck) computeDeckOrders() G.P_CENTERS[deck_id] = decks[deck_id] table.insert(G.P_CENTER_POOLS.Back, deck) - table.sort(self.P_CENTER_POOLS["Back"], function (a, b) return (a.order - (a.unlocked and 100 or 0)) < (b.order - (b.unlocked and 100 or 0)) end) + table.sort( + self.P_CENTER_POOLS["Back"], + function (a, b) + return (a.order - (a.unlocked and 100 or 0)) < (b.order - (b.unlocked and 100 or 0)) + end + ) end local function remove(deck_id) diff --git a/src/joker.lua b/src/joker.lua index 1eb7581..965c164 100644 --- a/src/joker.lua +++ b/src/joker.lua @@ -1,4 +1,5 @@ -local balamod = require('balamod') +local logging = require('logging') +local logger = logging.getLogger('jokerAPI') local joker = {} joker._VERSION = "0.9.0" @@ -10,13 +11,13 @@ joker.removeFromDeckEffects = {} joker.loc_vars = {} local function add_joker(args) - if not args.mod_id then logger:error("jokerAPI: mod_id REQUIRED when adding a joker"); return; end + if not args.mod_id then logger:error("mod_id REQUIRED when adding a joker"); return; end local id = args.id or "j_Joker_Placeholder" .. #G.P_CENTER_POOLS["Joker"] + 1 local name = args.name or "Joker Placeholder" local calculate_joker_effect = args.calculate_joker_effect or function(_) end local order = #G.P_CENTER_POOLS["Joker"] + 1 - local unlocked = nil - local discovered = nil + local unlocked = nil -- luacheck: ignore + local discovered = nil -- luacheck: ignore if args.unlocked ~= nil then unlocked = args.unlocked else @@ -29,7 +30,7 @@ local function add_joker(args) end local cost = args.cost or 4 local pos = {x=0, y=0} - local effect = args.effect or "" + local effect = args.effect or "" -- luacheck: ignore local config = args.config or {} local desc = args.desc or {"Placeholder"} local rarity = args.rarity or 1 @@ -81,7 +82,14 @@ local function add_joker(args) G.P_CENTERS[id] = newJoker --add name + description to the localization object - local newJokerText = {name=name, text=desc, unlock=unlock_condition_desc, text_parsed={}, name_parsed={}, unlock_parsed={}} + local newJokerText = { + name=name, + text=desc, + unlock=unlock_condition_desc, + text_parsed={}, + name_parsed={}, + unlock_parsed={} + } for _, line in ipairs(desc) do newJokerText.text_parsed[#newJokerText.text_parsed+1] = loc_parse_string(line) end @@ -131,4 +139,4 @@ local _MODULE = joker _MODULE.add = add_joker _MODULE.remove = remove_joker -return _MODULE \ No newline at end of file +return _MODULE diff --git a/src/logging.lua b/src/logging.lua index 85b3d4e..234bfdc 100644 --- a/src/logging.lua +++ b/src/logging.lua @@ -10,6 +10,28 @@ local _MODULE = { LOGGERS = LOGGERS, } +local function addZeroForLessThan10(number) + if(number < 10) then + return 0 .. number + else + return number + end +end + +local function generateDateTime(start) + -- start is now in ms + -- need to round to seconds for an accurate date/time + start = math.floor(start or socket.gettime()) + local dateTimeTable = os.date('*t', start) + local dateTime = dateTimeTable.year .. "-" + .. addZeroForLessThan10(dateTimeTable.month) .. "-" + .. addZeroForLessThan10(dateTimeTable.day) .. "-" + .. addZeroForLessThan10(dateTimeTable.hour) .. "-" + .. addZeroForLessThan10(dateTimeTable.min) .. "-" + .. addZeroForLessThan10(dateTimeTable.sec) + return dateTime +end + local function createLogger(name, lvl) local log_levels = { TRACE = 10, @@ -40,14 +62,20 @@ local function createLogger(name, lvl) text=text, time=socket.gettime(), name=self.name, - formatted=function(self, dump) - if self.level == "PRINT" and not dump then - return self.text + formatted=function(msg, dump) + if msg.level == "PRINT" and not dump then + return msg.text end if dump then - return string.format("%s [%s] - %s :: %s", generateDateTime(self.time), self.name, self.level, self.text) + return string.format( + "%s [%s] - %s :: %s", + generateDateTime(msg.time), + msg.name, + msg.level, + msg.text + ) end - return string.format("[%s] - %s :: %s", self.name, self.level, self.text) + return string.format("[%s] - %s :: %s", msg.name, msg.level, msg.text) end, } table.insert(self.messages, message) @@ -96,29 +124,7 @@ local function getAllMessages() return messages end -function generateDateTime(start) - -- start is now in ms - -- need to round to seconds for an accurate date/time - start = math.floor(start or socket.gettime()) - local dateTimeTable = os.date('*t', start) - local dateTime = dateTimeTable.year .. "-" - .. addZeroForLessThan10(dateTimeTable.month) .. "-" - .. addZeroForLessThan10(dateTimeTable.day) .. "-" - .. addZeroForLessThan10(dateTimeTable.hour) .. "-" - .. addZeroForLessThan10(dateTimeTable.min) .. "-" - .. addZeroForLessThan10(dateTimeTable.sec) - return dateTime -end - -function addZeroForLessThan10(number) - if(number < 10) then - return 0 .. number - else - return number - end -end - -function saveLogs() +local function saveLogs() local filename = "logs/" .. generateDateTime() .. ".log" love.filesystem.write(filename, "") for _, message in ipairs(getAllMessages()) do diff --git a/src/mod_menu.lua b/src/mod_menu.lua index f5b7430..cb74a8b 100644 --- a/src/mod_menu.lua +++ b/src/mod_menu.lua @@ -1,6 +1,9 @@ local balamod = require('balamod') local utils = require('utils') +local mods_collection = {} +local mods_collection_size = 0 + G.FUNCS.open_balamod_website = function(e) love.system.openURL('https://balamod.github.io/') end @@ -45,7 +48,6 @@ G.FUNCS.install_mod = function(e) end G.UIDEF.mod_description = function(e) - local text_scale = 0.75 local status_btn_id = 's_btn_' .. e.config.id local menu_btn_id = 'm_btn_' .. e.config.id local dl_up_btn_id = 'd_btn_' .. e.config.id @@ -65,8 +67,12 @@ G.UIDEF.mod_description = function(e) local status_colour = mod.enabled and G.C.GREEN or G.C.RED local need_update = mod.needUpdate local new_version = need_update and 'New ' .. mod.newVersion or version - local show_download_btn = not mod_present or need_update - balamod.logger:debug('Mod: ', mod.name, ' present: ', mod_present, ' need update: ', need_update, ' new version: ', new_version) + balamod.logger:debug( + 'Mod: ', mod.name, + ' present: ', mod_present, + ' need update: ', need_update, + ' new version: ', new_version + ) local mod_description_text = {} for _, v in ipairs(mod.description) do mod_description_text[#mod_description_text + 1] = { @@ -193,7 +199,7 @@ G.FUNCS.change_mod_description = function(e) end end -G.UIDEF.mod_list_page = function(_page) +G.UIDEF.mod_list_page = function(_page) -- luacheck: ignore local snapped = false local mod_list = {} local i = 0 @@ -241,16 +247,16 @@ G.FUNCS.change_mod_list_page = function(args) end end -mods_collection = {} -mods_collection_size = 0 - local function create_mod_tab_definition() G.MOD_PAGE_SIZE = 7 mods_collection = {} mods_collection_size = 0 - logger:debug('Mods collection generation with mods', utils.map(balamod.mods, function(mod) return mod.id end)) + balamod.logger:debug( + 'Mods collection generation with mods', + utils.map(balamod.mods, function(mod) return mod.id end) + ) for mod_id, mod in pairs(balamod.mods) do - logger:trace('Trying to add mod ', mod_id, ' to collection') + balamod.logger:trace('Trying to add mod ', mod_id, ' to collection') if not mods_collection[mod_id] then mods_collection[mod_id] = mod mods_collection_size = mods_collection_size + 1 @@ -258,7 +264,7 @@ local function create_mod_tab_definition() balamod.logger:warn('Mod ' .. mod.name .. ' already in collection') end end - logger:debug('Mods collection before repoMods additions', utils.keys(mods_collection)) + balamod.logger:debug('Mods collection before repoMods additions', utils.keys(mods_collection)) for index, mod in ipairs(balamod.getRepoMods()) do local cur_mod = mods_collection[mod.id] if cur_mod == nil then diff --git a/src/patches.lua b/src/patches.lua index f6d7e87..e579355 100644 --- a/src/patches.lua +++ b/src/patches.lua @@ -14,15 +14,17 @@ for _, modFolder in ipairs(modFolders) do end end end -local status, sortedMods = pcall(balamod.sortMods, balamod.mods) +local status, sortedMods, message + +status, sortedMods = pcall(balamod.sortMods, balamod.mods) if not status then logger:warn("Failed to sort mods: ", sortedMods) else balamod.mods = sortedMods end -logger:info("Mods: ", utils.keys(mods)) -local status, message = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_pre_load", true) +logger:info("Mods: ", utils.keys(balamod.mods)) +status, message = pcall(balamod.callModCallbacksIfExists, balamod.mods, "on_pre_load", true) if not status then logger:warn("Failed to preload mods: ", message) end diff --git a/src/platform.lua b/src/platform.lua index d92dadd..02d6e60 100644 --- a/src/platform.lua +++ b/src/platform.lua @@ -1,4 +1,5 @@ -return { +local _MODULE = { + _VERSION = "0.1.0", is_mac = love.system.getOS() == "OS X", is_windows = love.system.getOS() == "Windows", is_linux = love.system.getOS() == "Linux", @@ -7,3 +8,35 @@ return { is_android = love.system.getOS() == "Android", is_ios = love.system.getOS() == "iOS", } + +--- Strip the path off a path+filename. +-- @param pathname string: A path+name, such as "/a/b/c" +-- or "\a\b\c". +-- @return string: The filename without its path, such as "c". +local function baseName(pathname) + assert(type(pathname) == "string") + + local base = pathname:match(".*[/\\]([^/\\]*)") + return base or pathname + end + + --- Strip the name off a path+filename. + -- @param pathname string: A path+name, such as "/a/b/c". + -- @return string: The filename without its path, such as "/a/b/". + -- For entries such as "/a/b/", "/a/" is returned. If there are + -- no directory separators in input, "" is returned. + local function dirName(pathname) + assert(type(pathname) == "string") + + return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or "" + end + + local function stripBaseDir(pathname) + return pathname:gsub("^[^/]*/", "") + end + +_MODULE.baseName = baseName +_MODULE.dirName = dirName +_MODULE.stripBaseDir = stripBaseDir + +return _MODULE diff --git a/src/seal.lua b/src/seal.lua index 1d76c70..98cd096 100644 --- a/src/seal.lua +++ b/src/seal.lua @@ -1,4 +1,3 @@ -local balamod = require('balamod') local logging = require('logging') local logger = logging.getLogger("seal") local seal = {} @@ -6,7 +5,6 @@ seal._VERSION = "0.1.0" seal.seals = {} seal.effects = {} seal.timings = {} -local first_mod = true local function setData(args) local generate_card_ui_ref = generate_card_ui @@ -86,7 +84,7 @@ local function setData(args) } full_UI_table.name = full_UI_table.name[1] end - elseif card_type == 'Booster' then + elseif card_type == 'Booster' then -- luacheck: ignore else full_UI_table.name = localize { @@ -207,7 +205,7 @@ local function setData(args) vars = {specific_vars.bonus_chips} } end - elseif _c.set == 'Enhanced' then + elseif _c.set == 'Enhanced' then if specific_vars and _c.name ~= 'Stone Card' and specific_vars.nominal_chips then localize{type = 'other', key = 'card_chips', nodes = desc_nodes, vars = {specific_vars.nominal_chips}} end @@ -315,7 +313,7 @@ local function setData(args) } end end - if first_pass and not (_c.set == 'Edition') and badges then + if first_pass and (_c.set ~= 'Edition') and badges then for k, v in ipairs(badges) do if v == 'foil' then info_queue[#info_queue + 1] = G.P_CENTERS['e_foil'] @@ -364,7 +362,7 @@ local function setData(args) end end --- Provided args: +-- Provided args: -- mod_id, color, description -- id = Seal name with no spaces, -- label = Seal name as you want it to appear in game, diff --git a/src/tar.lua b/src/tar.lua index dc2b1c9..bd396e0 100644 --- a/src/tar.lua +++ b/src/tar.lua @@ -10,34 +10,6 @@ local math = require('math') local tar = {} local blocksize = 512 -local byte = string.byte - - ---- Strip the path off a path+filename. --- @param pathname string: A path+name, such as "/a/b/c" --- or "\a\b\c". --- @return string: The filename without its path, such as "c". -local function base_name(pathname) - assert(type(pathname) == "string") - - local base = pathname:match(".*[/\\]([^/\\]*)") - return base or pathname -end - ---- Strip the name off a path+filename. --- @param pathname string: A path+name, such as "/a/b/c". --- @return string: The filename without its path, such as "/a/b/". --- For entries such as "/a/b/", "/a/" is returned. If there are --- no directory separators in input, "" is returned. -local function dir_name(pathname) - assert(type(pathname) == "string") - - return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or "" -end - -local function strip_base_dir(pathname) - return pathname:gsub("^[^/]*/", "") -end -- trim5 from http://lua-users.org/wiki/StringTrim local function trim(s) @@ -123,7 +95,7 @@ local function read_header_block(block) if header.version ~= "00" and header.version ~= " \0" then return false, "Unknown version "..header.version end - if not checksum_header(block) == header.chksum then + if checksum_header(block) ~= header.chksum then return false, "Failed header checksum" end return header @@ -151,7 +123,7 @@ function tar.unpack(data) local longName = nil local longLinkName = nil local unpackedData = {} - local block = "" + local block repeat -- iterate by blocks of 512 bytes over the data block = readBlock(ptr, i, blocksize) diff --git a/src/utils.lua b/src/utils.lua index e652db6..88fc0af 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -212,8 +212,8 @@ local function mergeTables(table1, table2, logger) if type(v) == "table" and type(result[k]) == "table" then -- both are tables so we recurse, but first, we need to check -- whether it's an "array" table or a "dict" table - local isDictTable = all(map(keys(result), function(k) - return type(k) ~= "number" + local isDictTable = all(map(keys(result), function(key) + return type(key) ~= "number" end)) if isDictTable then result[k] = mergeTables(result[k], v, logger)