From a89680fe48dd1520843d7629e2006f732e313200 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 28 Jul 2023 15:54:12 +0800 Subject: made a little optimization for try-catch syntax. --- spec/inputs/try_catch.yue | 6 ++++++ spec/outputs/5.1/try_catch.lua | 4 ++++ spec/outputs/try_catch.lua | 16 ++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'spec') diff --git a/spec/inputs/try_catch.yue b/spec/inputs/try_catch.yue index e38cbef..96a87fc 100644 --- a/spec/inputs/try_catch.yue +++ b/spec/inputs/try_catch.yue @@ -50,5 +50,11 @@ do catch err print err +do + try + func 1, 2, 3 + + try func 1, 2, 3 + nil diff --git a/spec/outputs/5.1/try_catch.lua b/spec/outputs/5.1/try_catch.lua index 577df16..9972dca 100644 --- a/spec/outputs/5.1/try_catch.lua +++ b/spec/outputs/5.1/try_catch.lua @@ -68,4 +68,8 @@ do print(result) end end +do +pcall(func, 1, 2, 3) +pcall(func, 1, 2, 3) +end return nil diff --git a/spec/outputs/try_catch.lua b/spec/outputs/try_catch.lua index 129d412..de52c6c 100644 --- a/spec/outputs/try_catch.lua +++ b/spec/outputs/try_catch.lua @@ -1,8 +1,6 @@ -xpcall(function() - return func(1, 2, 3) -end, function(err) +xpcall(func, function(err) return print(err) -end) +end, 1, 2, 3) xpcall(func, function(err) return print(err) end, 1, 2, 3) @@ -11,11 +9,9 @@ pcall(function() return func(1, 2, 3) end) do - local success, result = xpcall(function() - return func(1, 2, 3) - end, function(err) + local success, result = xpcall(func, function(err) return print(err) - end) + end, 1, 2, 3) success, result = pcall(func, 1, 2, 3) end pcall(tb.func) @@ -58,4 +54,8 @@ do print(result) end end +do +pcall(func, 1, 2, 3) +pcall(func, 1, 2, 3) +end return nil -- cgit v1.2.3-55-g6feb