I'm happy to announce MoonScript version 0.2.4, the CoffeeScript inspired language that compiles to Lua. It’s been about 5 months since the last release.
As always, if you've got any questions or want to tell me about how you are using MoonScript you can email me or contact me on twitter.
a-b compiles to a - b and not
a(-b) anymore).moon library is no longer sets a global variable and instead returns
the module. Your code should now be:moon = require "moon"
\n in the generated code.x = "hello
world"
moonscript.base module. It’s a way of including the moonscript
module without automatically installing the moonloader.import a, b
c, d from z
b is not longer treated as self assign in { a : b }nil instead of throwing error, as described in
documentationmoon.mixin where it did not work as describedAs mentioned above a lot has changed about the generated code. Here’s a quick overview with examples. All of these address special cases, if it’s not possible to write the optimized form the original form will be generated.
Reusing locals:
input = { }
{ :a, :b, d: { one, two, } } = input
localinput={}
locala,b,one,two
do
local_obj_0=input
a,b,one,two=_obj_0.a,_obj_0.b,_obj_0.d[1],_obj_0.d[2]
end
localinput={}
locala,b,one,two
a,b,one,two=input.a,input.b,input.d[1],input.d[2]
No unnecessary with variable:
with thing = "hello!"
print \upper!
do
local_with_0="hello!"
localthing=_with_0
print(_with_0:upper())
end
do
localthing="hello!"
print(thing:upper())
end
Remove unnecessary inheritance code with simple classes:
class Hello
new: => print "hello"
localHello
do
local_parent_0=nil
local_base_0={}
_base_0.__index=_base_0
if_parent_0then
setmetatable(_base_0,_parent_0.__base)
end
local_class_0=setmetatable({
__init=function(self)
returnprint("hello")
end,
__base=_base_0,
__name="Hello",
__parent=_parent_0
},{
__index=function(cls,name)
localval=rawget(_base_0,name)
ifval==niland_parent_0then
return_parent_0[name]
else
returnval
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_0and_parent_0.__inheritedthen
_parent_0.__inherited(_parent_0,_class_0)
end
Hello=_class_0
end
localHello
do
local_base_0={}
_base_0.__index=_base_0
local_class_0=setmetatable({
__init=function(self)
returnprint("hello")
end,
__base=_base_0,
__name="Hello"
},{
__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
Hello=_class_0
end
Comprehensions reuse local, don’t make temporary function:
things = {}
x = [a for a in *things]
localthings={}
localx=(function()
local_accum_0={}
local_len_0=1
local_list_0=things
for_index_0=1,#_list_0do
a=_list_0[_index_0]
_accum_0[_len_0]=a
_len_0=_len_0+1
end
return_accum_0
end)()
localthings={}
localx
do
local_accum_0={}
local_len_0=1
for_index_0=1,#thingsdo
a=things[_index_0]
_accum_0[_len_0]=a
_len_0=_len_0+1
end
x=_accum_0
end
Accumulated loops also don’t use temporary function:
y = while check_something!
math.random!
localy=(function()
local_accum_0={}
local_len_0=1
whilecheck_something()do
_accum_0[_len_0]=math.random()
_len_0=_len_0+1
end
return_accum_0
end)()
localy
do
local_accum_0={}
local_len_0=1
whilecheck_something()do
_accum_0[_len_0]=math.random()
_len_0=_len_0+1
end
y=_accum_0
end
Some updates for libraries written in MoonScript:
magick, LuaJIT FFI bindings to ImageMagickweb_sanitize, HTML sanitizationLudum Dare happened again, and I wrote another game in MoonScript:
Thanks to everyone who provided feedback for this release. See you next time.
leafo.net · Generated Tue Dec 16 16:18:13 2025 by Sitegen mastodon.social/@leafo