Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…unctions with util.memoized_loadstring
  • Loading branch information...
commit dd5d5dfb55b2edb64fc6ae8d97faa99bb09d278c 1 parent d3f0d62
@jspahrsummers authored
Showing with 6 additions and 1 deletion.
  1. +6 −1 pure.lua
View
7 pure.lua
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.