Page 3 of 4
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 5:56 pm
by Jasoco
I didn't even realize kikito posted his own. Ignore mine. It sucks.
Anyway, what does def do versus function? And is there any benefit to using an underscore _ in the for loop?
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 5:58 pm
by bartbes
def vs function, well def doesn't exist.
_ vs i/k, no difference, but it tells people reading your source that you're not using it. (some languages actually see _ as an ignore keyword)
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:01 pm
by Jasoco
Oh, then why does kikito's code have def instead? Is that not valid code?
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:02 pm
by bartbes
It is not.
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:03 pm
by Robin
To clarify: def is in Python or Ruby what is function in Lua. I take it kikito was mistaken with one of those.
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:04 pm
by Jasoco
Oh. Good. Darn, I thought it was some new way of doing things I didn't know about.
Why can't all languages be the same? lol
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:05 pm
by bartbes
Because then they'd all suck.
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 6:22 pm
by Robin
... and you'd end up with PHP.
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 11:13 pm
by Luiji
The point of having different programming languages is so that they are different and better then each other. Personally, I wish there were less. I've learned 20 programming languages (at least), and I still haven't found the perfect one. Thus, I'm creating my own VM, etc., but that's besides the point.
So, _ tells programmers that it is ignored. That's pretty simple. It would be nice if Lua took that as a "black hole" and deleted anything sent to it (like on Linux when you redirect console output to /dev/null).
Re: Having trouble getting a program running
Posted: Wed Jun 23, 2010 11:22 pm
by thelinx
Luiji wrote:It would be nice if Lua took that as a "black hole" and deleted anything sent to it (like on Linux when you redirect console output to /dev/null).
Code: Select all
setmetatable(_G, {__newindex = function(table, key, value)
if key:sub(1,1) ~= "_" then
rawset(table, key, value)
end
return
end})