Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function check(variable, ...)
- local name = debug.getinfo(2, "n").name
- local func = debug.getinfo(2, "f").func
- local types = {...}
- local allowed = ""
- local matched = false
- for key, value in ipairs(types) do
- if #types ~= key then
- allowed = allowed .. value .. " or "
- else
- allowed = allowed .. value
- end
- if type(variable) == value then
- matched = true
- end
- end
- local arg = "???"
- for i=1, math.huge do
- local key, value = debug.getlocal(2, i)
- -- I'm not sure what to do about this part
- if value == variable then
- arg = i
- break end
- end
- if not matched then
- error(("bad argument #%s to '%s' (%s expected, got %s)"):format(arg, name, allowed, type(typ)), 3)
- end
- end
- function Hello( str, entity, hello )
- check(str, "string")
- check(entity, "Entity")
- check(hello, "Player", "Entity")
- end
- Hello("hey", Entity(3), Entity(1))
Advertisement
Add Comment
Please, Sign In to add comment