Coder Social home page Coder Social logo

leafo / moonscript Goto Github PK

View Code? Open in Web Editor NEW
3.1K 92.0 193.0 3.01 MB

:crescent_moon: A language that compiles to Lua

Home Page: https://moonscript.org

Lua 58.29% MoonScript 41.32% Shell 0.04% Makefile 0.32% C 0.02%
moonscript lua language transpiler parsing-expression-grammar

moonscript's Introduction

MoonScript

MoonScript

spec Build status

MoonScript is a programmer friendly language that compiles into Lua. It gives you the power of the fastest scripting language combined with a rich set of features. It runs on Lua 5.1 and above, including alternative runtimes like LuaJIT.

See https://moonscript.org.

Online demo/compiler at https://moonscript.org/compiler.

Join Our Community

We just created a Discord for those interested in MoonScript. You can join us here: https://discord.gg/Y75ZXrD

Running Tests

Tests are written in MoonScript and use Busted. In order to run the tests you must have MoonScript and Loadkit installed.

To run tests, execute from the root directory:

busted

Writing specs is a bit more complicated. Check out the spec writing guide.

Binaries

Precompiled versions of MoonScript are provided for Windows. You can find them in the GitHub releases page. (Scroll down to the win32- tags.

The build code can be found in the binaries branch

Editor Support

License (MIT)

Copyright (C) 2020 by Leaf Corcoran

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

moonscript's People

Contributors

arkeus avatar cahna avatar chickennuggers avatar eloff avatar geomaster avatar jnrowe avatar lassik avatar leafo avatar ludwikjaniuk avatar mpeterv avatar natnat-mc avatar nilnor avatar nonchip avatar nucleartide avatar pygy avatar qaisjp avatar rgieseke avatar ryansquared avatar shemarmc avatar slice avatar sliceofcode avatar woofers avatar ylixir avatar yorwba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moonscript's Issues

Why not use a more brief syntax for tables?

In MoonScript, to define a table one need to write:

some_values = {
  name: "Bill",
  age: 200,
  ["favorite food"]: "rice"
}

Comparison that, in CoffeeScript, curly brackets a not required:

some_values =
  name: "Bill"
  age: 200
  "favorite food": "rice"

Why not use something conciser, like CoffeeScirpt?
Or even:

table =: 1,2,3,4
table =
  "name" : "string"
  table::
    n: 1
  table2::
    1
    2
    3

return

Hi!

In order to suppress implicit returning of the last expression result i use closing return (verbatim). However, it goes intact in the resulting Lua code, which is simply redundant. Can you consider treating closing return as just sign to suppress implicit returning?

TIA,
--Vladimir

unless keyword

Although it's pure syntactical sugar that could be handled by if not, sometimes unless would read significantly better.

unless value
    value = calculate!

or

value = calculate! unless value

Could compile into

if not value then
    value = calculate()
end

An arithmetic formula Error

Right:
print 4+2-(2+3)
print (4+2)- (2+3)
print (4+2) - (2+3)

Error:
print (4+2) -(2+3)
print (4+2)-(2+3)

Error output:
moon: 1.moon:1(1): attempt to call a number value
stack traceback:
1.moon:1(1): in main chunk

whitespace agnostic mode (begin...end)

u already know that there is extremely large population which hates python due to its significant whitespace issue, including myself. It just backtracking to 1970s.
"Boo programming language" has two modes- one python inspired syntax (white space significant) and another whitespace agnostic mode

why can't it be offered by you
moon -nowhite file1.moon (using commandline switch OR a switch in API)
can process "begin.. end" blocks to convert them to tabs internally
or still better,
moon file1.moonx (moonx file extension will show that it has to be processed in whitespace agnostic mode) (I WILL PREFER THIS FILE EXTENSION BASED APPROACH)
or, moonx file1.moonx

in api also, if you have parse_code("moon_filename") , then you can extend it as parse_codex("moonx_filename") to deal with whitespace agnostic mode.

but why are you hampering the adoption of your language , just because you want to force people to use the whitespace issue , which is an editor/IDE issue to make it as a language source syntax issue. Still wherever or internet, it is discussed there are always two big camps (python guys and non-python(ruby,lua,groovy,C++,vb.net,C# etc) guys fighting this whitespace issue.

THIS significant whitespace is just plain braindead, we (me , my friends, my colleagues) just can not stand it, it just stinks.

Metamethod inheritance does not work

Not entirely sure if this is a feature or a bug, but metamethods defined in a class do not work in child classes. e.g.

class Foo
  new: =>
  __tostring: =>
    return "foo!"

class Bar extends Foo
  new: =>

print tostring Foo! -- prints "foo!"
print tostring Bar! -- prints "table: 0x..."

You can get the inheritance to work just by adding

__tostring:=>super!

to the child class, but it seems a little kludgey

I looked closer at the actual class code generated and it looks like the parent class' __base is no longer added as a metatable to the child's __base -- if it were it seems like the metamethods should inherit just fine.

-- Strike that, yes it does! Still doesn't work though, and I have no idea why.

Default function value definition within class

The first parms default value needs to by wrapped in parentheses in order to not return a moonc compile error if it is a reference to a variable.

class Test

    new: =>
        @v1 = '1'
        @v2 = '2'       

    testFunc: (a =(@v1), b = @v2) =>
        print a .. b

Test!\testFunc!

elseif -- assignment as conditional expression fails to compile

Reproducible with example from docs in online compiler:

if hello = os.getenv "hello"
  print "You have hello", hello
elseif world = os.getenv "world"
  print "you have world", world
else
  print "nothing :("

result:

./web_moon.lua:67: Compile error: /app/packages/share/lua/5.1/moonscript/types.lua:259: unknown key: `__class` on node type: `if`
stack traceback:
    [C]: in function 'error'
    /app/packages/share/lua/5.1/moonscript/types.lua:259: in function </app/packages/share/lua/5.1/moonscript/types.lua:255>
    /app/packages/share/lua/5.1/moonscript/util.lua:10: in function 'type'
    /app/packages/share/lua/5.1/moonscript/transform.lua:185: in function 'apply_to_last'
    /app/packages/share/lua/5.1/moonscript/transform.lua:645: in function 'transformer'
    /app/packages/share/lua/5.1/moonscript/transform.lua:360: in function </app/packages/share/lua/5.1/moonscript/transform.lua:351>
    (tail call): ?
    (tail call): ?
    /app/packages/share/lua/5.1/moonscript/transform.lua:196: in function </app/packages/share/lua/5.1/moonscript/transform.lua:190>
    (tail call): ?
    /app/packages/share/lua/5.1/moonscript/transform.lua:743: in function 'transformer'
    /app/packages/share/lua/5.1/moonscript/transform.lua:360: in function </app/packages/share/lua/5.1/moonscript/transform.lua:351>
    ...
    (tail call): ?
    /app/packages/share/lua/5.1/moonscript/transform.lua:645: in function 'transformer'
    /app/packages/share/lua/5.1/moonscript/transform.lua:360: in function </app/packages/share/lua/5.1/moonscript/transform.lua:351>
    (tail call): ?
    (tail call): ?
    /app/packages/share/lua/5.1/moonscript/transform.lua:196: in function </app/packages/share/lua/5.1/moonscript/transform.lua:190>
    (tail call): ?
    (tail call): ?
    /app/packages/share/lua/5.1/moonscript/compile.lua:591: in function </app/packages/share/lua/5.1/moonscript/compile.lua:589>
    (tail call): ?
 [6] >>    print "nothing :("

for loop variables not recognized upon assignment

I noticed that for loop variables are not recognized as being locals when they are the target of assignments.

To illustrate, the following moonscript:

for k,v in ipairs t
  v = v .. 'foo'

Transpiles down to:

for k, v in ipairs(t) do
  local v = v .. 'foo'
end

When I would have expected the following Lua output:

for k, v in ipairs(t) do
  v = v .. 'foo'
end

Reference manual: "This will take everything but the first element:"?

In the reference manual regarding about table slicing:
Any of the slice arguments can be left off to use a sensible default. In this example, if the max index is left off it defaults to the length of the table. This will take everything but the first element:

slice = [item for item in *items[1:]]

"but the first element"?
The code will get all of items, am I right?

Parent's __init is not called on children.

If I make a class with no explicit constructor, the __init method looks like this:

  __init = function(self, ...)
    if _parent_0 then
      return _parent_0.__init(self, ...)
    end
  end,

But if I declare the constructor, it looks like this:

    __init = function(self)
      self[privateKey] = { }
      self[privateKey].IReportPropertyChange_hooks = { }
      self[privateKey].IReportPropertyChange_values = { }
    end,

I obviously see a problem here with the class implementation.
The parent's __init must be called before the child's __init algorithm under all circumstances.
I was counting on that and I've been having headaches with my code not working, thinking that I messed up somewhere. This turned out to be the problem.

Assignment as last expression in function doesn't return

Use case:

cache = {}
func = (key) ->
  value = cache[key]
  if value ~= nil
    value
  else
    cache[key] = value + 1

Expected compilation:

local cache = { }
local func
func = function(key)
  local value = cache[key]
  if value ~= nil then
    return value
  else
    local _result = value + 1
    cache[key] = _result
    return _result
  end
end

Current compilation:

local cache = { }
local func
func = function(key)
  local value = cache[key]
  if value ~= nil then
    return value
  else
    cache[key] = value + 1
  end
end

Strange @__class calling behaviour

class Test
  new: (param) =>
    print param

  clone: =>
    assert @__class == Test
    @__class 'test2'
    Test 'test3'
    c = @__class
    c 'test4'

t = Test 'test1'
t\clone!

prints:

test1
table: 0x12e8c40
test3
test4

Is it a bug? I think calling @__class should work same as assigning @__class to a variable and then calling it.
Btw it translates to

      assert(self.__class == Test)
      self:__class('test2')
      Test('test3')
      local c = self.__class
      return c('test4')

Some suggestions

  1. Your homepage is beautiful. I like it. But the very first snippet of code is a bit too overwhelming for a newcomer.
  2. Maybe you need a mascot, a symbol, an icon to denote MoonScript. Ruby is ruby, Python is snake, Linux is penguin. etc..
  3. Perhaps you might want to grow a beard because mustache means popular. :)
    http://blogs.microsoft.co.il/blogs/tamir/archive/2008/04/28/computer-languages-and-facial-hair-take-two.aspx
  4. If possible, provide a live demo for users to try MoonScript online.
    Something like this http://www.lua.org/demo.html
  5. In the reference manual, I think you assume users/readers will read both MoonScript code and Lua code. Well, that's not the case for me. Providing good description in English is also important. For that matter, the Lua code for table comprehensions and OOP are not something which can be read/understood in a glance.

Compiler crashes with two identifiers left of an equals sign

I've spent more time in static languages, so I occasionally incorrectly add a type before a variable, as in:
string a = ""
Unfortunately this crashes moonc / moon :(.

Steps to reproduce:
$ cat > file.moon
string a = ""
^D

$ moonc file.moon
./file.moon Compile error: .../share/luarocks/share/lua/5.1/moonscript/compile.lua:347: Failed to compile value: {[7] "assign", {"a"}, {{[11] "string", """, ""}}}
stack traceback:
[C]: in function 'error'
.../share/luarocks/share/lua/5.1/moonscript/compile.lua:347: in function 'value'
.../share/luarocks/share/lua/5.1/moonscript/compile.lua:362: in function <.../share/luarocks/share/lua/5.1/moonscript/compile.lua:355>
.../share/luarocks/share/lua/5.1/moonscript/compile.lua:365: in function 'values'
.../luarocks/share/lua/5.1/moonscript/compile/value.lua:108: in function 'chain_item'
.../luarocks/share/lua/5.1/moonscript/compile/value.lua:134: in function <.../luarocks/share/lua/5.1/moonscript/compile/value.lua:92>
(tail call): ?
.../share/luarocks/share/lua/5.1/moonscript/compile.lua:387: in function 'stm'
.../share/luarocks/share/lua/5.1/moonscript/compile.lua:524: in function <.../share/luarocks/share/lua/5.1/moonscript/compile.lua:520>
[1] >> string a = ""

EDIT: I'm on version 0.2.0 release

Sorry to be the bearer of bad news :)

can not use ; to combine two lines?

i = 1
j = i; i+=1
print j

this code will print 2, because moon think , and ; are all the separator of multi-value :(

Isn't semicolon just the separator of sentence?

#!/usr/bin/moon

Hi,

This works with Lua:

#!/usr/bin/lua
print("hi")

But fails with Moonscript:

#!/usr/bin/moon
print "hi"

When run:

./test.lua
hi
./test.moon
/usr/bin/lua: /usr/share/lua/5.1//moonscript/init.lua:24: Parse error: Failed to parse:
 [1] >>    #!/usr/bin/moon (0)
stack traceback:
    [C]: in function 'error'
    /usr/share/lua/5.1//moonscript/init.lua:24: in function 'moon_chunk'
    /usr/lib/luarocks/rocks/moonscript/dev-1/bin/moon:48: in main chunk
    [C]: ?

It would be great if moon also would support shebang on the first line.

Cannot run on Windows, get_opts fails

I'm trying to use moonscript-0.1.0-1 installed with LuaRocks 2.0.4.1 on my Windows 7 computer.

"moonc" or "moon" always fail with the following error, whatever the command-line arguments are:

lua: fatal error: `C:\LuaRocks/share/lua/5.1//alt_getopt.lua:75: attempt to get length of local 'arg' (a nil value)
stack traceback:
        C:\LuaRocks/share/lua/5.1//alt_getopt.lua:75: in function 'get_ordered_opts'
        C:\LuaRocks/share/lua/5.1//alt_getopt.lua:156: in function 'get_opts'
        [string "..."]:11: in main chunk'

Can table comprehension work on tables of key-value pairs?

Suppose I have a table, key is student's name, value is a table of 4 scores.

names_scores = {
["Amy"]: {61, 75, 70, 82}
["Bob"]: {91, 58, 75, 81}
["Cathy"]: {99, 91, 85, 88}
["David"]: {55, 40, 62, 48}
["Eddie"]: {78, 70, 72, 64}
}

Now, I want to generate a new table, key is student's name, value is average score. The resulting table should be like this:
names_avg = {
["Cathy"]: 90.75
["David"]: 51.25
["Amy"]: 72
["Eddie"]: 71
["Bob"]: 76.25
}

I could use for loop to achieve this.
names_avg = {}
for name, scores in pairs names_scores
avg = 0
for i, score in ipairs scores
avg += score
avg /= #scores
names_avg[name] = avg

But, can I use table comprehension to do this kind of thing?

Table literals don't accept variables as keys

In lua I can do this:

b = 'key_b'
t = {
  a = 'a',
  [b] = 'b' ,
}

for k, v in pairs(t) do print(k,v) end

and it prints

a       a
key_b   b

But in MoonScript the following

b = 'key_b'
t =
  a: 'a'
  [b]: 'b' 

print k,v for k, v in pairs t

gives me

a       a
b       b

It is because moonc generates

b = 'key_b'
t = {
  a = 'a',
  b = 'b' ,
}

instead of the following:

b = 'key_b'
t = {
  a = 'a',
  [b] = 'b' ,
}

Interesting enough, moonc does generate the key between [ ] when the key is a
literal (number, table, function or string).

Inability to use decimals

Using 0.1, for example gives a parsing error:

Script:

print 0.1

Error:

/usr/bin/lua: .../.luarocks/share/lua/5.1//moonscript/init.lua:24: Parse error: Failed to parse:
 [1] >>    print 0.1 (0)
stack traceback:
    [C]: in function 'error'
    .../.luarocks/share/lua/5.1//moonscript/init.lua:24: in function 'moon_chunk'
    ...uarocks/lib/luarocks/rocks/moonscript/dev-1/bin/moon:48: in main chunk 
            [C]: ?

Static initializers for classes.

I see this as a much needed feature for the class implementation in Moonscript.
A great thing would be the ability to manipulate the base table through the static initializer.

It will be extremely useful for applying macros to the base class, or when it has to be registered with a function.

As an example, I've had to paste this 10 times and modify 8 parts every time.

    SetStrength: (val) =>
        @str = val

        self\ReportPropertyChange   "str",  val

    AddStrength: (val) =>
        @str += val

        self\ReportPropertyChange   "str",  val

    GetStrength: =>
        return @str

And I'm going to have a bad time if that will ever need to be modified.

Of course, having the static initializers would bring up many more possibilities.

P.S. Please don't use something like "Init" or "Initialize" for the static initializer. In the game I am programming for, those are used for initializing certain table-based object types, and it can't be the only game.

And don't forget about inheritance. Static initializers of the base class should apply to it's children too.

method invocation syntax

Hi!

Imho, back-slash style of method invocation is not eye pleasant. Back-slashes mean escaping of special characters in most languages.

Wonder if we could allow instance:method(...) syntax instead? We have such double meaning for -, which when used immediately before a token means negation, otherwise subtraction. Likewise, MoonScript's instance:method(...) could compile to Lua's instance:method(...), while instance: method(...) could compile like at present, to {instance = method(...)}.

What do you think?

TIA,
--Vladimir

Proposal: shortcut for member assignment in constructor

class Foo
    new: (a, @b, @c = 123) =>
        --some code

works like:

class Foo
    new: (a, b, c = 123) =>
        @b = b
        @c = c
        --some code

There's similar feature in Coffeescript and it's quite useful, many classes has such duplication:

class .Bone
    new: (name, texture_path, z, ..blabla) =>
        @name = name
        @z = z
        @texture_path = texture_path

Unexpected method translation in a with statement

The unexpected behavior is demonstrated here: http://moonscript.org/compiler/#a

In a with statement, if you leave the parenthesis off after a method call to a nested object, the method is invoked on the "with" object, rather than the indicated target. So:
with foo
.prop\send msg

Becomes:
do
local _with_0 = self.foo
_with_0.prop(_with_0:send(msg))
return _with_0
end

But,
with foo
.prop\send(msg)

Becomes:
do
local _with_0 = self.foo
_with_0.prop:send(msg)
return _with_0
end

In-table class declaration

Hi! Feature request here. I use "return _M"-style module implementation (it's actually preferred way) with classes:

_M = {}
class Sprite
  --...
_M.Sprite = Sprite
return _M

So _M.Sprite = Sprite is really boilerplate. Could you please extend class declaration syntax like this? -

class _M.Sprite
  --...

Flaws in +=, -=, *= and /=

It took me a lot of time to track down the source of a problem, and I came to this:

a -= b - c
Produces the following:
a = a - b - c
While, to me, it should obviously produce:
a = a - (b - c)

Same goes for other listed operators.

moonscript code has no comments at all!

Hi, reading moonscript code, I noticed there are no comments at all. That's pretty troublesome for one that wishes to change things up. Some comments inside the code could be very helpful for the curious developer.

Multiple assignment of same value

The following is possible in lua, but causes a parse error in MoonScript. It could be handy, as I use the pattern in lua frequently.

a = b = c

Which sets both a and b to c.

For an actual use case,

someTable.name = localValue = somethingElse

Which, ideally would turn into

local localValue
someTable.name = localValue = somethingElse

or something along those lines.

export foo = bar

atm you must do export foo; foo = bar
also export foo,bar,baz = 1,2,3 should work here
(IMO, do with it what you will)
btw great job

'\' is weird syntax why not keep ':' and '='?

I know MoonScript replace ':' with '' to call an instance method, but I think it's sooooooo weird.
As most language, '' meant escape. So, try to read:
file\read
vs
file.read
vs
file:read

When reading code, I think the first way is hardest.

and try these code:

obj1\method2 "\01\002\010"

And, I don't think so use ':' to assigning a value to key in a table is better than '='.

So, why not keep ':' and '=' behavior?
It's bad idea to change the operator behavior, it make hard to port code between Lua and Moonscript,
also make people more confused.

@

Hi!

The following expression foo @ meaning calling foo with current self doesn't compile. Bug or feature?

TIA,
--Vladimir

extends example

Hi!

I'd like to extend a moonscript class with an ordinary metatable. Say,
Base = {__index: ...} class Foo extends Base

What should be Base for extends to work properly? Or, how can I manually chain them both?

TIA,
--Vladimir

static class variable

I read through the reference manual. It seems that moonscript's doesn't support the semantics of static class variable, which is common in most OOP languages( ex. C++, Java).

I come up with my own implementation as the following. If anyone know a better way do it, please leave comments. Thank you.

class Stone
  static: { scount: 0 }
  new: =>
    @static.scount+=1
    print 'scount = ', @static.scount

s1= Stone()                                                                
s2= Stone()
s3= Stone()
s4= Stone()
s5= Stone()
print 'total stones = ', Stone.static.scount

Incorrect error line number sometimes with rewrite_traceback

I have a C program that runs a Lua file via Lua C API (LuaJIT actually). This Lua file loads Moonscript files this way:

-- it's init.lua
require "moonscript"
require "moonscript.errors"
local textures = assert(require 'src/textures')  --it's .moon file

To have nice traceback we do like in bin/moon:

local function pb(err)
   local trace = debug.traceback()
   print(moonscript.errors.rewrite_traceback(trace, err))
   os.exit(1)
end
xpcall(run, pb) --"run" is some local function that calls other functions from .moon files
  1. When i read the docs i thought that if moonloader is used (is it in our case?), trace is automatically rewritten, but seems like it's not (that's why we used xpcall wrapper). Are we doing something wrong?
  2. In some cases error lines are reported incorrectly. I'm sending you an e-mail with some example code (it's code from some project that i prefer not to publish), please check it. It's wrapped with if false with error call at bottom so you can run it without other required file. This is obviously not handled by our xpcall wrapper (error is called at include time) but reported line is wrong too, maybe you could check how parser handles such file please..

Scope blocks

In lua, you can introduce new scope easily with do ... end, it would be nice to do the same in MoonScript.

Ideally, I want something like this to work:

myFunction = do
    hidden = { a: 1, b: 2, c: 3 }
    (key) -> hidden[key]

Which would compile into something along the lines of this:

local myFunction
do
    local hidden = { a = 1, b = 2, c = 3 }
    myFunction = function (key)
        return hidden[key]
    end
end

Or

local myFunction = (function ()
    local hidden = { a = 1, b = 2, c = 3 }
    return function (key)
        return hidden[key]
    end
end)()

Noop block or statement

Statements like

if blah
    -- indented
else
    bleh

are invalid at the moment. So if one wants to e.g. quickly comment out the line in such block (or even to have an empty block), one have to add some stub code and it can't be just nil if one doesn't want to return cause it translates to return nil.
So, maybe translate

if foo
    --

to

if foo then
end

or introduce some noop statement like ; (; is already allowed, maybe reuse it?) or pass (like in Python)

Word quoting operator

It would be a great addition to have a word quoting operator which splits on whitespace, like qw{} in Perl or %w{} from Ruby.

on ubuntu fails to build

on ubuntu 10.04 LTS , i did
apt-get install luarocks
luarocks install lpeg
luarocks install luafilesystem
luarocks install alt-getopt
luarocks build http://moonscript.org/rocks/moonscript-0.1.0-1.rockspec

everything is done successfully.NOW. typing "moon" on bash prompt gives following error

/usr/bin/lua: /usr/local/share/lua/5.1//moonscript/errors.lua:2: module 'moonscript' not found:
no field package.preload['moonscript']
no file '/usr/local/share/lua/5.1//moonscript.lua'
no file '/usr/local/share/lua/5.1//moonscript/init.lua'
no file '/root/.luarocks/share/lua/5.1//moonscript.lua'
no file '/root/.luarocks/share/lua/5.1//moonscript/init.lua'
no file '/usr/local/share/lua/5.1//moonscript.lua'
no file '/usr/local/share/lua/5.1//moonscript/init.lua'
no file '/root/.luarocks/share/lua/5.1//moonscript.lua'
no file '/root/.luarocks/share/lua/5.1//moonscript/init.lua'
no file '/usr/share/lua/5.1//moonscript.lua'
no file '/usr/share/lua/5.1//moonscript/init.lua'
no file './moonscript.lua'
no file '/usr/local/share/lua/5.1/moonscript.lua'
no file '/usr/local/share/lua/5.1/moonscript/init.lua'
no file '/usr/local/lib/lua/5.1/moonscript.lua'
no file '/usr/local/lib/lua/5.1/moonscript/init.lua'
no file '/usr/share/lua/5.1/moonscript.lua'
no file '/usr/share/lua/5.1/moonscript/init.lua'
no file '/usr/local/lib/lua/5.1//moonscript.so'
no file '/root/.luarocks/lib/lua/5.1//moonscript.so'
no file '/usr/local/lib/lua/5.1//moonscript.so'
no file '/root/.luarocks/lib/lua/5.1//moonscript.so'
no file './moonscript.so'
no file '/usr/local/lib/lua/5.1/moonscript.so'
no file '/usr/lib/lua/5.1/moonscript.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/usr/local/share/lua/5.1//moonscript/errors.lua:2: in main chunk
[C]: in function 'require'
...r/local/lib/luarocks/rocks/moonscript/dev-1/bin/moon:4: in main chunk
[C]: ?

HERE, why there are two forward slashes (//) in the debug output "/usr/local/share/lua/5.1//moonscript/errors.lua" ( see after /usr/local/share/lua/5.1 )

ALSO ADDITIOALLY I DID, ls /usr/local/share/lua/5.1/moonscript
compile compile.lua data.lua dump.lua errors.lua parse.lua transform.lua types.lua util.lua version.lua
THERE IS NO moonscript.lua here.

block comments

Hi!

How do I do block comments in moonscript? Apart from their vanilla usage, they are handy in switching off blocks of code while debugging.

TIA,
--Vladimir

An operator for table insertion

A shortcut for tbl[#tbl + 1] = item would be handy, it quite frequently appears in the code. What do you think?
Something like tbl << item maybe

declarations

Hi!

Noticed the absense (or am unaware) of the following patterns:

  • just declaration of a number of variables: local foo, bar -- what would be moonscript for this?
  • combined declaration and assignment to a global: export foo = () -> 'bar'. Allowed is first to export foo and then foo = () -> 'bar'. In modules it's natural to define local variables and functions and then export them at the bottom of the file.

Please, comment

TIA,
--Vladimir

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.