Page 3 of 6
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 2:33 am
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.
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 6:24 am
by BlackBulletIV
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.
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 7:29 am
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:
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
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 7:42 am
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.
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 8:32 am
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.
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 + "
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 8:55 am
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.
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 10:47 am
by BlackBulletIV
sharpobject wrote:You could also have your editor expand "foo += " to "foo = foo + "
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.
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 11:13 am
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:
- 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
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 11:48 am
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
Re: The "I Love Lua, but..." post
Posted: Sun May 01, 2011 4:55 pm
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?