Lua Programming/How to Lua/assignment

      The assignment operator

      In lua, as with most other programming languages, the *equals sign* acts as a dyadic *assignment operator* assigning the value of the expression of the right hand operand to the variable named by the left operand:

      Assignment of variables

      The following examples show the use of the equals sign for the assignment of variables:

      fruit = "apple"   -- assign a string to a variable
      count = 5         -- assign a numeric value to a variable
      

      Strings and Numeric Values

      Note that literal strings should be enclosed in quotationmarks to distinguish them from variable names:

      apples = 5
      favourite = "apples"   -- without quotes, apples would be interpreted as a variable name
      

      Note that numeric values do not need to be enclosed in quotation marks and cannot be misinterpreted as a variable name, because variable names cannot begin with a numeral:

      apples = 6    -- no quotes are necessary around a numeric parameter
      pears = "5"   -- quotes will cause the value to be considered a string
      

      Multiple Assignments

      The lua programming language supports multiple assignments:

      Last modified on 13 February 2011, at 23:58