half-life 3 confirmed
Can’t use rawset/rawget on Userdata, meaning you can make a secure sandbox of the global environment. Useful for stuff like Script Builders, which is admittedly a very narrow use case.
The major reason is: Lua 5.1 has it naturally, and there is zero reason to remove it, as it poses no security or functionality concern.
When is this coming back? I have a very important use case for detecting instances, and hate causing errors to find the actual type
Until TheGamer101 is able to fix the bug, have this nice alternative hack:
-- Environment Localization
local type = type
local pcall = pcall
local string_dump = string.dump
local string_find = string.find
local string_match = string.match
-- string Utilities.TypeOf(anyvalue Anyvalue)
-- Returns the type of its only argument, coded as a string. Includes support for ROBLOX types.
function TypeOf(Anyvalue)
local AnyvalueType = type(Anyvalue)
local Ran, Error = pcall(string.dump, Anyvalue)
if not (Ran) then
if (string.find(Error, "got (%w+)")) then
AnyvalueType = string.match(Error, "got (%w+)")
end
end
if not (AnyvalueType) then
AnyvalueType = type(AnyvalueType)
end
if (AnyvalueType == "Object") then
AnyvalueType = "Instance"
end
return AnyvalueType
end
Should work just like typeof, except hacky
[102216] below showed me a stupid. i fixed my stupid. 100% works
[102216a] changed function name to “typeof” so it makes more sense
[102316] realized another flaw in my function. if the passed argument was an “function”, the result would have been nil as string.dump only accepts functions. #fixedtho (also fixed formatting)
[102416] why am i making a changelog for this?
[102416a] fixed not returning “function” for calling typeof(Instance.GetFullName) functions. aka, wasn’t handling “C Lua Functions” correctly
[102416b] due to its rather slow nature, i optimized it a bit. it will also switch over to the real “typeof” when released once again.
[102416c] rip forgot typeof compatibility again. also, it seems you can only do so much with formatting. god it looks ugly here
[102416d] fixed a grammar error in post. why am i noting this.
[102516] i rewrote it again. last time i doing it. this one works and works well, and i gotta stop this madness.
Why do you use the same identifier for the function name and a variable in your code? It obfuscates your code because I have to read your entire code to understand that ‘return Type’ is not returning the function itself but rather a variable. Just call the function “typeof”, then the change later on just means you have to delete some code.
That’s… pretty good right there. Smart.
I have submitted a fix for the bug, so hopefully it will be back soon
… what. That’s clever.
Yeah, this is basically the best ROBLOX update in a long time. I just wish it would be un-broken sooner so I can make serialization not lag.
that’s really smart.
I tried implementing your hack differently and the result is pretty small.
local typeof = getfenv(0).typeof -- keeps intellisense from flipping out
if not typeof then
local type = type
local pcall = pcall
local string_dump = string.dump
local string_sub = string.sub
function typeof(val)
local rtype = type(val)
if rtype == 'userdata' then
local _, err = pcall(string_dump, val)
rtype = string_sub(err, 48, -2)
if rtype == 'Object' then
return 'Instance'
end
end
return rtype
end
end
yea … There’s bound to be better ways than mine (aka yours)
This should improve your code’s performance and also prevent warnings (without getfenv)
typeof = typeof
if not typeof then
local type = type
local pcall = pcall
local string_dump = string.dump
local string_sub = string.sub
local lookup = setmetatable({}, {
__index = function(lookup, result)
local rtype = string_sub(result, 48, -2)
rtype = (rtype == 'Object' and 'Instance') or rtype
lookup[result] = rtype
return rtype
end
})
function typeof(val)
local rtype = type(val)
if rtype ~= 'userdata' then
return rtype
end
local _, result = pcall(string_dump, val)
return lookup[result]
end
end
Even when new API’s are added, some people still manage to play using outdated clients
Nice! I forgot about negative string indices.
Only reason the getfenv was there was to get around writing typeof=typeof so that intellisense doesn’t complain.
I mean:
local typeof = typeof -- complains
typeof = typeof -- doesn't complain
Whoa, really? That’s a pretty old change by now. I wonder if there’s not some bug in loading the flag that enables it.
If you try to start studio offline the request for the flag list will time out and all the flags will just maintain their default states. Maybe this can happen on the client too on sufficiently slow connections.
This is now live once again, sorry for any inconvenience.
Aaaay! No more string.dump hacks
Great idea