You can create custom Userdata with newproxy(), sadly information on this is sparse, so I can't figure out how to edit the Userdata. I vaguely remember something about getmetatable, but nothing specific.
#Any ideas?
You can create custom Userdata with newproxy(), sadly information on this is sparse, so I can't figure out how to edit the Userdata. I vaguely remember something about getmetatable, but nothing specific.
#Any ideas?
No there is no use for "newproxy(false)", "newproxy(true)" attaches metatable to the userdata but that's it, there is no information on that because "newproxy" was removed in Lua 5.2+ or somewhere around this version, there was not even a documentation on this function. "newproxy(true)" itself is kind of useless because of Roblox framework, but it's not that bad if you think about it.
So i won't talk about "newproxy(false)" anymore, you know it's garbage, if you don't trust me, Ellyzia said so, so you know it's true.
Now about the "newproxy(true)", i did not say it's absolute garbage, that's because if you use some metamethods you can make custom enum for example, you can make same with table and that's why it's not so usefull. The only use is the __len metatmethod for the # operator, here is my poor example of my Enum where __len returns total amount of Enums:
local Enum = newproxy(true) do
local EnumMetatable = getmetatable(Enum)
EnumMetatable.WoodType = {
HighQuality = 1,
BadQuality = 2,
}
EnumMetatable.__index = EnumMetatable
function EnumMetatable.NewEnum(Name, Values)
EnumMetatable[Name] = Values
end
function EnumMetatable:__newindex()
error("Cannot edit Enum", 2)
end
function EnumMetatable:__len()
local Total = 0
for Key, Value in next, EnumMetatable do
if type(Value) == "table" and Key ~= "__index" then
Total += 1
end
end
return Total
end
end
-- Enum.WoodType = nil -- Uncomment to get error
print(Enum.WoodType.HighQuality)
Enum.NewEnum("CarType", {
Good = 1,
Bad = 2,
})
print(Enum.CarType.Good)
print(#Enum)
Output: 1 1 2
Here you see i made properties uneditable but again, same possible with tables. And i of course i ain't sure but i think userdata takes less memory than tables.
This discussion is preserved as it was. New answers, comments, and votes are closed.