The "I Love Lua, but..." post
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: The "I Love Lua, but..." post
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.
- 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
Actually, the compound operators (not prefix/postfix however) do add something: you don't have to reference the same object twice. Theoretically
is father than
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:
or
And I like the "end"s, I find it much easier to outline blocks of code with my eyes.
Code: Select all
w.x.y.z += 3
Code: Select all
w.x.y.z = w.x.y.z + 3
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
Code: Select all
code if x == 3
Re: The "I Love Lua, but..." post
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: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
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:
Moreover, do cannot be optional in a for or while statement because the block could itself start with a do statement:Code: Select all
if x then (funcs[x] or default_func)() end
Code: Select all
while x > 100 do do local y = f(x) g(y) h(y) end -- ... end
- 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
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.
- sharpobject
- Prole
- Posts: 44
- Joined: Fri Mar 18, 2011 2:32 pm
- Location: California
Re: The "I Love Lua, but..." post
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 + "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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
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.BlackBulletIV wrote:The main problem now I guess, is that they have to maintain backwards compatibility with grammar.
Help us help you: attach a .love.
- 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
Hey, that's a cool idea!sharpobject wrote:You could also have your editor expand "foo += " to "foo = foo + "
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.Robin wrote: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.BlackBulletIV wrote:The main problem now I guess, is that they have to maintain backwards compatibility with grammar.
Re: The "I Love Lua, but..." post
It's because the codeBlackBulletIV wrote:I don't quite get the first one, but anyway.
Code: Select all
if x (funcs[x] or default_func)() end
- if x then (funcs[x] or default_func)() end
- 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
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: The "I Love Lua, but..." post
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
- ishkabible
- Party member
- Posts: 241
- Joined: Sat Oct 23, 2010 7:34 pm
- Location: Kansas USA
Re: The "I Love Lua, but..." post
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?
*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?
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 10 guests