summaryrefslogtreecommitdiff
path: root/example/simple-example.lua
diff options
context:
space:
mode:
Diffstat (limited to 'example/simple-example.lua')
-rw-r--r--example/simple-example.lua48
1 files changed, 44 insertions, 4 deletions
diff --git a/example/simple-example.lua b/example/simple-example.lua
index 327167f..af19499 100644
--- a/example/simple-example.lua
+++ b/example/simple-example.lua
@@ -41,15 +41,55 @@ local mt = {
setmetatable(tab, mt)
+local function lprint(...)
+ local foo = {n=select("#",...),...}
+ if foo[1] then
+ print "Function ran OK:"
+ else
+ print "Error encountered:"
+ end
+ for i = 2, foo.n do
+ print(foo[i])
+ end
+ print()
+end
+
-- Finally, run the subcode
-print(supple.host.run(subcode, "@test-code", tab))
+lprint(supple.host.run(subcode, "@test-code", tab))
assert(tab.tot == 24)
-- Now run a supple command which we expect to error out.
-print(supple.host.run("unknown()", "@test-code"))
+lprint(supple.host.run("unknown()", "@test-code"))
-- And now, one where we pass an error from host to sandbox and back
-print(supple.host.run("local f = ... f()", "@test-code", function() unknown() end))
+lprint(supple.host.run("local f = ... f()", "@test-code", function() unknown() end))
-- And now, one where we pass an error from sandbox to host to sandbox and back
-print(supple.host.run("local f = ... f(function() unknown() end)", "@test-code", function(ff) ff() end))
+lprint(supple.host.run("local f = ... f(function() unknown() end)", "@test-code", function(ff) ff() end))
+
+-- And finally, a reasonable traceback via named functions on each end...
+
+local errsrc = [[
+ function raises()
+ does_not_exist()
+ end
+
+ function passes()
+ raises()
+ end
+
+ function chains(f)
+ f(passes)
+ end
+
+ local callme = ...
+
+ callme(chains)
+]]
+
+function loopback(f)
+ f(loopback)
+end
+
+lprint(supple.host.run(errsrc, "@error-code", loopback))
+