diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-29 18:16:55 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-07-29 18:16:55 +0100 |
commit | 6a5aada44bdd26d62d93de5310c81ad0d66f8bc9 (patch) | |
tree | f3e27c3d4cb80c3aef0540963b56016dad409d98 | |
parent | c9ec1fc955887b4c5eccdb62a250cd994b84abdd (diff) | |
download | supple-6a5aada44bdd26d62d93de5310c81ad0d66f8bc9.tar.gz |
EXAMPLE: Simple example
-rw-r--r-- | example/simple-example.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/example/simple-example.lua b/example/simple-example.lua new file mode 100644 index 0000000..33f62e8 --- /dev/null +++ b/example/simple-example.lua @@ -0,0 +1,46 @@ +-- example/simple-example.lua +-- +-- Sandbox (for) Untrusted Procedure Partitioning (in) Lua Engine +-- +-- Simple example +-- +-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org> +-- +-- For licence terms, see COPYING +-- + +supple = require'supple' + +-- Code string to run in the untrusted environment +subcode = [[ +local t = ... +local tot = 0 +for i = 1, #t do + tot = tot + t[i]() +end +t.tot = tot +return tot, -t +]] + +-- Generate a function to return 'n' +local function give_n(n) + return function() return n end +end + +-- A useful table for the test +local tab = { + give_n(4), + give_n(8), + give_n(12), +} + +-- A metatable which defines -tab to equal 'JEFF' +local mt = { + __unm = function () return "JEFF" end +} + +setmetatable(tab, mt) + +-- Finally, run the subcode +print(supple.host.run(subcode, "@test-code", tab)) +assert(tab.tot == 24) |