+  Scratch Projects Forum
|-+  Programmers Corner» Lua» Introduction to Lua Programming
Username:
Password:
Pages: [1]
  Print  
Author Topic: Introduction to Lua Programming  (Read 4273 times)
Scratch Projects
Administrator
novice coder
*****

Karma: +0/-0
Posts: 56


View Profile
« on: September 01, 2007, 12:50:37 AM »

Lua is a powerful, light-weight programming language designed for extending applications. Coupled with it being relatively fast and having a very lenient license, it has gained a following among game developers for providing a viable scripting interface. It has been used in games such as World of Warcraft and Far Cry, and in applications such as Adobe Photoshop Lightroom and Snort.

Read the full tutorial here: http://www.scratchprojects.com/2007/08/introduction_to_lua_programming_p01.php
Logged
Kevin
Administrator
31337
*****

Karma: +1/-0
Posts: 137


View Profile WWW
« Reply #1 on: September 10, 2007, 06:06:20 AM »

Thanks to help from Tomás and Christian, the follow errors have been corrected in the tutorial.

- 'printf' instead of 'print', in the "-- Multiple Assignments" example
- 'io.read(*line)' instead of 'io.read("*line")', in the last page
- 'a[i[' instead of 'a', in the section about assignment
- absence of 'do' after while-expression as in the "--break example"
- absence of parenthesis in _all_ calls to `print' in the example about
  variables
- "There are 3 kinds of variables in Lua, global variables, local variables and table fields." Table fields are NOT variables!
- "print(a^b)   -- 125  calls the __pow function" There is no '__pow' function.  The '^' operator calls the function 'math.pow' or it could call the '__pow' metamethod of the metatable of the object being operated (if it is not a number)
- File mySqrt.lua does not computes the square instead of the square root

Thanks again guys.
Logged

Kevin
Administrator
31337
*****

Karma: +1/-0
Posts: 137


View Profile WWW
« Reply #2 on: September 13, 2007, 03:44:27 AM »

A couple more corrections have been made. Thanks again Tomás.

- The phrase "If the function call is not the first element in the list
  of values, then only the first return value is used and the remaining
  values are ignored" is incorrect and should be removed.

- The explanation about the generic for is incomplete.  The iterator
  function could return many values (as any Lua function) and the general
  syntax is in fact:

for <var_list> in <exp> do <block> end

  Where <var_list> could be a list of variables (with the same scoping
  rules of the 'i' control loop variable mentioned above).

- Changed the name of the file "mySqrt.lua" to "mySqr.lua"
  at the end of the section about the for-loop.

- In the "return example", the expression 'num == 10' will always
  evaluate to false, because the call to 'io.read' will always return
  a string.  You could correct this with 'tonumber(num) == 10' or
  'num == "10"'
Logged

gigante
n00b
*

Karma: +0/-0
Posts: 1


View Profile
« Reply #3 on: December 20, 2007, 10:23:13 AM »

Hello Kevin, hello Scratch Projects
I´m an initial student of Lua language. And I´m having some problems, because I don´t have enough materials to study.
I have had problems working with Lua and HTML, in another words, I want to do interaction with Lua and HTML languages.
I would like knowing if you may help me.
How can I do this interaction?

Best regards
Gigante
Brazil
Logged
Kevin
Administrator
31337
*****

Karma: +1/-0
Posts: 137


View Profile WWW
« Reply #4 on: January 09, 2008, 05:01:17 AM »

I'd say right now the best place to learn is from lua.org. It'll help you get all the basics down. After that, the best thing to do is to come up with a project you want to work on and learn by trial and error. Unfortunately I don't know Lua, maybe some of the people on this forum can provide you with a better place to look.
Logged

Pages: [1]
  Print  
 
Jump to: