The "I Love Lua, but..." post

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: The "I Love Lua, but..." post

Post by Jasoco »

Syntactic bloat, shmyntactic bloat. It's all about saving time. I'd rather save typing strokes even if it means putting all love functions in global two keystroke shortcuts. WHICH I DO. :joker:
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: The "I Love Lua, but..." post

Post by BlackBulletIV »

Actually, the compound operators (not prefix/postfix however) do add something: you don't have to reference the same object twice. Theoretically

Code: Select all

w.x.y.z += 3
is father than

Code: Select all

w.x.y.z = w.x.y.z + 3
because Lua has to look up w for 'x', w.x for 'y', w.x.y for 'z' twice until it gets what you're looking for.

As for the "then" thing, I don't mind much, I prefer not typing it though. Ruby handles that one fine:

Code: Select all

if x == 3
  code
end
or

Code: Select all

code if x == 3
And I like the "end"s, I find it much easier to outline blocks of code with my eyes.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

Re: The "I Love Lua, but..." post

Post by Mud »

BlackBulletIV wrote:As for the "then" thing, I don't mind much, I prefer not typing it though. Ruby handles that one fine:

Code: Select all

if x == 3
  code
end
I once patched Lua make then after if, and do after while and for, optional, just to see how invasive a patch it would be. Turns out it's a few lines of code, so I argued on the Lua mailing list for this change to be made to the language. This was the answer:
Although then was completely redundant in Lua 4, this changed when the grammar was changed to allow call and assignment statements to start with a parenthesized expression; this change made the ; statement terminator only semi-optional. The following could not be written without then because ; can only go after a statement; without the then it would be ambiguous:

Code: Select all

  if x then (funcs[x] or default_func)() end
Moreover, do cannot be optional in a for or while statement because the block could itself start with a do statement:

Code: Select all

 while x > 100 do
    do 
      local y = f(x)
      g(y)
      h(y)
    end
    -- ...
  end
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: The "I Love Lua, but..." post

Post by BlackBulletIV »

Interesting. I don't quite get the first one, but anyway. The main problem now I guess, is that they have to maintain backwards compatibility with grammar.
User avatar
sharpobject
Prole
Posts: 44
Joined: Fri Mar 18, 2011 2:32 pm
Location: California

Re: The "I Love Lua, but..." post

Post by sharpobject »

Jasoco wrote:Syntactic bloat, shmyntactic bloat. It's all about saving time. I'd rather save typing strokes even if it means putting all love functions in global two keystroke shortcuts. WHICH I DO. :joker:
Sure, but you can do that in the editor instead of exposing people who read your code to exactly what keystrokes you used to produce it. You could also have your editor expand "foo += " to "foo = foo + " :o
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: The "I Love Lua, but..." post

Post by Robin »

BlackBulletIV wrote:The main problem now I guess, is that they have to maintain backwards compatibility with grammar.
No, it's that it would allow ambiguous syntax. In which case it's not at all obvious what the compiler should do. These situations cause debugging to be very hard, because the code doesn't look wrong, and there is probably not even an error at that exact location.
Help us help you: attach a .love.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: The "I Love Lua, but..." post

Post by BlackBulletIV »

sharpobject wrote:You could also have your editor expand "foo += " to "foo = foo + " :o
Hey, that's a cool idea!
Robin wrote:
BlackBulletIV wrote:The main problem now I guess, is that they have to maintain backwards compatibility with grammar.
No, it's that it would allow ambiguous syntax. In which case it's not at all obvious what the compiler should do. These situations cause debugging to be very hard, because the code doesn't look wrong, and there is probably not even an error at that exact location.
Sorry, I probably said that without giving the context for what I was thinking. I was thinking of how impossible it would to switch to something like Ruby has, now that Lua is mature; for example begin ... end, and all that stuff. If that happened, it would cause compatibility problems all over the place.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: The "I Love Lua, but..." post

Post by vrld »

BlackBulletIV wrote:I don't quite get the first one, but anyway.
It's because the code

Code: Select all

if x (funcs[x] or default_func)() end
can be understood in two ways:
  1. if x then (funcs[x] or default_func)() end
  2. Invoke the function x with the argument funcs[x] or default_func, which returns a function that is then invoked. Then do nothing, i.e.:

    Code: Select all

    function x(other_func)
        return function()
            other_func('default', 'arguments') ~= 'foo'
        end
    end
    
    if x(funcs[x] or default_func)() then end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: The "I Love Lua, but..." post

Post by bartbes »

I'll just leave this here:

Code: Select all

--main.lua
table.insert(package.loaders, function(name)
	name = name:match("^meta%-(.+)$")
	if not name then return nil end
	local tokenized_name = name:gsub("%.", "/") .. ".lua"
	if not love.filesystem.exists(tokenized_name) then
		return nil
	end
	local contents = love.filesystem.read(tokenized_name)
	do --replacements
		contents = contents:gsub("([%w%.:%[%]]+)%s*%+=", "%1 = %1 + ")
		contents = contents:gsub("([%w%.:%[%]]+)%s*%-=", "%1 = %1 - ")
		contents = contents:gsub("([%w%.:%[%]]+)%+%+", "%1 = %1 + 1")
		contents = contents:gsub("([%w%.:%[%]]+)%-%-", "%1 = %1 - 1")
	end
	print(contents)
	return loadstring(contents)

end)

require "meta-game"

--game.lua
function love.load()
	timer = 0
	frames = 0
end

function love.update(dt)
	timer += dt
	frames++
end

function love.draw()
	love.graphics.print("Time: " .. timer, 50, 50)
	love.graphics.print("Frames: " .. frames, 50, 64)
	love.graphics.print("Average FPS: " .. math.floor(frames/timer), 50, 78)
end
User avatar
ishkabible
Party member
Posts: 241
Joined: Sat Oct 23, 2010 7:34 pm
Location: Kansas USA

Re: The "I Love Lua, but..." post

Post by ishkabible »

List of my issues with Lua(many of which have been said):
*no += like operators, and no ++/-- operators either
*no control over for loops, sometimes i want a different condition than <= or a more complex increment than addition
*globals by default is really annoying, locals by defualt would be equally annoying. i can't tell you how many bugs i have had becuase i mistyped a variable
*no bit-wise operators, this doesn't effect me very often but when it dose i hate it.
*arrays start at 1, WTF!! they should start at 0!!
*no default OO mechanisms, i would like to have a means to literally write a class
*no type dispatching, i hate writing all those type checked functions that do different things for different types. i want function overloads
*'tonumber' dose not support a __tonumber meta method. what if you want to make a number class of sorts. i made a ratio class a while back and i wanted to be able to convert to number, i settled for a method instead.
*~=...WTF what happened to !=?
*and, or, not ... i don't like them i prefer &&, ||, ! instead
however all and all i love Lua, it's my second favorite language. it basically rocks. meta-methods are sexy, Lua is fast, Lua is cool.

edit: wtf how do you use the List BBcode?
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests