Skip to content

Add support for tagged userdata and userdata destructors#45

Merged
natecraddock merged 2 commits intonatecraddock:mainfrom
nurpax:userdata-dtor
Jan 12, 2024
Merged

Add support for tagged userdata and userdata destructors#45
natecraddock merged 2 commits intonatecraddock:mainfrom
nurpax:userdata-dtor

Conversation

@nurpax
Copy link
Contributor

@nurpax nurpax commented Jan 10, 2024

Luau doesn't support the usual metatable __gc method, instead userdatadtors should be used. There's more information available about these differences here:

luau-lang/luau#251 (comment)


Pushing patch for FYI and review. This is probably the last of my pending Ziglua changes that I think make the Luau support reasonably complete to be used in let's say a game engine.

@nurpax nurpax changed the title WIP: Add support for tagged userdata and userdata destructors Add support for tagged userdata and userdata destructors Jan 12, 2024
@nurpax
Copy link
Contributor Author

nurpax commented Jan 12, 2024

This patch is also ready for review @natecraddock.

Couple of notes:

  • CUserdataDtorFn -- this passes an anyopaque pointer to the dtor callback. Maybe there's a cleaner way to do that?
  • I mirrored a couple of api_check asserts from Luau into the Zig bindings. Reason? Hitting asserts on Luau side leads to really confusing errors at least on Windows. I expect giving an out of range tag index to be a probable mistake, so this is just to make diagnosing the mistake easier. OTOH, I don't want to make this return an error, since the original Luau API doesn't do that either, and IMO it's a little silly for the bindings to start doing extra error checking.

The functionality added by userdatadtor is IMO required functionality in the Luau version, as Luau doesn't support the usual Lua __gc metatable function.

@nurpax
Copy link
Contributor Author

nurpax commented Jan 12, 2024

I'll rebase since the other change went in

Luau doesn't support the usual metatable __gc method, instead
userdatadtors should be used.  There's more information
available about these differences here:

luau-lang/luau#251 (comment)
Copy link
Owner

@natecraddock natecraddock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for contributing! Just a couple of style things I pointed out

@natecraddock natecraddock merged commit 848190f into natecraddock:main Jan 12, 2024
@nurpax nurpax deleted the userdata-dtor branch January 17, 2024 16:34
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.

2 participants