upvote
LuaJIT borrowed from 5.2 and 5.3 (PUC-Rio's Lua) what it could without breaking compatibility, as I understand it. LuaJIT 3.0 adds some feature of its own.

All the Lua 5.x versions that I have seen have small compatibility issues, and that's why many projects stick with what it's compatible with 5.1 only.

C++ doesn't have any "native json support" either, and that's fine. I don't think JSON is that critical. You can use a library for the kind of serialization that you want. Neovim uses JSON and Lua extensively, and it just uses a C library inside.

It's true that `{}` doubles down as an empty array or an empty map. It is not a problem that often, IME. You also can't signal that a certain key in a map is `nil`, but you can use a sentinel for it. You can do the same to disambiguate between these two.

Different features hit differently to different people. I agree that global by default seems so wrong, but I just go used to it, and I don't care anymore. To me, the main deal is not that Lua doesn't have this features by default, is more that, when I want them, there is no generally agreed library/framework that can plug all the features in a unified, coherent way. Penlight should be that, but I don't like it that much.

This is something that personally hits me the most, because I'm used to Qt. With Qt, I have tons and tons of functionality and a well established community and practices.

reply
Wanting things like native JSON support goes against the Lua spirit. Something like that belongs in a library, and lo and behold, there are several:

https://luarocks.org/modules/luarocks/json4lua - https://luarocks.org/modules/winterstream/wjson - https://luarocks.org/modules/xpol/rapidjson - etc.

Lua supports arrays; it has optimizations when all of a table’s keys are integers. Keep in mind that AWK is the same way: There’s no numeric array in AWK per se either, just AWK’s version of a “table”, but it works just fine when all of the keys are integers.

Keep in mind that I have a fork of Lua which is 116,224 bytes in size (security hardened Lua 5.1 with `lfs` support); Lua is tiny and that’s why it does not have a built in JSON library nor will it wash the dishes for you.

Versions of Lua after Lua 5.1 introduced changes which broke backward compatibility. Lua 5.1 is smaller than newer versions of Lua, runs great, and is incredibly fast. I see Lua 5.5 as a different language than Lua 5.1, even though one can make a polyglot program which can run in both. Lua 5.1 is also the point from which a bunch of offshoots were made: luau (Roblox Lua), LuaJIT, etc.

reply
luajit and luau supporting 5.1 only is a feature: it freeze language so no more backward compatibility breaks

Lua has many quirks (global by default etc.) but with a language server like https://luals.github.io/, you can detect most of them easily plus optional type annotations.

reply
Also, it’s possible to force global variables to be explicitly declared.

  function declare(name)
    rawset(_G,name,false)
  end
  function exists(name)
    if rawget(_G,name) ~= nil then 
      return true 
    else return false end
  end
  setmetatable(_G, {
    __newindex = function(self,x) error("Undeclared global " .. x) end,
    __index = function(self,x) error("Undeclared global " .. x) end
  })
And now

  declare("foo")
  foo = 1
  -- Create name if it hasn’t 
  -- been declared yet
  if not exists("name") then 
    declare("name")
    name = 1
  end
More discussion: https://lua.org/pil/14.2.html
reply