I'm happy to announceMoonScript version 0.2.4, the CoffeeScript inspiredlanguage 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 areusing MoonScript you canemail me or contact me ontwitter.
a-b compiles toa - b and nota(-b) anymore).moon library is no longer sets a global variable and instead returnsthe module. Your code should now be:moon=require"moon"\n in the generated code.x="helloworld"moonscript.base module. It’s a way of including themoonscriptmodule without automatically installing the moonloader.importa,bc,dfromzb is not longer treated as self assign in{ a : b }nil instead of throwing error, as described indocumentationmoon.mixin where it did not work as describedAs mentioned above a lot has changed about the generated code. Here’s a quickoverview with examples. All of these address special cases, if it’s notpossible to write the optimized form the original form will be generated.
Reusing locals:
input={}{:a,:b,d:{one,two,}}=inputlocalinput={}locala,b,one,twodolocal_obj_0=inputa,b,one,two=_obj_0.a,_obj_0.b,_obj_0.d[1],_obj_0.d[2]endlocalinput={}locala,b,one,twoa,b,one,two=input.a,input.b,input.d[1],input.d[2]No unnecessarywith variable:
withthing="hello!"print\upper!dolocal_with_0="hello!"localthing=_with_0print(_with_0:upper())enddolocalthing="hello!"print(thing:upper())endRemove unnecessary inheritance code with simple classes:
classHellonew:=>print"hello"localHellodolocal_parent_0=nillocal_base_0={}_base_0.__index=_base_0if_parent_0thensetmetatable(_base_0,_parent_0.__base)endlocal_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_0thenreturn_parent_0[name]elsereturnvalendend,__call=function(cls,...)local_self_0=setmetatable({},_base_0)cls.__init(_self_0,...)return_self_0end})_base_0.__class=_class_0if_parent_0and_parent_0.__inheritedthen_parent_0.__inherited(_parent_0,_class_0)endHello=_class_0endlocalHellodolocal_base_0={}_base_0.__index=_base_0local_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_0end})_base_0.__class=_class_0Hello=_class_0endComprehensions reuse local, don’t make temporary function:
things={}x=[aforain*things]localthings={}localx=(function()local_accum_0={}local_len_0=1local_list_0=thingsfor_index_0=1,#_list_0doa=_list_0[_index_0]_accum_0[_len_0]=a_len_0=_len_0+1endreturn_accum_0end)()localthings={}localxdolocal_accum_0={}local_len_0=1for_index_0=1,#thingsdoa=things[_index_0]_accum_0[_len_0]=a_len_0=_len_0+1endx=_accum_0endAccumulated loops also don’t use temporary function:
y=whilecheck_something!math.random!localy=(function()local_accum_0={}local_len_0=1whilecheck_something()do_accum_0[_len_0]=math.random()_len_0=_len_0+1endreturn_accum_0end)()localydolocal_accum_0={}local_len_0=1whilecheck_something()do_accum_0[_len_0]=math.random()_len_0=_len_0+1endy=_accum_0endSome 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 Sun Oct 8 13:02:35 2023 bySitegenmastodon.social/@leafo