Created
October 9, 2013 02:50
-
-
Save snipsnipsnip/6895439 to your computer and use it in GitHub Desktop.
nyaos.filter.quote_eval: bash-like $() style quote for nyaos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- nyaos_filter_quote_eval.lua | |
-- bash風な逆クォートのカッコ版。ネスト可能。 | |
-- 「echo $(echo bar $(echo foo))」は「bar foo」と出力される。 | |
function nyaos.filter.quote_eval(cmdline) | |
return cmdline:gsub('%$(%b())', function(m) | |
local result, err = nyaos.eval(string.sub(m, 2, -2)) | |
if err then | |
print('error in substitution: '..err) | |
return false | |
else | |
return result:gsub('^%s+', ''):gsub('%s+$', '') | |
end | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment