-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex25.8.lua
More file actions
38 lines (32 loc) · 971 Bytes
/
ex25.8.lua
File metadata and controls
38 lines (32 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local debug = require "debug"
-- maximum "steps" that can be performed
local steplimit = 1000
local count = 0 -- counter for steps
-- set of authorized functions
local validfunc = {
[string.upper] = true,
[string.lower] = true,
[string.format] = true,
[string.gmatch] = true,
[table.insert] = true,
[assert] = true,
-- other authorized functions
}
local function hook (event)
if event == "call" then
local info = debug.getinfo(2, "fnS")
if not validfunc[info.func] and info.source ~= "@".. arg[1] and info.name ~= "for iterator" then
error("calling bad function: " .. (info.name or "?"))
end
end
count = count + 1
if count > steplimit then
error("script uses too much CPU")
end
end
-- load chunk
-- local f = assert(loadfile(arg[1], "t", {}))
local f = assert(loadfile(arg[1], "t"))
-- debug.sethook(hook, "", 100) -- set hook
debug.sethook(hook, "c") -- set hook
f() -- run chunk