Python1320

Untitled

Dec 6th, 2010
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. function check(variable, ...)
  2.     local name = debug.getinfo(2, "n").name
  3.     local func = debug.getinfo(2, "f").func
  4.     local types = {...}
  5.     local allowed = ""
  6.    
  7.     local matched = false
  8.    
  9.     for key, value in ipairs(types) do
  10.         if #types ~= key then
  11.             allowed = allowed .. value .. " or "
  12.         else
  13.             allowed = allowed .. value
  14.         end
  15.        
  16.         if type(variable) == value then
  17.             matched = true
  18.         end
  19.     end
  20.    
  21.     local arg = "???"
  22.    
  23.     for i=1, math.huge do
  24.         local key, value = debug.getlocal(2, i)
  25.         -- I'm not sure what to do about this part
  26.         if value == variable then
  27.             arg = i
  28.         break end
  29.     end
  30.    
  31.     if not matched then
  32.         error(("bad argument #%s to '%s' (%s expected, got %s)"):format(arg, name, allowed, type(typ)), 3)
  33.     end
  34. end
  35.  
  36. function Hello( str, entity, hello )
  37.     check(str, "string")
  38.     check(entity, "Entity")
  39.     check(hello, "Player", "Entity")
  40. end
  41.  
  42. Hello("hey", Entity(3), Entity(1))
Advertisement
Add Comment
Please, Sign In to add comment