Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Development

Successfully merging this pull request may close these issues.

3 participants