lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



> My basic understanding of functions is that they do something with values stored in container variables.

Functions are a way to give a name to a piece of code that you want to be able to call later more than once.

> I want a full list of these functions to read up what are they and what they do.

The Lua Reference Manual has a description of every function that is provided by the standard library.
 
But you shouldn't need to know this to use Lua. The most important thing is knowing how to create your own functions.

> For example I guess print is a function.

Yes.

> io.read waits user input until Enter is hit on keyboard.

That isn't quite what happens. io.read reads from the standard input stream, and from the point of view of Lua that is just a stream of characters.

What is causing the pause until you press enter is your terminal emulator. Due to line buffering, it only sends the data you type to the Lua program after you press Enter. (This let's you use backspace to fix mistakes as you type)

> function math

Actually, "math" is just a table of functions for organizing common math function. Run type(math) and type(math.sin) in you Lua REPL to check that out.

> io.write takes the value stored in a variable where io runs it or evaluates it using a function and shoots it on screen post processing. 

Functions receive values as input.

When you type something like f(1+2) in Lua, Lua will first evaluate the 1+2 _expression_ and then pass the 3 value to the f function, as a parameter.

Similarly, if you call f(blah), Lua first evaluates the blah _expression_ (reading the value stored in the blah variable) and then passes that value to f. The f function never gets to see the Lua _expression_ or variable names that produced the values it us receiving. It only gets the value and that's it.

> Same thing for tables. I know to start a table I use {} but what are its uses in the context of practicality in a program except data entry.

The Programming in Lua book should have some examples.

> Also the arbitrary so called type userdata which briefly I skimmed I dont know what is it used for or examples of its use.

Userdata is most useful if you are scripting. If you have Lua code that manipulates values originally created in a different language (like C) then those values will be exposed to Lua through user data.

If you are just starting out you probably won't need to worry about user data for now.

> Is there a source for all chapters in PIL where the mentioned definitions (array,value,function,metatable,etc..) are merged to form chunks explained head to toe? To the novice people like me? Beginners

It sounds like you are asking for the Reference Manual.

But I'm not sure its an ideal starting point. It is very dense, and is most useful when you need to search for the precise definition of some Lua construct.