Advertisement
Yevano

breakfrom

Jan 3rd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. local top
  2.  
  3. function mklabel(name, func)
  4.     if not top then top = func end
  5.     local isTop = top == func
  6.     local suc, res = pcall(func)
  7.     if not suc then
  8.         if not res:find("__BREAKFROM") then error(res, -1) end
  9.         local target = res:gsub("[^\:]+:[^\:]+: __BREAKFROM", "")
  10.         if name ~= target then
  11.             if isTop then
  12.                 error("Tried to break from label '" .. target .. "' which does not exist.", 2)
  13.             end
  14.             error("__BREAKFROM" .. target)
  15.         end
  16.     end
  17.     if isTop then top = nil end
  18. end
  19.  
  20. function breakfrom(name)
  21.     error("__BREAKFROM" .. name)
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement