Author Topic: General Programming Megathread - New OP  (Read 29008 times)

Anybody know a good lua programming tutorial for beginners? I really want to learn how to program in lua .

Google. You need to be able to problem solve if you're going to program.

Now about my game idea, any feedback or questions? :3

Question: why haven't u started

Anybody know a good lua programming tutorial for beginners? I really want to learn how to program in lua .
Don't kill me for this, but beginners learn lua best from the roblox wiki. This is where I personally had a start, and it explains things really well for beginners.

There's also the official guide, Programming in Lua, and the Lua Reference Manual.


print 'hi guys'

for _, v in pairs{119, 97, 115, 115, 117, 112} do
    io.write(string.char(v))
end

message = ["h","e","l","l","o"]
message.each {|a| print a}

Question: why haven't u started

I'm going to be extremely busy in life real soon. Snow falls any day and I start working, then I go to school full time. I'm planning this to be a life project down the line, and just want to intellectually organize it right now.

for _, v in pairs{119, 97, 115, 115, 117, 112} do
    io.write(string.char(v))
end
No map in Lua (the higher-order function, I'm not talking about dicts/tables)?
« Last Edit: November 09, 2012, 03:40:13 PM by DontCare4Free »


Lua confuse me why there no ;

Lua confuse me why there no ;
you should be thankful that they aren't there

because they shouldn't need to be there

you can still type them if you want, though

(the higher-order function, I'm not talking about dicts/tables)?
what

what
Takes a function/closure/lambda and a list/sequence/iterable, returns the list but with every value replaced with the result of passing it to the function. An example of what you posted, ported to Python using map:

print "".join(map(chr, [119, 97, 115, 115, 117, 112]))

Python also has a special syntax for this, which is useful when you need to do something more advanced:

print "".join(chr(x) for x in [119, 97, 115, 115, 117, 112])

And a third syntax using map again (but with lambdas, accomplishes same thing as the second syntax, but with less case-specific magic (although that magic has a reason for existing, it's somewhat faster than the first/third syntax except for when you're just calling a function anyway)):

print "".join(map((lambda x: chr(x)), [119, 97, 115, 115, 117, 112]))

And in Haskell (roughly equivalent to the first Python syntax):

import Data.Char
main = putCharLn (map chr [119, 96, 115, 115, 117, 112])

And in Haskell again (like the third Python syntax):

import Data.Char
main = putCharLn (map (\x -> chr x) [119, 96, 115, 115, 117, 112])

And in Ruby (like the third Python syntax):

puts [119, 96, 115, 115, 117, 112].map {|x| x.chr}.join

And here's the literal Python translation of what you posted:

import sys
for x in [119, 97, 115, 115, 117, 112]:
    sys.stdout.write(chr(x))
print  # Terminate with a newline



I'm working on it! :(
« Last Edit: November 09, 2012, 04:00:03 PM by DontCare4Free »

lua was made to only have the necessities so that users could make their own functions, like the one you've demonstrated (unnecessarily with multiple languages, some of which i can barely understand, lol)

but for this specific purpose, you can pass multiple numbers to string.char, so if I wanted, I could do

print(string.char(119, 96, 115, 115, 117, 112))

and it'd do the same thing, I only wanted to complicate the process, lol.

also, there's really no point in having a join() function by default since it's so easy to make on your own.

function table.join(t)
  s = ''
  for _, v in pairs(t) do
    s = s .. v
  end
  return s
end

same with other "missing" lua utilities, like round()

function math.round(n)
  return math.floor(n + 0.5)
end

put ms dos batch on the list under low level, if your good at it you can get some pretty decent scripts and utilize vbscript along with it

put ms dos batch on the list under low level, if your good at it you can get some pretty decent scripts and utilize vbscript along with it
Batch is NOT low-level.



but for this specific purpose, you can pass multiple numbers to string.char, so if I wanted, I could do

print(string.char(119, 96, 115, 115, 117, 112))
This wouldn't work for, say, a table you already have populated though. Nor is it a generic solution to the problem (it only works with that specific function). But sure, it is something that is relatively easy to reimplement on your own.

Quote
also, there's really no point in having a join() function by default since it's so easy to make on your own.

function table.join(t)
  s = ''
  for _, v in pairs(t) do
    s = s .. v
  end
  return s
end

same with other "missing" lua utilities, like round()

function math.round(n)
  return math.floor(n + 0.5)
end
Sure, but it's still stuff that is relatively useful and that there isn't really any good reason for not having in the standard library, especially when there, AFAIK, isn't a good dependency manager available either.
« Last Edit: November 09, 2012, 04:30:38 PM by DontCare4Free »