MoonScript, a language that compiles to Lua

classic Classic list List threaded Threaded
62 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

MoonScript, a language that compiles to Lua

leaf corcoran
Hello,

I've been working on a little language heavily inspired by
CoffeeScript, which I've called MoonScript. The homepage is located at
http://moonscript.org

It compiles into Lua, but there are numerous ways to actually run the code.

The parser is all done in LPeg, and the majority of the compiler
itself is written in MoonScript. I've also used a few other libraries
(listed on the site) to build the tools.

I've also written copious amounts of documentation in the hopes that
someone will actually use it, http://moonscript.org/reference

The source is located on GitHub: https://github.com/leafo/moonscript

I've successfully installed it with LuaRocks on both Linux and OSX. I
have not tried it on Windows, but I don't see why it wouldn't work.

I think there's some pretty cool stuff in it. By just requiring
"moonscript", you can make the require function MoonScript aware and
have it automatically build and run .moon files as you would with .lua
files. I've also got line number reversal, so errors that happen in
the compiled Lua are rewritten to point back to the original
MoonScript line.

Anyway, check it out the docs to see the rest of the features. I'd
appreciate any input (including feature requests). This is the initial
release so there might be some bumps.

Thanks, Leaf

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Xavier Wang
2011/8/11 leaf corcoran <[hidden email]>:

> Hello,
>
> I've been working on a little language heavily inspired by
> CoffeeScript, which I've called MoonScript. The homepage is located at
> http://moonscript.org
>
> It compiles into Lua, but there are numerous ways to actually run the code.
>
> The parser is all done in LPeg, and the majority of the compiler
> itself is written in MoonScript. I've also used a few other libraries
> (listed on the site) to build the tools.
>
> I've also written copious amounts of documentation in the hopes that
> someone will actually use it, http://moonscript.org/reference
>
> The source is located on GitHub: https://github.com/leafo/moonscript
>
> I've successfully installed it with LuaRocks on both Linux and OSX. I
> have not tried it on Windows, but I don't see why it wouldn't work.
>
> I think there's some pretty cool stuff in it. By just requiring
> "moonscript", you can make the require function MoonScript aware and
> have it automatically build and run .moon files as you would with .lua
> files. I've also got line number reversal, so errors that happen in
> the compiled Lua are rewritten to point back to the original
> MoonScript line.
>
> Anyway, check it out the docs to see the rest of the features. I'd
> appreciate any input (including feature requests). This is the initial
> release so there might be some bumps.
>
> Thanks, Leaf
>
>

Looks interesting, A question:
Why use (function()...end)() method to create a class? if I write
class in a function, every times the function called, the new function
will created, is that OK?

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

云帆江
cool language, can you compile it to lua vm?

On Thu, Aug 11, 2011 at 03:07:34PM +0800, Xavier Wang wrote:

> 2011/8/11 leaf corcoran <[hidden email]>:
> > Hello,
> >
> > I've been working on a little language heavily inspired by
> > CoffeeScript, which I've called MoonScript. The homepage is located at
> > http://moonscript.org
> >
> > It compiles into Lua, but there are numerous ways to actually run the code.
> >
> > The parser is all done in LPeg, and the majority of the compiler
> > itself is written in MoonScript. I've also used a few other libraries
> > (listed on the site) to build the tools.
> >
> > I've also written copious amounts of documentation in the hopes that
> > someone will actually use it, http://moonscript.org/reference
> >
> > The source is located on GitHub: https://github.com/leafo/moonscript
> >
> > I've successfully installed it with LuaRocks on both Linux and OSX. I
> > have not tried it on Windows, but I don't see why it wouldn't work.
> >
> > I think there's some pretty cool stuff in it. By just requiring
> > "moonscript", you can make the require function MoonScript aware and
> > have it automatically build and run .moon files as you would with .lua
> > files. I've also got line number reversal, so errors that happen in
> > the compiled Lua are rewritten to point back to the original
> > MoonScript line.
> >
> > Anyway, check it out the docs to see the rest of the features. I'd
> > appreciate any input (including feature requests). This is the initial
> > release so there might be some bumps.
> >
> > Thanks, Leaf
> >
> >
>
> Looks interesting, A question:
> Why use (function()...end)() method to create a class? if I write
> class in a function, every times the function called, the new function
> will created, is that OK?

--
cheers
    Yunfan Jiang
{'nick':['jyf', 'geek42'], 'im': {'gtalk': '[hidden email]', 'irc': 'irc.freenode.net#ubuntu-cn'}, 'blog': 'http://geek42.info', 'interesting': {'teck': ['linux', 'python', 'lua', 'c', 'nosql', 'redis', 'nginx'], 'history': ['chinese history',], 'sf': [42,], 'music': ['NewAge style', 'chinese old theme', 'Any strange music']}}

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

steve donovan
On Thu, Aug 11, 2011 at 10:16 AM, jyf <[hidden email]> wrote:
> cool language, can you compile it to lua vm?

Well, it's translated directly to Lua, so it should work with both Lua
5.1 and LuaJIT.

It does look good. Not sure that the world needs another language, but
there are some very cool ideas at work here.

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

leaf corcoran
In reply to this post by Xavier Wang
Yeah, it's not required in this case. I've got a few places where I
need to optimize the generated code a bit.

On Thu, Aug 11, 2011 at 12:07 AM, Xavier Wang <[hidden email]> wrote:

> 2011/8/11 leaf corcoran <[hidden email]>:
>> Hello,
>>
>> I've been working on a little language heavily inspired by
>> CoffeeScript, which I've called MoonScript. The homepage is located at
>> http://moonscript.org
>>
>> It compiles into Lua, but there are numerous ways to actually run the code.
>>
>> The parser is all done in LPeg, and the majority of the compiler
>> itself is written in MoonScript. I've also used a few other libraries
>> (listed on the site) to build the tools.
>>
>> I've also written copious amounts of documentation in the hopes that
>> someone will actually use it, http://moonscript.org/reference
>>
>> The source is located on GitHub: https://github.com/leafo/moonscript
>>
>> I've successfully installed it with LuaRocks on both Linux and OSX. I
>> have not tried it on Windows, but I don't see why it wouldn't work.
>>
>> I think there's some pretty cool stuff in it. By just requiring
>> "moonscript", you can make the require function MoonScript aware and
>> have it automatically build and run .moon files as you would with .lua
>> files. I've also got line number reversal, so errors that happen in
>> the compiled Lua are rewritten to point back to the original
>> MoonScript line.
>>
>> Anyway, check it out the docs to see the rest of the features. I'd
>> appreciate any input (including feature requests). This is the initial
>> release so there might be some bumps.
>>
>> Thanks, Leaf
>>
>>
>
> Looks interesting, A question:
> Why use (function()...end)() method to create a class? if I write
> class in a function, every times the function called, the new function
> will created, is that OK?
>
>

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Philippe Lhoste
In reply to this post by steve donovan
On 11/08/2011 10:27, steve donovan wrote:
> It does look good. Not sure that the world needs another language, [...]

A question coming with each announce of a new language, ie. some
fifty-two times per year (made up figure, of course).
Particularly in the JVM world, with the announces of Gosu, Mirah,
Ceylon, Kotlin, etc. "Why make a new language when we have the awesome
Scala?" <- often prompted because the new languages feel the need to
compare to Scala, promising more simplicity, while detractors say that
then they loose power and flexibility.

Why make a new language?
- Because it is fun! (that alone is probably the main cause for
proliferation)
- Because of some frustration with the existing languages (on syntax, on
limitations, etc.)

There are some languages inspired more or less by Lua, but not much
using the LuaVM and even less producing Lua code, so it is an
interesting product. I wonder how hard it would be to produce JavaScript
instead. It is a common target for compilers today, because it is so
pervasive / cross-platform, and recent performances of JS engines make
it a more realistic target.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Xavier Wang
2011/8/11 Philippe Lhoste <[hidden email]>:

> On 11/08/2011 10:27, steve donovan wrote:
>>
>> It does look good. Not sure that the world needs another language, [...]
>
> A question coming with each announce of a new language, ie. some fifty-two
> times per year (made up figure, of course).
> Particularly in the JVM world, with the announces of Gosu, Mirah, Ceylon,
> Kotlin, etc. "Why make a new language when we have the awesome Scala?" <-
> often prompted because the new languages feel the need to compare to Scala,
> promising more simplicity, while detractors say that then they loose power
> and flexibility.
>
> Why make a new language?
> - Because it is fun! (that alone is probably the main cause for
> proliferation)
> - Because of some frustration with the existing languages (on syntax, on
> limitations, etc.)
>
> There are some languages inspired more or less by Lua, but not much using
> the LuaVM and even less producing Lua code, so it is an interesting product.
> I wonder how hard it would be to produce JavaScript instead. It is a common
> target for compilers today, because it is so pervasive / cross-platform, and
> recent performances of JS engines make it a more realistic target.
>
> --
> Philippe Lhoste
> --  (near) Paris -- France
> --  http://Phi.Lho.free.fr
> --  --  --  --  --  --  --  --  --  --  --  --  --  --
>
>
>

I think it is not a *new* language -- as it looks very like CoffeeScript :)

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

steve donovan
In reply to this post by Philippe Lhoste
On Thu, Aug 11, 2011 at 11:04 AM, Philippe Lhoste <[hidden email]> wrote:
> There are some languages inspired more or less by Lua, but not much using
> the LuaVM and even less producing Lua code, so it is an interesting product.

Fun is a good motivation and any new language opens up possibilities.
Being Lua-based is a smart way to go, since there are libraries
available and you will get great performance.  Some of the MS idioms
(*t is short for ipairs(t), table comprehensions) are very expressive.

Local-by-default and Significant whitespace raise their heads again...

steve d.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Miles Bader-2
steve donovan <[hidden email]> writes:
> Local-by-default and Significant whitespace raise their heads again...

Gotta wait until all the python programmers are dead I suppose...

-miles

--
Selfish, adj. Devoid of consideration for the selfishness of others.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

David Kastrup
Miles Bader <[hidden email]> writes:

> steve donovan <[hidden email]> writes:
>> Local-by-default and Significant whitespace raise their heads again...
>
> Gotta wait until all the python programmers are dead I suppose...

Just send them to the Netherlands.  They'll declare themselves dead
based solely on their elevation level.

--
David Kastrup


Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Lorenzo Donati-2
In reply to this post by Miles Bader-2
On 11/08/2011 12.32, Miles Bader wrote:
> steve donovan<[hidden email]>  writes:
>> Local-by-default and Significant whitespace raise their heads again...
>
> Gotta wait until all the python programmers are dead I suppose...
>
> -miles
>

Fortunately I "was exposed" to Lua shortly after I started learning
Python (coming from an experience of mostly statically typed languages
like Java and C++), so I had a better subject on which to focus my brain
:-).

Although I started to appreciate the batteries of Python and its dynamic
features, I always hated deeply that "significant whitespace" thing (and
was bitten by it several times refactoring code).

It always brings to my mind the stubborness of some old "make"
implementation and those old FORTRAN (77?) requirements (the heritage of
punchcards, I mean). Ugh! I've never understood why to some people it is
a good thing to make the well-formedness or (worse) the semantics of a
program (in a general purposes language) depend on something that you
cannot even see and that may depend visually on the settings of your
current editor (ugh!)!

I can accept to spend hours to find a subtle bug because of my faults in
programming (after which I probably know the language better and I'm a
better programmer). I cannot accept to spend hours to detect a bug
induced by a space/tab idiosyncrasy (after which I haven't learned
anything and have only grown the feeling of throwing the workstation out
of the window!).

Yes, I know smart editors can make your life better in this respect, but
it is a silly exercise if you made your life worse by choosing an ugly
syntax in the first place [1].

But as a programming professor told us when I was at the university in
early 90s: "...sadly, sometimes ugly and horrible things get widespread,
and even famous - so *you have* to learn how to use vi editor on a Unix
workstation". 8-)

As for "local by default", I didn't know much at the time. But after
learning about closures and upvalues in Lua, I can really appreciate Lua
team decision of not doing that (yes - I read many of the old threads on
local/global/nothing by default and I find the current alternative the
best approach - YMMV).


[1] Maybe I overemphasize a bit, but IMO compared to significant WS,
even Java anonymous inner classes syntax looks beautiful (ugh!). At
least you *see* something!


-- Lorenzo

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Axel Kittenberger
> I cannot accept to spend hours to detect a bug induced
> by a space/tab idiosyncrasy

IMHO that was the biggest error of python on their take of significant
white-space.
I'd outlaw either, so any script that has not exclusively spaces or
tabs in every line until the first non-space-character should simply
just generate a compiler error.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Mihamina Rakotomandimby
On 08/11/2011 02:29 PM, Axel Kittenberger wrote:
>> I cannot accept to spend hours to detect a bug induced
>> >  by a space/tab idiosyncrasy
> IMHO that was the biggest error of python on their take of significant
> white-space.
> I'd outlaw either, so any script that has not exclusively spaces or
> tabs in every line until the first non-space-character should simply
> just generate a compiler error.
>

This has advantages and drawbacks...

--
RMA.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Enrico Colombini
In reply to this post by Axel Kittenberger
On 11/08/2011 13.29, Axel Kittenberger wrote:
> I'd outlaw either, so any script that has not exclusively spaces or
> tabs in every line until the first non-space-character should simply
> just generate a compiler error.

That would make things better, but couldn't unfortunately prevent subtle
(and not so subtle) errors introduced when
copying/pasting/deleting/editing code if the insertion point is not in
the correct horizontal position.
It happens often enough to me in any language, that I thought it better
to avoid a language where I'd be sure to shoot myself in the foot sooner
or later.

I've always wondered why force programmers to take care manually of
something that could be automated by the editor.
e.g. some scripters in one of my teams did a good job, but never managed
to grasp the idea of proper indentation. Fortunately it was Lua and I
didn't have to guess what their code was supposed to do :-)

Hmm... we could design a language where even the 3rd dimension is
semantically significant. It would need a 3D printer, of course, but
updented code would really stand out ;-)

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Mihamina Rakotomandimby
In reply to this post by Axel Kittenberger
On 08/11/2011 02:29 PM, Axel Kittenberger wrote:
>> I cannot accept to spend hours to detect a bug induced
>> >  by a space/tab idiosyncrasy
> IMHO that was the biggest error of python on their take of significant
> white-space.
> I'd outlaw either, so any script that has not exclusively spaces or
> tabs in every line until the first non-space-character should simply
> just generate a compiler error.
>

This has advantages and drawbacks...

--
RMA.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Lorenzo Donati-2
In reply to this post by Enrico Colombini
On 11/08/2011 14.02, Enrico Colombini wrote:

[...]

> Hmm... we could design a language where even the 3rd dimension is
> semantically significant. It would need a 3D printer, of course, but
> updented code would really stand out ;-)
>

Or we can rely on the amazing 3D capabilities of current graphics
adapters and let the programmer write code in different parallel layers
along the z-axis :-)

It would be interesting to see what kind of syntax and semantics could
be devised for such a beast! :-D

Not to mention a suitable editor (autocad 3D ? ;-)

-- Lorenzo

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Peter Hickman-3
Wasn't there a variant of Befunge that operated in 3D?

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

Enrico Colombini
On 11/08/2011 14.43, Peter Hickman wrote:
> Wasn't there a variant of Befunge that operated in 3D?

It's getting harder and harder to invent something nowadays. How sad :-)

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

The Scripting World Cup (was: MoonScript, …)

Dirk Laurie
In reply to this post by David Kastrup
On Thu, Aug 11, 2011 at 12:54:55PM +0200, David Kastrup wrote:
>
> Just send them to the Netherlands.  They'll declare themselves dead
> based solely on their elevation level.
>

Imagine a World Cup for scripting languages:

US              Perl        Running hard all over the park, no style
Netherlands     Python      Oversophisticated, many passes, few goals
Japan           Ruby        Exquisite little tricks that almost work
Brazil          Lua         Simplicity, elegance and flair

Força Brasília!

D.

Reply | Threaded
Open this post in threaded view
|

Re: MoonScript, a language that compiles to Lua

steve donovan
In reply to this post by Enrico Colombini
On Thu, Aug 11, 2011 at 3:09 PM, Enrico Colombini <[hidden email]> wrote:
> It's getting harder and harder to invent something nowadays. How sad :-)

Which is why we should support the OP with his brave effort to
generate a new language!

As a side note, it seems that both whitespace and curly brackets are
invisible to some people. Educated, smart professionals who could not
see { } as a block. Lua is good for communicating with them ;)

As for 3D; nah, 3D printers are too messy. It must be an immerse
virtual world, where programming becomes a matter of picking up
virtual servers and plugging them into each other; configuration is
done with 'instrument panels' and you can do cool things like making
the cables glow when they're active. A fantastic way to blow immense
amounts of computing power, and so much fun when you have to trace
cables behind the cabinets ;)

steve d.

1234