Names and data types Lua

Asked

Viewed 95 times

0

About names and data types in the Lua language. What is the maximum size of a name? Is the definition of Enumeration, Subrange, Registration and Union types allowed? I did not find this information in the documentation.

  • By "name" you mean variable/function name?

  • Yes, variable/class

1 answer

1


What is the maximum size of a name?

Lua does not have a maximum size for variable names. Internally, basically names are just strings.

Has the type Enumeration?

Today it still does not support enumerations by default. There are libraries that try to create something like moonlight, or you can also simply create a table:

local dias_da_semana = {
    ["SEGUNDA"] = 1,
    ["TERÇA"] = 2,
    -- ...
}

print(dias_da_semana.SEGUNDA) -- E então usar desta forma

But as expected, it will not have the same behavior as an enumeration of truth.

Has the type Subrange?

No, in language there’s nothing ready for that either.

Has the type Record?

Neither. The closest you’ll get is using the Tables, which can serve as dynamic records:

local registro = {
    x = 1,
    y = nil
}

Has the type Union

No! And I don’t think it makes much sense in a language with dynamic typing. v:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.