diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-08 20:59:03 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-08-08 20:59:03 +0100 |
commit | da00d0b89c8e36f0e999241b34629cf3050e5e9a (patch) | |
tree | 52e34340ae43de714692cefe6796fddfbadda6b6 | |
parent | e71b67fdc40ef28e83378e0fa48e241c1ba9354d (diff) | |
download | supple-da00d0b89c8e36f0e999241b34629cf3050e5e9a.tar.gz |
EXAMPLE: Add demonstration for supple.host.loadstring()
-rw-r--r-- | example/simple-example.lua | 16 |
1 files changed, 16 insertions, 0 deletions
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)) |