hgr7pt4j.png
[Hide] (523KB, 452x790) I don't know how anyone can tolerate Lua. The only good things about it are looping with pairs(), and the fact that you can format strings with string.format (unlike something like javascript which has no equivalent).
local array = {500, 1.2, 0.325254, 2.22222}
for key,value in pairs(array) do
printf(string.format("[%s] = %.2f", key, value))
end
For comparison, in javascript you have to get the value manually, and you have to do annoying things to format strings.
let array = [500, 1.2, 0.325254, 2.22222];
for (let key in array) {
let value = array[key];
console.log("["+key+"] = "+value.toFixed(2));
console.log(`[${key}] = ${value.toFixed(2)}`);
}
The fact that you can modify crap from other files is also interesting, for example you can replace a function that exists in another file, without having to touch that file. I frequently see something like this:
local original_do_stuff = some_file.do_stuff
function some_file.do_stuff (x, y, z)
-- Insert some patch code here.
original_do_stuff(x, y, z)
end
If this is a feature of Lua itself, then I could see this being the reason why people say it's good for mods.
- Arrays are 1 indexed. It's not as bad as I would have thought, but having to change all my habits and learned tricks and way of approaching things sucks, and I don't see any benefit to it. Maybe it would be useful since 1 is the first item so you can treat 0 as none, however...
- ...Neither "" nor 0 equates to false, and you can't compare nil with a number. If you want to check if something is 0 or nil, you have to do if((not x) or (x == 0)) instead of just if(!x). Same with empty strings. I can only think of 1 context where I would want to accept an empty string instead of treating it similarly to undefined, and that's when you call a function that replaces nil with a default string but you specifically want it to be empty, but in all other cases it's the same as undefined to me. Similarly 0 means that there is none of something when I was asking for an amount, I'll usually want to check for it and branch out. This probably wouldn't be a problem in a type checked language, it's a problem in Lua because every single variable in the universe has the potential to also be nil.
- There's no differentiation between an array and an object/hashtable, there's just some weird combined amalgamation that starts behaving weirdly if you do the wrong thing. Array-related functions in general seem lackluster in Lua.
- The word-based syntax is cancer, especially the and/or shit, it doesn't make any sense when you start trying to do things like ternary conditionals.
- There's no "undefined" type. I never understood the purpose of js having both "undefined" and "null", but over time I've started to see some value in it. If you try to access an unset item from an array, you get undefined, but it may sometimes be useful to set an array item to an undefined value, in which case you would set it to null. There's a difference between an item not having a value or being disabled, and the item not existing in the first place.
- There's no single-line shorthands, for example in Javascript you can simplify things like this:
if (x) { foo(); }
if (x) foo();
some_value = some_value + 1;
some_value += 1;
But in Lua you cannot:
if (x) then foo() end
if (x) foo() -- Error.
some_value = some_value + 1
some_value += 1 -- Error.
I'm also starting to really get burned out from the typical scripting language shit. If you send a vector to a function and that function does something with it, it'll change the value of the original vector. You can't just send it by value. Duplicating the data of some object is a pain in the ass in general since everything is some kind of fucking hash table, and for similar reasons I become very uncomfortable when I need to store 10s of thousands of objects in some clusterfuck hierarchy. If you want to modify the data of a non-object, you also can't choose to send it as a pointer, you have to get the value from a return. I've also had a million crashes and every single one of them has been because I typoed or used the wrong a variable or the wrong function or function arguments were wrong or used the wrong object key or something ended up as nil because of some unexpected reason despite me checking for it everywhere. It's impossible to know that you did such a mistake until that piece of code tries to execute, which means you can't find it until after you've spent a whole minute launching the game and opening a save and doing the action you were trying to test.
All in all I can't understand why everyone is okay with languages like this. Maybe it's just because there's no good alternative, if you want a secure scripting language then what kind of language/runtime can you even use that has type checking and pointers/references and lets you actually control data? It just makes me keep coming back to admire how perfect C is. There's obviously many ways that C is lacking, but the fundamental concepts are so simple and effective that it's amazing how people managed to convince themselves not to have them in any language anymore. I can picture a language that would be like C except with various guard rails and high level conveniences and maybe even garbage collection, it sounds like an amazing language for scripting and probably for a lot of other things.