Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support termination of errors by __close() #1

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

belm0
Copy link
Owner

@belm0 belm0 commented Oct 23, 2022

If a __close() metamethod was called with an error in flight, the error can be terminated by returning true.

See use cases.

This is a work in progress, and the implementation may not be robust.

example (not yet working):

do
  local x <close> = setmetatable({}, {
    __close = function(self, err)
      print('__close()')
      return true
    end
  })

  error('oops')
  print('not reached')
end

print('goodbye')
__close()
goodbye

TODO:

  • fix stack unwind not stopping at the to-be-closed level
  • documentation

@belm0 belm0 marked this pull request as draft October 23, 2022 15:11
@well-in-that-case
Copy link

Maybe I've misunderstood the rationale, but I feel like this is a patch skirting around try .. catch syntax. A TBC variable being able to enforce such authority over an entire block of code is uncanny.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants