diff options
| author | Saikari <[email protected]> | 2026-02-01 14:40:44 +0300 |
|---|---|---|
| committer | Saikari <[email protected]> | 2026-02-01 14:40:44 +0300 |
| commit | 50b428269a657fd0adce1de35b01abe42c13708b (patch) | |
| tree | e98678a188667cfc0dfa488dcaf6ba56280e5692 /xmake/plugins/lua | |
| parent | 2b7c02a0ef930e394829027fab3d7acaa948d6e9 (diff) | |
refactor: enhance stdin handling by adding utf8 BOM removal and main function check
Diffstat (limited to 'xmake/plugins/lua')
| -rw-r--r-- | xmake/plugins/lua/main.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/xmake/plugins/lua/main.lua b/xmake/plugins/lua/main.lua index 0c0b44005..1cc13dbc3 100644 --- a/xmake/plugins/lua/main.lua +++ b/xmake/plugins/lua/main.lua @@ -63,6 +63,10 @@ function main() if script == "-" or from_stdin then local script_content = io.read("*a") if script_content then + -- remove utf8 bom + if script_content:startswith("\239\187\191") then + script_content = script_content:sub(4) + end import("core.base.tty") local shell = tty.shell() if shell == "cmd" or shell == "powershell" or shell == "pwsh" or os.host() == "windows" then @@ -72,7 +76,11 @@ function main() end script_content = script_content:replace("\\n", "\n", {plain = true}):replace("\\r", "\r", {plain = true}) end - script_content = "function main(...)\n" .. script_content .. "\nend" + + if not script_content:find("function main", 1, true) then + script_content = "function main(...)\n" .. script_content .. "\nend" + end + script = os.tmpfile() .. ".lua" io.writefile(script, script_content) script_file_to_remove = script |
