Math.type function not available un lua

Problem description

Hello.
The math.type function in lua doesn’t work.

Expected behavior

math.type(5) should return “integer”

Actual behavior

math.type(5) returns an error as if math.type function does not exist.

Steps to reproduce

Just create a lua repl and type math.type(5) in the command section.

Browser

Firefox

OS

Windows 11

Device if mobile

N/A

Plan

free tier

Is it possible that you need to import the math library? Try adding require "math" at the top of your code.

3 Likes

require “math” doesn’t solve the issue.
Moreover, other math functions are available even without writing require “math”.

Hi @MMartin2 Yes, I don’t think type is included in the math library for Lua in Replit. You can print out a list of what’s included:

for key, value in pairs(math) do
    print(key, value)
end

I’m not sure why it was excluded, but I’ll let the team know that you’re interested in seeing it; it would essentially be a feature enhancement request. Thanks so much.

2 Likes

Hello @MMartin2 Good news! The team decided to go ahead and update the Lua template, which will now include the math.type function. Happy coding!

print(math.type(5))
3 Likes

Hello.
That’s great news.
As of today it is still not working. math.type return nil

@MMartin2 Worked okay for me when I tested.


Maybe relogin or clear browser cache?

Relogged and cleared cache :

Try a new Repl? It probably won’t propagate to existing Repls.

1 Like

It works in a new Repl, thanks.

The console behaves differently though but that’s another topic.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.