Permalink
Browse files

Allow string arguments to pure.sandbox, which will be compiled into f…

…unctions with util.memoized_loadstring
  • Loading branch information...
jspahrsummers committed Oct 10, 2011
1 parent d3f0d62 commit dd5d5dfb55b2edb64fc6ae8d97faa99bb09d278c
Showing with 6 additions and 1 deletion.
  1. +6 −1 pure.lua
View
@@ -115,7 +115,8 @@ local pure_env_locked = false
-- Save global environment
local global_env = _G
--- Returns 'func' sandboxed to only have access to pure functions and constants
+-- Returns 'func' sandboxed to only have access to pure functions and constants.
+-- 'func' may also be a string to compile into a pure function.
function pure.sandbox (func)
if not pure_env_locked then
-- Lock out modifications in the pure environment
@@ -125,6 +126,10 @@ function pure.sandbox (func)
pure_env_locked = true
end
+
+ if type(func) == "string" then
+ func = util.memoized_loadstring(func)
+ end
return util.memoize(func, pure_env)
end

0 comments on commit dd5d5df

Please sign in to comment.