Here
is what LuaX
does to make scripts loadable with load:
function comment_shebang(script)
return script
: gsub("^#!.-\n(\x1b)", "%1") -- remove the whole shebang of compiled scripts
: gsub("^#!", "--") -- comment the shebang before loading the script
end
Just
call load(comment_shebang(script))
instead of load(script)
to load a script, ignoring the shebang and preserving the line
numbers.
Em qua., 27 de nov. de 2024 às 02:03, 'Sainan' via lua-l
Line numbering for debug info (e.g. raised exceptions) will be wrong
if load() itself doesn't handle this problem.
I think the sane approach to load Lua shell script as Lua string is
convert shebang #! to Lua's line comment "--#!".
We need to store additional information about that file string.
(And for shebang hack to work file needs "+x" executable attribute.
So we'll need to store "x" attr too.)