diff options
| author | Quentin Young <qlyoung@users.noreply.github.com> | 2021-08-02 13:51:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-02 13:51:35 +0000 |
| commit | 41d3d77496fb43df16c55c2c5834cdc3048f43d0 (patch) | |
| tree | 0ee0dcfb67330c179bb27e26eb0dd83d431468c9 /tests/lib/script1.lua | |
| parent | 08bbca7511959e1944f0d002dfcc71f51fcb777e (diff) | |
| parent | c5f9744c33df5a9d335691d73fbeb1ad8d0e58d4 (diff) | |
Merge pull request #8982 from dlqs/lua-func-stack
Diffstat (limited to 'tests/lib/script1.lua')
| -rw-r--r-- | tests/lib/script1.lua | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/lib/script1.lua b/tests/lib/script1.lua index e9ebc29bd9..6361c960a7 100644 --- a/tests/lib/script1.lua +++ b/tests/lib/script1.lua @@ -1 +1,54 @@ -a = a + b + +-- Positive testing + +function foo(a, b) + a = a + 1 + b = b + 1 + return { + a = a, + b = b, + } +end + +function bar(a, b) + a = a + 1 + b = b + 1 + c = 303 + return { + b = b, + c = c, + } +end + +function fact(n) + -- outer function must return a table + -- inner functions can be used to recurse or as helpers + function helper(m) + if m == 0 then + return 1 + else + return m * helper(m - 1) + end + end + return { + ans = helper(n) + } +end + +-- Negative testing + +function bad_return1() +end + +function bad_return2() + return 123 +end + +function bad_return3() + return {} +end + +function bad_return4() + error("Something bad!") +end + |
