mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update function-newproxy-table-support
This commit is contained in:
parent
563c05e48f
commit
2b63d682d4
1 changed files with 9 additions and 5 deletions
|
@ -6,15 +6,19 @@ Introduce a new way of creating `userdata` objects from Luau with an existing me
|
|||
|
||||
## 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.
|
||||
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.
|
||||
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
|
||||
Allow `newproxy` to be called with a table or nil instead of a boolean.
|
||||
- When it is called with a table, the newly constructed userdata will have that table assigned as its metatable.
|
||||
- When it is called with nil, the newly constructed userdata will have no metatable.
|
||||
|
||||
Passing a boolean to `newproxy` will continue to be supported for backwards compatability but is not recommended over the proposed behavior.
|
||||
|
||||
## Drawbacks
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue