Lua - Tables

Published 2014/03/03 by Admin in LUA
Tags: ,

Create an empty table -

a = {}

Create a table with the numbers 1,2,3 assigned -

b = {1,2,3}

Create a table with the strings "a","b","c" assigned -

c = {"a","b","c"}

 

We are unable to call print() on tables directly. See Printing tables.


Lua - Standard output (stdout)

Published 2014/03/03 by Admin in LUA

You can use the print() function to write a line to the stdout.

  • print("Hello"), or
  • print "Hello"
If you want to write to stdout without the new line appended at the end use the io.write() function.
  • io.write("Hello")

Lua - Multiple Assignments

Published 2014/03/03 by Admin in LUA

You are able to make multiple assignments at the same time.

  • a,b,c,d,e = 1, 2, "three", "four", 5

 

The above assign is equivalent to the code below.

  • a = 1
  • b = 2
  • c = "three"
  • d = "four" 
  • e = 5
This allows for interesting swapping of values.
  • a = 1
    b = 2 
  • a,b = b,a 
  • now a = 2 and b = 1

Lua - Strings

Published 2014/03/03 by Admin in LUA
When making string values the characters that always give the most problem are the " and ' (I don't know whether I should put them inside "quotes". My brain just exploded because of the Recursion...). Below is a guide as to the correct implementation of strings and quotes.
  • value="single 'quoted' string and double \"quoted\" string", or
  • value='single \'quoted\' string and double "quoted" string', or
  • value=[[multiple line
    with 'single'
    and "double" quoted strings inside]]
Hopefully this informations helps more than it confuses...

The following words are all reserved for internal functions in Lua.

These words cannot be used for variable names, but Lua is case sensitive, so 'and' is reserved and can't be a variable, but 'aND, aNd, AND, anD, AnD, And, ANd' are not reserved and can be used as variables.


Chicken and the egg...

Published 2014/02/18 by Admin in My coding blog


my coding

This is a collection of all the coding gems I have found and would like to share with the world!