summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-05 11:46:13 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-05 11:46:13 +0100
commit134978255ba674870f67d7a65a051a8edc73b131 (patch)
tree8c0cc5f6364f8595dd11ae97184468df4b1cd5f2
parentb8892dabfc998390722b1c347d4b25cf76b654ac (diff)
downloadsupple-134978255ba674870f67d7a65a051a8edc73b131.tar.gz
EXAMPLE: Show pairs, ipairs and next working, and allow lprint() to show simple tabular returns too
-rw-r--r--example/simple-example.lua48
1 files changed, 47 insertions, 1 deletions
diff --git a/example/simple-example.lua b/example/simple-example.lua
index c385474..a7ca3d4 100644
--- a/example/simple-example.lua
+++ b/example/simple-example.lua
@@ -49,7 +49,15 @@ local function lprint(...)
print "Error encountered:"
end
for i = 2, foo.n do
- print(foo[i])
+ if type(foo[i]) == "table" then
+ print("{")
+ for k, v in pairs(foo[i]) do
+ print("",k,v)
+ end
+ print("}")
+ else
+ print(foo[i])
+ end
end
print()
end
@@ -107,3 +115,41 @@ supple.host.set_limits { count = 100 }
lprint(supple.host.run(long_run, "@long-code"))
supple.host.set_limits { memory = 1000 }
lprint(supple.host.run(long_run, "@big-code"))
+
+
+-- next we demonstrate that ipairs works on proxied tables
+
+local summing = [[
+ local t = ...
+ local tot = 0
+ for i, v in ipairs(t) do
+ tot = tot + v
+ end
+ return tot
+]]
+
+lprint(supple.host.run(summing, "@summing", { 10, 14, 3 }))
+
+-- next we demonstrate that next works on proxied tables
+
+local isempty = [[
+ local t = ...
+ return next(t) == nil
+]]
+
+lprint(supple.host.run(isempty, "@isempty", {}))
+lprint(supple.host.run(isempty, "@isempty", {"bar"}))
+
+-- And now that pairs works on proxied tables
+
+local keys = [[
+ local t = ...
+ local ret = {}
+ for k, v in pairs(t) do
+ ret[#ret+1] = k
+ end
+ ret.ret = ret
+ return ret
+]]
+
+lprint(supple.host.run(keys, "@keys", { foo="bar", baz="meta" }))