Skip to content

Instantly share code, notes, and snippets.

@shakesoda
Last active December 31, 2015 23:29
Show Gist options
  • Save shakesoda/8060243 to your computer and use it in GitHub Desktop.
Save shakesoda/8060243 to your computer and use it in GitHub Desktop.
shamelessly snagged from lua-l
return {
-- loadstring with function calls disabled. Useful for config files.
safe_load = function(data)
local f = assert(loadstring("return (" .. data .. ")"))
local count = 0
debug.sethook(function()
count = count + 1
if count >= 3 then
error "cannot call functions"
end
end, "c")
local ok, res = pcall(f)
count = 0
debug.sethook()
return ok, res
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment