Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • For others interested in alternative syntax to the Lua VM/API sometime ago I've created LJS https://github.com/mingodad/ljs and also https://github.com/mingodad/ljsjit, I've also included an utility lua2ljs program based on the Lemon parser and re2c that convert Lua scripts to LJS with line by line synchronization https://github.com/mingodad/ljs/tree/master/lua2ljs, to test it I've also translated a few non trivial projects (https://github.com/mingodad/ZeroBraneStudioLJS , https://github.com/mingodad/raptorjit-ljs, https://github.com/mingodad/snabb-ljs, https://github.com/mingodad/premake-core/tree/ljs, https://github.com/mingodad/CorsixTH-ljs).

    I'm proud of it and thankfull to the Lua/Luajit projects.

  • This:

        var ary = [1,2,3,4]; //Array style declaration, syntax sugar for {}
    
    Is not a good idea. I tried using Haxe with Lua target at some point - the mismatch between what you think you get with [], and what you actually get in Lua, requires either a lot of boilerplate (Haxe compiles [] to Array objects), or a chronic WTF from all the new people reading your code (and from yourself, after a few weeks to months of disuse). If you want [1,2,3], make it behave more like an array - or just leave it out, would be my advice. Lua doesn't have arrays, and adding syntax that suggests it does will be a permanent footgun for your users, I think.
  • It might have been better to publicly document and stabilise the LuaJIT bytecode, which would allow people to then come up with whatever syntax they wanted in their own custom frontends.
  • Please don't, inscrutable bitwise operators are an accident of the past even in systems languages, let alone in a scripting language. I'm not against infix operators for bitwise operations, just please spell them out with keywords rather than giving them sigils.

    Likewise, going from `and` and `or` to `&&` and `||` would be a dispiriting regression. This is something that Zig got right.

  • The btiwise operators library doesn’t go away
  • Doesn't Zig also have bitwise operators?
  • I'm going to disagree only because one of the primary use cases for LuaJIT is interop with C and I think there's a case for making the ergonomics match.
  • You can have them in C/C++ at least [1]

    [1] https://en.cppreference.com/cpp/language/operator_alternativ...

  • What kind of person understands and needs bitwise operators but can't easily remember & | ~ and the arrows for shift? It's very little information.

    The part I'd call a hassle is the different kinds of right shift but you have that same hassle if you use keywords.

    I like using the and/or keywords for logical operations. Now let's make bitwise look significantly different from that.

  • One of the interesting things about Lua is because they don't really maintain compatibility between major versions, there isn't a huge ecosystem, and as a result there's less friction against making your own, slightly incompatible version. When you add on the simplicity of implementing the language, it's created a really diverse set of lua-alikes. Weird (and cool) for a language to have a diverse ecosystem of implementations, but not necessarily libraries.
  • Fragmentation is terrible for a language. Just look at Scheme. Nobody actually uses Scheme itself, it's always some Scheme implementation like Racket, Guile, Chicken, Chez, etc.

    Languages should probably protect themselves with trademarks or something.

  • Looks like LuaJIT is really going to fork away from Lua this time. After these changes, it won't be a compatible Lua 5.1 implementation anymore, it will be a new language.

    So shouldn't it have a new name?

  • Are there any rough estimates on popularity of lua implementations? At this point it feels lua means luajit
  • It could be opt in.
  • well, it doesn’t say Lua5.1-JIT
    by ulbu
  • Why won't it be compatible? Any code written in Lua 5.1 will run on LuaJIT.
  • Never will I understand ternary operators. As soon as you introduce it, some chuckle heads want to use them everywhere. Worse if the syntax allows nested ternarys. I guess it keeps the language open for code golfing, but it otherwise seems like redundant syntax that at best saves a few characters.
  • In Lua (and LuaJIT) you can already use `and` and `or`:

        local x = y and y + 1 or 0
    
    The knuckle heads are already using them everywhere.
  • I find it most useful in languages that have non-mutable variables and you want to avoid a mutable variable or an extra function when the value comes from a simple condition.
  • I guess for the JS case it makes sense to be able to shave a few characters for file shrinking purposes, but generally I'm more biased to code clarity and "self-explainability"
  • Lua basically already has ternary operators anyway since "and" and "or" short circuit. I also don't see the need of adding additional syntax for it.

      local x = condition ? value_a : value b
      local x = condition and value_a or value_b
  • That’s why “if” should just be an expression
  • I see JavaScript.

    Some of these really look like QoL improvements. I'm not convinced ternary statements are an ergonomic improvement in particular. The examples given don't make a compelling case, 'visually tidy' is not the same as readable.

  • Lua to me always felt very JavaScripty, just with a different syntax.
  • I kinda have seen somewhere on internet, that the language design of lua and js(well, ecmascript to be precise) is somehow related. But can't really find the exact reference I have seen.. it was long time ago when I read this.
  • Worse, I see C (as in ! or &&), and Perl (as in manifestly more than one way to do it).

    There are real improvements though, such as ?. and ??= that help with default-nullable everything.

    Ternary is very useful, but it I'd rather see it implemented idiomatically:

      pos += (if forward then +1 else -1)
    
    Structural pattern-matching could be fantastic, but no syntax is suggested.
  • Tangently related but I’ve been deep in Lua recently working on a rust implementation that supports Lua 5.1-5.5 in one Rust Binary https://github.com/ianm199/omnilua.

    My ultimate goal was to support LuaJIT in Rust as well but this does not make it easier.

  • This is amazing! Can a program call across versions? Like could we take a Lua 5.1 codebase and upgrade only a portion of it at a time to a new Lua version?
  • Oh wow, seriously, I always thought Lua should have been like this. The 5.1/5.2/5.3+ split was so painful.

    > My ultimate goal was to support LuaJIT in Rust as well but this does not make it easier.

    I think you could stop right before the syntax extension.

  • Also, one issue I have with this repo is that, since so much of it seems to use Claude, as an actual human I struggle to read and parse any of the information.

    For example, what’s the performance like?