Echo wrote:I'm going to learn meta-tables and then use them because they seem to be very interesting
Fine, it is up to you.
Echo wrote:
another reason I am doing this anyway is to learn Lua and real programming so I cant just dumb down the variables instead of taking the next step and learning something new like meta-tables.
Well, I am just saying it is not really needed here.
But that's just a simple opinion.
Echo wrote:
Since I'm learning, I never really understood your _toString function or what it does and how it does it exactly
Code: Select all
function _tostring(data)
local buf = 'return {'
for i,v in pairs(data) do
buf = buf .. i ..' = '..v..','
end
buf = buf .. '}'
return buf
end
Well, in human language, it corresponds to:
Code: Select all
function _tostring(data)
Create a local buffer to store a string (local, so that it won't be accessible outside this function)
Store "return {" inside this buffer
for each key, value in table (data) do
concatenate the buffer with all these : key, "=", value, ","
end for
concatenate the buffer with "}"
return the buffer
Echo wrote:
Also when creating a function do you have to use the following systax?
Code: Select all
function myname
--statement
--return statement
end
Somehow. In Lua, functions receive arguments, or not, make some processing, and then return one or more results, or not.
All of theses a valid, for instance
Code: Select all
-- Takes nothing, returns nothing, just prints 'hello'
function a()
print('Hello')
end
-- Takes something, prints it, but returns nothing
function a(str)
print(str)
end
-- Takes something, capitalizes it, prints it, and returns it
function a(str)
str = str:upper()
print(str)
return str
end
-- Takes, nothing, do nothing and returns nothing
function foo() end
Echo wrote:
I should porbably just go look for a tutorial on functions for Lua instead of bothering you guys but this is why I found _toString wierd.
Learning Lua, at least the basics, isn't that hard.
As for me, french guy, it was complicated cause I couldn't find french resources at first.
I sat in one day, opened PiL in my browser, and went through, while trying some samples. And was highly helpful.
Here is some good resources, ready to consume.
To me, here is your bible:
PiL
Lots of interesting stuff here, too:
Lua-Users Tutorial directory
And of course, the
Ref manual (
5.1,
5.2, though Löve features Lua 5.1, I guess)