From 6a5aada44bdd26d62d93de5310c81ad0d66f8bc9 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 29 Jul 2012 18:16:55 +0100 Subject: EXAMPLE: Simple example --- example/simple-example.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 example/simple-example.lua 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 +-- +-- 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) -- cgit v1.2.1