From 4676bb3a05d89bb3c282da2ed8b2072e163093ff Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Sat, 24 Oct 2026 10:12:51 +0530 Subject: Multi return values instead of a table. --- mkelf.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mkelf.lua b/mkelf.lua index 3775956..6edeebb 100644 --- a/mkelf.lua +++ b/mkelf.lua @@ -11,9 +11,9 @@ local function usage() end ---@param fn string|nil ----@return {header: Header, sections: Section[], segments: Segment[]} +---@return Header, Segment[], Section[] local function loadconfig(fn) - local spec = {} + local header, segments, sections = {}, {}, {} local env = { -- Keep in sync with types/elf.d.lua Class = elf.Class, @@ -25,16 +25,16 @@ local function loadconfig(fn) SegmentFlags = elf.SegmentFlags, ELFVERSION = elf.VERSION, - header = function(t) spec.header = t end, - sections = function(t) spec.sections = t end, - segments = function(t) spec.segments = t end, + header = function(t) header = t end, + segments = function(t) segments = t end, + sections = function(t) sections = t end, } -- TODO error check for multiple headers local chunk, err = loadfile(fn, "t", env) if not chunk then die("%s", err) end local ok, perr = pcall(chunk) if not ok then die("%s", perr) end - return spec + return header, segments, sections end local function main() @@ -51,13 +51,13 @@ local function main() end i = i + 1 end - local c = loadconfig(infn) - c.header.phnum = #c.segments - c.header.phentsize = (c.header.class == ec.Class.bit64) and 0x38 or 0x20 + local header, segments, sections = loadconfig(infn) + header.phnum = #segments + header.phentsize = (header.class == ec.Class.bit64) and 0x38 or 0x20 -- TODO write to a temp file and atomic rename to outfn. local out = assert(io.open(outfn, "wb")) - out:write(elf.header.pack(c.header)) - out:write(elf.segment.pack(c.segments, c.header.data, c.header.class)) + out:write(elf.header.pack(header)) + out:write(elf.segment.pack(segments, header.data, header.class)) -- TODO finish section.pack -- out:write(elf.section.pack(c.sections, c.header.data)) end -- cgit v1.3