From da00d0b89c8e36f0e999241b34629cf3050e5e9a Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 8 Aug 2012 20:59:03 +0100 Subject: EXAMPLE: Add demonstration for supple.host.loadstring() --- example/simple-example.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/example/simple-example.lua b/example/simple-example.lua index a7ca3d4..1d82944 100644 --- a/example/simple-example.lua +++ b/example/simple-example.lua @@ -153,3 +153,19 @@ local keys = [[ ]] lprint(supple.host.run(keys, "@keys", { foo="bar", baz="meta" })) + +-- Next demonstrate that using supple.host.loadstring works to allow +-- globals set in the parent to be seen/changed + +local function loader(n) + return supple.host.loadstring(([[return { print=print, name = %q }]]):format(n), "@" .. n) +end + +local getname = [[ + local f = ... + local mod = (f("Jeff"))() + return mod.print and "PRINT" or mod.name +]] + +-- Expect to see 'PRINT' +lprint(supple.host.run(getname, "@getname", loader)) -- cgit v1.2.1