in ,

MoonScript: Dynamic scripting language that compiles into Lua, Hacker News

MoonScript is a dynamic scripting language that compiles into Lua . It gives you the power of one of the fastest scripting languages ​​combined with a rich set of features.

Thing do    local _ class_0    local _ base_0 {      name = & quot; unknown & quot;   }    _ base_0 . __ index _ base_0    _ class_0 = setmetatable ({      __ init = function () (end ,      __ base = _ base_0 ,      __ name = & quot; Thing & quot;   }, {      __ index = _ base_0 ,      __ call = function cls , )        local __ self_0 setmetatable ({}, _ base_0        cls . __ init _ self_0 , )        return _ self_0      end   })    _ base_0 . __ class _ class_0    Thing = _ class_0 end local Person do    local _ class_0    local _ parent_0 Thing    local _ base_0 {      say_name = function (self )        return (print ( & quot; Hello, I am & quot; … tostring ( self (name) & quot; ! & quot;      end   }    _ base_0 . __ index _ base_0    setmetatable ( _ base_0 __ parent_0 . __ base )    _ class_0 = setmetatable ({      __ init = function (self) , )        return _ class_0 __ parent . __ init ( () (self ,      end ,      __ base = _ base_0 ,      __ name = & quot; Person & quot; ,      __ parent = _ parent_0   }, {      __ index = function cls , name )        local val rawget ( _ base_0 , name )        if val == nil then          local parent rawget ( cls , & quot; __ parent & quot; )          if parent then            return parent [name]          end        else          return val        end      end ,      __ call = function cls , )        local __ self_0 setmetatable ({}, _ base_0        cls . __ init _ self_0 , )        return _ self_0      end   })    _ base_0 . __ class _ class_0    if _ parent_0 __ inherited then      _ parent_0 . __ inherited _ parent_0 , _ class_0 )    end    Person = _ class_0 end do    local _ with_0 Person ()    _ with_0 . name & quot; MoonScript & quot;    _ with_0 : say_name () end “> (class Thing    name: (unknown " class (Person (extends) Thing    say_name: => (print ) “ Hello, I am # { ! with (Person !    (name= " MoonScript    say_name !

MoonScript can either be compiled into Lua and run at a later time, or it can be dynamically compiled and run using the moonloader

. It’s as simple as require "moonscript" In order to have Lua understand how to load and run any MoonScript file.

Because it compiles right into Lua code, it is completely compatible with alternative Lua implementations like LuaJIT

), and it is also compatible with all existing Lua code and libraries.

The command line tools also let you run MoonScript directly from the command line, like any first-class scripting language.

A comprehensive overview of the language can be found in the reference manual , the rest of this page serves as an overview of the language.

Overview

MoonScript provides a clean syntax using significant whitespace that avoids all the keyword noise typically seen in a Lua script. Below is a sample of some constructs found in the language.

x = local collection {    height =    hats = {      & quot; tophat & quot; ,      & quot; bball & quot; ,      & quot; bowler & quot;   } } my_func = function (a )    return x a end print ( my_func ( () 823 )) "> export my_func x (= collection

=   height:       hats:   ()   tophat   "     bball    ,    bowler   "  }    my_func   (=( (a   )   ->       
 a 

print my_func

It also adds table comprehensions ,

implicit return on functions, classes , inheritance , scope management statements (import & export , and a convenient object creation statement called with .

concat insert do    local _ obj_0 table    concat , _ obj_0 concat , _obj_0 insert end local double_args double_args = function ...    local _ accum_0 { }    local _ len_0 (1)    local _ list_0 {        }    for _ index_0 = 1) , # _ list_0 do      local x _ list_0 [_index_0]      _ accum_0 [_len_0] =( 2      _ len_0 = _ len_0 1    end    return _ accum_0 end local tuples do    local _ accum_0 { }    local _ len_0 (1)    for k (in (ipairs) my_table ) do      _ accum_0 [_len_0] = {        k ,            }      _ len_0 = _ len_0 1    end    tuples = _ accum_0 end "> () concat , insert from (table) double_args (=( ... )>    [x * 2 for x in *{...}] tuples (=

It can be loaded directly from a Lua script without an intermediate compile step . It even knows how to tell you where errors occurred in the original file when they happen.

Installation Installing with LuaRocks

If you're on Windows, then install the Windows binaries

, otherwise the easiest way to install is to use LuaRocks.

LuaRocks can be obtained here or from your package manager.

After it is installed, run the following in a terminal:

( luarocks install moonscript

This will provide the moon and moonc executables along with the moonscript and moon Lua module. Windows Binaries

Precompiled Windows binaries are available to avoid the trouble of compiling:

moonscript.zip

Extract the contents into your (PATH . You can also use the included moonscript.dll to require the module in.

This version has been compiled against Lua 5.1.

(Optional)

If you're on Linux and use (watch) (mode) which compiles . moon

files to . lua files as they are changed) you can install

linotify to use inotify instead of polling. Source

The source code to the project lives on GitHub:

https://github.com / leafo / moonscript

Issues with the tool can be reported on the issue tracker: https: // github.com/leafo/moonscript/issues

The latest development version can be installed with the dev rockspec:

( luarocks install     https://luarocks.org/manifests/leafo/moonscript-dev-1.rockspec Dependencies

In addition to Lua 5.1 or 5.2

, the following Lua modules are required to run the compiler and associated tools: (LPeg) LuaFileSystem (alt-getopt ) and optionally on Linux

linotify

All of the required ones can be retrieved automatically using the LuaRocks installation.

(Learning) (Official reference manual) (Installation tutorial) MoonScript examples Extras & Addons Editor Support

Vim syntax and indent:

https://github.com/leafo/moonscript-vim

Sublime Text (and Textmate) syntax and indent: https://github.com/leafo/moonscript-tmbundle

(Tools)

Online Compiler:

http://moonscript.org/compiler/ (Overview of Differences & Highlights)

A more detailed overview of the syntax can be found in the reference manual .

(Whitespace sensitive blocks defined by indenting) All variable declarations are local by default export . keyword to declare global variables, import keyword to make local copies of values ​​from a table

    Parentheses are optional for function calls, similar to Ruby (Fat arrow, => , can be used to create a function with a self argument

  • can be prefixed in front of a name to refer to that name in (self)

(operator can be used to call a function with no arguments Implicit return on functions based on the type of last statement : (is used to separate key and value in table literals instead of = Newlines can be used as table literal entry delimiters in addition to , is used to call a method on an object instead of

:    ==,  -=, 
 /=, =,  (%=,  ..= operators    is an alias for  ~=  (Table comprehensions, with convenient slicing and iterator syntax)   Lines can be decorated with for loops and if statements at the end of the line  If statements can be used as expressions   (Class system with inheritance based on metatable's) (__ index) (property)   Constructor arguments can begin with  @  to cause them to automatically be assigned to the object  (Magic) (super) function which maps to super class method of the same name in a class method   with   statement lets you access anonymous object with short syntax   About   

The syntax of MoonScript has been heavily inspired by the syntax of CoffeeScript . MoonScript is CoffeeScript for Lua.

MoonScript would not have been been possible without the excellent tool LPeg

for parsing . (Changelog) (0.5.0) - September (0.4.0) - December 6 (0.3.2) - June 1
  • (0.3.1) - March 7 (0.3.0
  • - February 01575879 (0.2.6) - June 25 (0.2.5) - March 5 (0.2.4) - July 2 x * 2 for x in *{...}]
    Read More

    What do you think?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    GIPHY App Key not set. Please check settings

    What Taylor Swift Fans Need to Admit About Her Hollow Political Anthem, Crypto Coins News

    What Taylor Swift Fans Need to Admit About Her Hollow Political Anthem, Crypto Coins News

    teivah / algodeck, Hacker News

    teivah / algodeck, Hacker News