blob: 33f62e8ac7dd9ed659fb27b4ae639091ff102d4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
|