Earlier quoted context omitted.
cond1 ? res1 : cond2 ? res2 : cond3 ? res3 : or_else_res If they are truly nested, then that is confusing. But if you have an if-else chain, then it can be quite readable.
Or they could just ask granddaddy for advice: (cond (cond1 res1) (cond2 res2) (cond3 res3) (t else_res)) =)
LuaJIT 3.0 proposed syntax extensions
151–160 of 170 posts
Re: LuaJIT 3.0 proposed syntax extensions
#152For 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…
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.Re: LuaJIT 3.0 proposed syntax extensions
#153I would love to see all of these come to LuaJIT (and love2d to support the new version too). It’s nice that Lua is simple, the syntax changes should hopefully make Lua code even simpler to read too
> It’s nice that Lua is simple, the syntax changes should hopefully make Lua code even simpler to read too But which Lua? Lua as implemented by LuaJIT is a fork of the language at this point. It's not fully compatible with PUC Lua (the reference implementation) and LuaJIT does not support features from the latest Lua version.
Lua is strange. Lua 5.2 was more of a "fork of the language" than LuaJIT, at the time. 5.3 and 5.4 (especially the latter) changed even more. Lua looks like a family of languages, and it seems to be by design. It probably makes sense in the "embedded scripting" space. Lua is not really meant to be (though it obviously is, if you want) a general-purpose language. It's meant for extending other apps, and scripting engines have different requirements than other language implementations: basically, hardcore backward compatibility. But it's impossible to evolve the language and innovate in its design if you commit to that. This is still an academic project, so hardcore backward compatibility is unlikely to be something the authors would value. Hence, the mixed model - every major version is a new "take" on the language. You're expected to pick a version when you first need a scripting engine, and then sit on that version until the end of time. Meanwhile, PUC releases new versions of Lua, and new projects pick those newer versions (and then sit on them forever).
It looks strange, and it has important downsides (a fragmented ecosystem, huge PITA when trying to write portable libraries, so fewer libraries in general, etc.), but it does seem to work in that Lua still exists and, project after project (not within a single project), it continues evolving.
Re: LuaJIT 3.0 proposed syntax extensions
#154Some of these things are already implemented in PUC Lua. I don't know why they are diverting from lua spec on other aspects though. Why not work together with the PUC Lua team to add some of these to both lua versions and work on bringing their functionality closer to each other instead of further apart. You might as well just make a new language instead. New features will end up not being used in effort to keep lua…
Re: LuaJIT 3.0 proposed syntax extensions
#155Some of these things are already implemented in PUC Lua. I don't know why they are diverting from lua spec on other aspects though. Why not work together with the PUC Lua team to add some of these to both lua versions and work on bringing their functionality closer to each other instead of further apart. You might as well just make a new language instead. New features will end up not being used in effort to keep lua…
I agree. I posted this on the GitHub issues but got nothing but downvotes.
> In effort to not pollute the github issue
You should make yourself heard. It's a legitimate concern.
Re: LuaJIT 3.0 proposed syntax extensions
#156Earlier quoted context omitted.
Is there any reason why they're not considering a single '?' like rust? Is it a parsing issue? So you'd have: obj?:method(…)
Mike Pall wrote in the issue that it's easier to parse. If they get rid of the ternary operator, I'll ask him again to drop the period.
Re: LuaJIT 3.0 proposed syntax extensions
#157Earlier quoted context omitted.
Mike Pall wrote in the issue that it's easier to parse. If they get rid of the ternary operator, I'll ask him again to drop the period.
a lone ? can mean anything, you can already tell that . is for fetching a subtable.
Lua could have ?. ?[ ?" ?{ and ?(
Re: LuaJIT 3.0 proposed syntax extensions
#158Earlier quoted context omitted.
> Is the intent to hold LuaJIT fixed against some earlier Lua version (I guess 5.1) Yeah. PUC-Rio went in a direction that Mike Pall didn't want to follow. Something to do with garbage collector finalizers, if I remember correctly, which is a notoriously thorny issue in every language it exists.
I think it was more the extra layers of indirection added to function environment\effectively global variable access added in 5.2 . The removal of scanning for changed userdata finalizer meta method in 5.2 is just a commonsense fix for bad design that made GC atomic phase run time, thats not incremental scale up with the number of GC userdata objects alive no matter if they have a finalizer or not.
Re: LuaJIT 3.0 proposed syntax extensions
#159I am asking because i want to implement plugins in my media server, however i want to guard them in vm's i can control.
Re: LuaJIT 3.0 proposed syntax extensions
#160Some of these things are already implemented in PUC Lua. I don't know why they are diverting from lua spec on other aspects though. Why not work together with the PUC Lua team to add some of these to both lua versions and work on bringing their functionality closer to each other instead of further apart. You might as well just make a new language instead. New features will end up not being used in effort to keep lua…
The bracketed syntax is an okay idea especially for , adding close as a keyword would be a disaster given how common the word is. If anything, local should have been tossed away as a keyword and the bracketed syntax adopted completely
v , v2 = io.open'file', false
g = 5
5.5 introduced global which makes better use of attributes as well. of course, I don't deny how great it would be to not type or local const since const would already imply a local> string interpolation
Hisham already made this nice module https://github.com/hishamhm/f-strings Which I don't dare use, even if you don't have string interpolation. Of course, I don't care because I just have a table.format(tbl, "tbl.key is %{key}"), is it a little tedious? sure, but its just a gsub call.
> short form function syntax
I disagree with this, I've always wanted it and roll my eyes as I write/create a function, especially when you like to use lots of them like
str:gsub('%d+', (s){ tonumber(s)+1 })
> Named varargs: It may be nice, but there is no real reason to add this. If you wanted a name for your varargs you could do `local name = ...` or just use the `args` variable already available in every function.You've made a mistake there
local name = ...
is local name = ({...})[1]
In order to actually do this you need to local name = table.pack(...)
If you will use a vararg, you will always have to do this, so why not just let it be handled in the parameter definition? its costless. AND lua5.5 already introduced this so it seems they liked it.Quite frankly I would like the capability of treating ... as just an array like ...[1] but I haven't looked at the parser to see if its feasible or not.
> Switch/Match/Select Statements: An optimized if/else block works just as well and another expansion of a small language.
I don't disagree, but big table of functions is so ugly, switch statements would be nice