Last active
December 31, 2015 23:29
-
-
Save shakesoda/8060243 to your computer and use it in GitHub Desktop.
shamelessly snagged from lua-l
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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