It's what the most popular languages out there use. It simply casts it to an int32 before doing the operationĬontinue is very much necessary in loops like this, unless you want some deeply nested code:Ħ. Javascript has bitwise operators even though it only has doubles. I would argue that ++x and x += aren't that hard to grasp.Ĥ. Using "it's easier for new users" is not a good argument for a good programming language. How can a language offer such a bad support for its most important datastructure? Another one is that there's no function to copy a hashtable (neither for shallow nor for deep copies). The lack of round() is symptomatic of Lua's standard library, it's not a singular example. > I don't think a core library's choice should be an argument to judge the whole language I have read those implementations and they are all unsatisfying:ġ) The "minimalism" argument: How is that consistent with the existence of g() and math.rad()? Both are easier to manually implement and less rarely used than round().Ģ) The "ease of implementation" argument: The C standard library actually provides a round() function, so binding it would be negligible in terms of both resources and implementation effort. > I guess the lack of round function is surprising too, but the explanations I see online about it being a minimalism and ease of implementation make sense. > But I don't understand the original comment's point.ġ) A minimalistic scripting language is appropriate for a few niches only, therefore Lua would be a bad replacement for Python in most cases.Ģ) Missing basic functionality (e.g., printing the contents of the language's fundamental datastructure) decreases productivity, the one thing which scripting languages are supposed to excel at.ģ) Pressing arrays into hashtables-as-arrays-but-not-really is a very bad, unnecessary design decision with few upsides and many downsides. Lua will just print the address of the hashtable, which is completely useless if you want to see its contents. How is that more important than round()?!
But it does have functions to convert degrees to radians and back. Similarly, you might get an array argument from a caller, check its length (4 elements), append a single value, and suddenly your array has 10 elements, instead of 5! That's terrible design. That's because the first nil in a hashtable demarks the end of an array. In the end, you have to treat arrays and hashtables differently (see, e.g., pairs() and ipairs()), because – big surprise – arrays and hashtables are very different conceptually, so you don't gain much from unifying them.Īlso great is that if you set element #5 in a 10-element array to nil (maybe you write foo = arg1, and arg1 comes from a caller), your array suddenly only has 4 elements. Sure, as an embedded scripting language in very small, resource-constrained devices this is a good strategy, but that's a niche application.Įven worse is the "arrays are hashtables in disguise" concept, because even though it might appear to be elegant, it doesn't work well in practice. What good is a scripting language where I have to either implement every utility function myself, or look for and include an external library? Lua does not even have a round() function! You can't just write print(some_table), which makes using the REPL needlessly burdensome. The number one benefit you should get from a scripting language as opposed to a compiled one is higher productivity – otherwise, you could just write it in C and have higher performance and lower resource usage.
Let's visit this passage from section 13.1.18.Thank goodness it didn't. It shifts up any other integer keys above the index: It shifts up any other integer keys above the index: > t = print (Table [Test.
table.insert takes an optional index parameter to insert into the middle of an array.Home Lua table insert with key lua-users wiki: Tables Tutoria