New typeof() global function

We can go deeper… which actually prints string.

print(typeof(typeof(typeof)))
3 Likes

I will take credit for the name, glad you like it!

5 Likes

It matches JavaScript so I’m happy too :stuck_out_tongue:

4 Likes
print(typeof(newproxy(true)))

Currently this causes every client to lose connection (when ran server-side).

2 Likes

More generally, typeof(newproxy(true)) always causes a crash. gg.

I’ll make a bug report so someone sees it faster

1 Like

I had to turn this off due to the bug. I will fix the bug as soon as possible and then turn this on again.

1 Like

You can ignore this post if the bug caused issues that affected something outside of just the typeof function, but:

What’s the reasoning behind turning it off due to an obscure bug? newproxy isn’t commonly used in ROBLOX, so only a very narrow margin of cases would have actually been affected by this, if any at all (not counting people who were doing it to test).

What’s the difference from using a piece of code like while true do end compared to this? If they both have the same result (crashing the client or server) and they are both either programmer error or something that would probably never realistically happen, then I don’t see the benefit of turning this off.

A lot of things have bugs when they are released but I don’t think it’s really a good idea to just remove them after announcing them due to an obscure bug. I feel that in this case by removing the function you have probably broken or affected more code than would have been affected if you had just left it in its current state then hotfixed it a few days later.

But that’s just my two cents.

7 Likes

They probably don’t want something else to surface with the weekend coming up.

Rip all of Guardian’s code. It was using this :frowning:

Roblox still uses Lua 5.1 where newproxy is a thing. Also I think only newproxy is able to use __len. The primary use that comes to mind is making type return “userdata” instead of “table”.

2 Likes

what if I told you there was a 3rd thegamer101

2 Likes

3 of them? Illuminati confirmed?

Yeah, and the part about type(newproxy(true)) returning “userdata” is also true (and why it’s liked).
You can’t use rawget/rawset on userdata, so you can force people to (new)index, firing the metamethods.
Unlike the official Lua one, we can’t use newproxy(userdata) to get a userdata with the same metatable.
(which is to be expected, as newproxy(game) doesn’t seem very… good…)
Would be nice if we could use newproxy(newproxy(true)) to share one metatable between several stuff.
Seems cleaner than creating (and filling) a metatable for each newproxy instance you make.
(security risk? you can easily make your metamethods check stuff… not that security is a big issue)

1 Like

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 :stuck_out_tongue:

1 Like

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 :frowning:
[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.

12 Likes

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.

1 Like

That’s… pretty good right there. Smart.

1 Like

I have submitted a fix for the bug, so hopefully it will be back soon :slight_smile:

1 Like

… what. That’s clever.

1 Like