Page 4 of 4

Re: MoonScript & love

Posted: Wed Aug 28, 2013 12:35 am
by szensk

Code: Select all

moonc -w
Watch a directory and output Lua code. It just works™. Moonscript 0.2.4 has fixed a number of quirks with the language itself. It's quite nice as a terse & higher-level Lua. Compiler errors could be more specific.

ie, this will do exactly what you expect:

Code: Select all

color = {128, 46, 222}
radius = 50
inc = 10

love.update = (dt) ->
	radius += (inc * dt)
	if radius > 200
		inc = -10
	elseif radius < 50
		inc = 10

love.draw = ->
	love.graphics.setColor color
	love.graphics.circle 'fill', 400, 300, radius, 100
it outputs:

Code: Select all

local color = {
  128,
  46,
  222
}
local radius = 50
local inc = 10
love.update = function(dt)
  radius = radius + (inc * dt)
  if radius > 200 then
    inc = -10
  elseif radius < 50 then
    inc = 10
  end
end
love.draw = function()
  love.graphics.setColor(color)
  return love.graphics.circle('fill', 400, 300, radius, 100)
end
which can be ran within Love, as normal.

Re: MoonScript & love

Posted: Tue Sep 24, 2013 10:25 pm
by qaisjp
szensk wrote:

Code: Select all

moonc -w
Watch a directory and output Lua code. It just works™. Moonscript 0.2.4 has fixed a number of quirks with the language itself. It's quite nice as a terse & higher-level Lua. Compiler errors could be more specific.

ie, this will do exactly what you expect:

Code: Select all

color = {128, 46, 222}
radius = 50
inc = 10

love.update = (dt) ->
	radius += (inc * dt)
	if radius > 200
		inc = -10
	elseif radius < 50
		inc = 10

love.draw = ->
	love.graphics.setColor color
	love.graphics.circle 'fill', 400, 300, radius, 100
it outputs:

Code: Select all

local color = {
  128,
  46,
  222
}
local radius = 50
local inc = 10
love.update = function(dt)
  radius = radius + (inc * dt)
  if radius > 200 then
    inc = -10
  elseif radius < 50 then
    inc = 10
  end
end
love.draw = function()
  love.graphics.setColor(color)
  return love.graphics.circle('fill', 400, 300, radius, 100)
end
which can be ran within Love, as normal.
I already know about and use all of that, I meant integrating it in love (so you can debug errors at the exact position in moonscript)

Re: MoonScript & love

Posted: Tue Jan 02, 2018 1:44 am
by jojomickymack
Like the previous reply, I feel like bumping this thread, which was started 7 years ago, might be some kind of trespass, but I am just baffled that combining love and moonscript isn't something everyone is trying to do. This is probably even simpler in linux, but I was able to (using the 32bit windows distribution of love2d) just drop the moonscript.dll file into my love2d directory and then by using a main.lua file consisting of

Code: Select all

require 'moonscript'
require 'mymoonfile'
and having a mymoonfile.moon right there, run the project using love. The only issue (on windows) is that there's only a 32 bit binary distribution of moonscript and I'm sure most users would have the 64bit love installed.

For distribution, you could surely bundle your own 32bit love2d with the moonscript.dll included, or you could just compile your finished project to lua once it's complete.

The main thing I'm confused about at this point is why more people aren't compelled to do this?

Re: MoonScript & love

Posted: Tue Jan 02, 2018 2:07 am
by Sir_Silver
For me, it's because if I want to write something in Lua, it's pretty easy to just do that and not have to bother with anything more than that.

Re: MoonScript & love

Posted: Tue Jan 02, 2018 7:27 pm
by hlship
I have some Makefiles that compile the MoonScript down to Lua and package up my game folder.

Re: MoonScript & love

Posted: Tue Jan 02, 2018 8:56 pm
by Tricky
MoonScript is a whitespace sensitive language. This means that instead of using do and end (or { and }) to delimit sections of code we use line-breaks and indentation.
Ooh, one of the things of which I am still not sure if I should love or hate Python for that. So I don't know if I should love or hate MoonScript for that either...

I am however glad about features like

Code: Select all

a = 1
a += 1
print (a) -- prints 2
as that is something I really miss in Lua. (Would a++ also work?)
I am also not sure if I am happy about auto-local inside functions.... That has a bit to do with the way Lua has been set up. Lua needs no declarations aside from locals (except maybe for tables as they require a tabvar={} command) often forcing me to "declare" globals inside functions. Now as a Pascal programmer (although my skills in Pascal are a bit outdated and rusty now), I wouldn't mind it, and there any var declared inside a function or procedure (procedures in Pascal are required when the function returns no value. A bit similar to void functions in C) is also automatically a local, but since all globals needed to be declared anyway, the trouble I see in MoonScript is automatically non-existent in Pascal. Well, I guess the same goes for Go. It's been too long ago I tried to code anything at all in C.

So I guess it has its pros and its cons. MoonScript code is in most cases definitely shorter, which can be a plus.
I think I'll stick with standard Lua, but I can see how some people might prefer MoonScript over Lua, as the cons are most of all my personal preference in this.