summaryrefslogtreecommitdiff
path: root/xmake/plugins/lua
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-02-01 14:06:52 +0300
committerSaikari <[email protected]>2026-02-01 14:07:06 +0300
commit554f7a23f12ba4df73c23de64d52855e82a37088 (patch)
tree0cafd2a51d185c7719977bfc439b399be75ec7e4 /xmake/plugins/lua
parent9fce99ffc77bdd8c77cb0e3d4c129eaa012246f1 (diff)
refactor: improve stdin handling and shell command execution across platforms
Diffstat (limited to 'xmake/plugins/lua')
-rw-r--r--xmake/plugins/lua/main.lua26
-rw-r--r--xmake/plugins/lua/xmake.lua20
2 files changed, 30 insertions, 16 deletions
diff --git a/xmake/plugins/lua/main.lua b/xmake/plugins/lua/main.lua
index 0a608b10a..a945a64c1 100644
--- a/xmake/plugins/lua/main.lua
+++ b/xmake/plugins/lua/main.lua
@@ -55,15 +55,26 @@ function main()
-- run script
local script = option.get("script")
local arguments = option.get("arguments")
- local from_stdin = option.get("from_stdin") or option.get("from-stdin")
+ local from_stdin = option.get("stdin")
if script or from_stdin then
-- run script from stdin?
- local script_content
+ local script_file_to_remove
if script == "-" or from_stdin then
- script_content = io.read("*a")
- if not script or script == "-" then
- script = "xmake_lua_stdin"
+ local script_content = io.read("*a")
+ if script_content then
+ import("core.base.tty")
+ local shell = tty.shell()
+ if shell == "cmd" or shell == "powershell" or shell == "pwsh" or os.host() == "windows" then
+ script_content = script_content:trim()
+ if script_content:startswith('"') and script_content:endswith('"') then
+ script_content = script_content:sub(2, -2)
+ end
+ script_content = script_content:replace("\\n", "\n", {plain = true}):replace("\\r", "\r", {plain = true})
+ end
+ script = os.tmpfile() .. ".lua"
+ io.writefile(script, script_content)
+ script_file_to_remove = script
end
end
@@ -74,8 +85,11 @@ function main()
diagnosis = option.get("diagnosis"),
command = option.get("command"),
arguments = arguments,
- content = script_content,
deserialize = option.get("deserialize")})
+
+ if script_file_to_remove then
+ os.tryrm(script_file_to_remove)
+ end
end
else
-- enter interactive mode
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index 467cde3f1..8b60c96d3 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -45,20 +45,20 @@ task("lua")
{'l', "list" , "k" , nil , "List all scripts." }
, {'c', "command" , "k" , nil , "Run script as command" }
, {'d', "deserialize" , "kv" , nil , "Deserialize arguments starts with given prefix" }
- , {nil, "from-stdin" , "k" , nil , "Run script from stdin",
+ , {nil, "stdin" , "k" , nil , "Run script from stdin",
"e.g.",
" - CMD",
- " - Single: echo print(\"hello\") | xmake lua --from-stdin",
- " - Multiline: (echo print('1') && echo print('2')) | xmake lua --from-stdin",
- " - File: type script.lua | xmake lua --from-stdin",
+ " - Single: echo print(\"hello\") | xmake lua --stdin",
+ " - Multiline: (echo print('1') && echo print('2')) | xmake lua --stdin",
+ " - File: type script.lua | xmake lua --stdin",
" - PWSH",
- " - Single: Write-Output 'print(\"hello\")' | xmake lua --from-stdin",
- " - Multiline: Write-Output \"print('1')`nprint('2')\" | xmake lua --from-stdin",
- " - File: Get-Content script.lua | xmake lua --from-stdin",
+ " - Single: Write-Output 'print(\"hello\")' | xmake lua --stdin",
+ " - Multiline: Write-Output \"print('1')`nprint('2')\" | xmake lua --stdin",
+ " - File: Get-Content script.lua | xmake lua --stdin",
" - SH",
- " - Single: echo 'print(\"hello\")' | xmake lua --from-stdin",
- " - Multiline: (echo 'print(\"1\")'; echo 'print(\"2\")') | xmake lua --from-stdin",
- " - File: cat script.lua | xmake lua --from-stdin"
+ " - Single: echo 'print(\"hello\")' | xmake lua --stdin",
+ " - Multiline: (echo 'print(\"1\")'; echo 'print(\"2\")') | xmake lua --stdin",
+ " - File: cat script.lua | xmake lua --stdin"
}
, {nil, "script" , "v" , nil , "Run the given lua script name, file or module and enter interactive mode if no given script.",
"e.g.",