diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-11-01 15:52:28 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-11-01 15:52:28 -0700 |
| commit | 8c7915e466e3bd8499c00fce6d6ffd2bebf310f5 (patch) | |
| tree | 95b2e03db3cb8fe15ea4689e3eb184abf45461aa /lib | |
| parent | b0072e6dcf3525365977cd4ba9f4f19c745fa16e (diff) | |
Added try/except.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/utils.nom | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/utils.nom b/lib/utils.nom index 13c7d49..c65ac2a 100644 --- a/lib/utils.nom +++ b/lib/utils.nom @@ -126,3 +126,25 @@ lua> ".." | nomsu:defmacro(name, function() return escape end, ""); | end; |end; + +compile [try %action and if it fails %fallback] to code: ".." + |do + | local _write_err = nomsu.write_err + | nomsu.write_err = function() end; + | local had_return = true; + | local ok, ret1, ret2 = pcall(function(nomsu, vars) + | local ret + | \(%action as lua statements) + | had_return = false; + | return ret; + | end, nomsu, vars); + | nomsu.write_err = _write_err; + | if not ok then + | \(%fallback as lua statements) + | elseif had_return then + | return ret1, ret2; + | else + | ret = ret1; + | end + |end + |
