From eb4ed34d7dfa5ce0e4cb0f24a3ec9c2115406b9e Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Wed, 4 Nov 2026 21:45:34 +0530 Subject: Make it a proper module and call main accordingly. --- mkelf | 2 +- mkelf.lua | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mkelf b/mkelf index 5285cc1..8d85489 100755 --- a/mkelf +++ b/mkelf @@ -1,3 +1,3 @@ #! /usr/bin/env lua -require("mkelf") +require("mkelf").main() diff --git a/mkelf.lua b/mkelf.lua index 2b8310f..2fcd207 100644 --- a/mkelf.lua +++ b/mkelf.lua @@ -86,7 +86,9 @@ local function loadconfig(fn) return state.header, state.segments, state.sections end -local function main() +local M = {} + +function M.main() local outfn = "a.out" local infn local i = 1 @@ -106,8 +108,8 @@ local function main() -- TODO check against headerOptions not normalized header. if header.phnum == 0 then header.phnum = #segments end if header.shnum == 0 then header.shnum = #sections end - local out = io.open(outfn, "wb") - if out == nil then die("failed to open %s", outfn) end + local out , err = io.open(outfn, "wb") + if out == nil then die("failed to open: %s", outfn, err) end out:write(elf.header.pack(header)) for _, segment in ipairs(segments) do out:write(elf.segment.pack(segment, header.data, header.class)) @@ -117,4 +119,4 @@ local function main() end end -main() +return M -- cgit v1.3