From 563c05e48f965370d863894d811f1c06ba480b4f Mon Sep 17 00:00:00 2001 From: Brad Sharp Date: Mon, 9 Jan 2023 10:02:59 -0800 Subject: [PATCH] Create function-newproxy-table-support --- rfcs/function-newproxy-table-support | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 rfcs/function-newproxy-table-support diff --git a/rfcs/function-newproxy-table-support b/rfcs/function-newproxy-table-support new file mode 100644 index 00000000..e108e936 --- /dev/null +++ b/rfcs/function-newproxy-table-support @@ -0,0 +1,25 @@ +# Support table as first argument to newproxy + +## Summary + +Introduce a new way of creating `userdata` objects from Luau with an existing metatable. + +## Motivation + +Since Luau is derived from Lua 5.1 it retains the `newproxy` function used to create custom `userdata` objects from Lua. While this function is used by a number of libraries it has its limitations. + +The `newproxy` function accepts a single, boolean parameter which specifies if the newly created `userdata` should be initialized with a metatable or not. If the `userdata` is initialized with a metatable then it can be retrieved and edited by calling `getmetatable`. Unfortunately, this means that a `userdata` created through `newproxy` cannot share a metatable with another `userdata`. There are two main implications of this: +- Memory - A `userdata` with a metatable has the same cost as a table with a metatable. +- Usability - `userdata` with the same 'type' do not have the same metatable. + +## Design + +TODO + +## Drawbacks + +TODO: It will increase the usage of newproxy which may not be desirable. + +## Alternatives + +TODO: New method entirely - add more support for userdata