Setting the environment explicitly works, but that doesn't really help
me write the tighter syntax that I want.
For instance, this does allow me to use the syntax I want:
function getEnv()
local env = {}
local i = 1
while true do
local localVar, value = debug.getlocal(3, i)
if localVar ~= nil then
env[localVar] = value
else
break
end
i = i + 1
end
setmetatable(env, {__index = _G})
return env
end
function eval(s)
local f = assert(loadstring(s))
setfenv(f, getEnv())
f()
end
function flarp()
local myLocal = "hello"
eval[[print(myLocal)]]
end
flarp()
(prints hello)
... but it uses the debug library and has a nice fat function call
overhead.