Open ngocgodwar opened 4 years ago
It's intended behavior for existential op. Expression ends with a ?
will be compiled to (expr ~= nil)
. Maybe we can add existential check syntax to the with statement in this way.
with? io.open "test.txt", "w"
\write "hello"
\close!
compiles to:
local _with_0 = io.open("test.txt", "w")
if _with_0 ~= nil then
_with_0:write("hello")
_with_0:close()
end
return _with_0
The reason Moonscript does not support putting chain calls over new lines is because it conflicts with the 'with' statement syntax. Consider the case:
with strA
str = strB
\gsub("a", "") -- Is it strA\gsub("a", "") or strB\gsub("a", "") ?
This feature can be added. But modifiying generated Lua codes from Moonscript might not be a good idea, which means there will be two copies of codes to be maintained separately. Maybe we can write a Moonscript IDE with autocomplete features someday and let the users focus on Moonscript side only.
";" in Moonscript is currently used to separate argument list from expression list, for example:
a, b = f 1; 2
return f 123, 456; 123
compiles to:
local a, b = f(1), 2
return f(123, 456), 123
Maybe we can change it to another symbol and make ";" work for putting statements in a same line.
The infix macro operator is worth to be considered as a syntax sugar, maybe add it in the future.
Can you show me some Lua DSL usages so that I can figure out what MS lacks for it? And I think macro system is ready for implementing many DSL features in MS.
Until ... Repeat can be added to Moonscript with support for continue
keyword.
Improvements 1, 7 were done by commit d80160356d7b7119d164ada51867cecb0a371f09
It not about modify generated Lua codes but have a good looking Lua code file. It good for follow reasons:
Maybe we can use double symbol like ";;" or "&&" or "||" or whatever make sense, maybe it will easy to look at and distinct each statements.
I not that good with DSL so it all my speculate. I love Lua DSL feature that we call function without () with literal string or table. Well EX below valid Lua and nice to look at:
dialogue
"A: Hi!"
"B: Hello"
"..."
{"ABC", "XYZ"}
"A: abc"
"B: xyz"
"."
jump "end"
Now thing about it, this feature really not that much import... and I think it hard to transfer to MoonScript. We don't really need it that much anyway.
Thanks for your time and regards!
Just think about some improvements to MoonPlus that worth to consider:
Exist OP + "with" keyword. Let look at this code:
Compile to:
Is it intended behaviour or maybe it should be:
Support chain function call over new lines. With would be nice to look at and edit code. EX:
It would be good if MoonPlus have options to keep full blank lines and full line comments. It would make generated lua file more easy to look at, work with, debug and make sense to distribute lua file. More over many Lua IDE like EmmyLua support editor autocomplete with meta data fetch from line comments. This feature would be a great addition to MoonPlus over old MoonScript.
Support inline many statements separated with ";" because sometime keep many things on the same line many reason, especially when work with anonymous function.
Macro feature is really good. And I have been thinking if something similar can do with operations. The idea is that can add other modern operations to lua like: power(**), floor division (//), bit and(&), bit or(|). EX: Instead of write: local res = bit32.band(a, b) We can write: res = a | b Or let symbol . or & or whatever to denote macro operations like: res = a .| b Or use normal macro string res = a $and b
DSL support. Lua support it but MoonScript lost it. I write some dynamic scripts dialogue include game flow framework. DSL is very good at it kind of task but not play nice with MoonScript. It would be great it MoonPlus somehow make it but I know it would be kind of difficult.
Until ... Repeat Not really need it but Lua have it. MoonScript have it for completion mapping to Lua.
What you thinks? Many thanks and regards!