Lua - aRustyDev/CodeWars GitHub Wiki
- Variables
- String manipulation
- Operators
- Syntax
- Data Structures
- Data Types
In Lua, though we don't have variable data types, we have three types based on the scope of the variable.
- Global Variables − All variables are considered global unless explicitly declared as a local.
- Local Variables − When the type is specified as local for a variable then its scope is limited with the functions inside their scope.
- Table Fields − This is a special type of variable that can hold anything except nil including functions.
Basic Structure of variable declaration: <type> <variable_list>;
Local Variables
local i, j
local i
local a,cGlobal Variables
d , f = 5, 10; +, -, *, /, %, ^
==, ~=, >, <, >=, <=
'and', 'or', 'not'
.. #
Left -> Right : *, /, %, +, -, <, >, <=, >=, ==, ~=, ==, ~=, 'and', 'or'
Right -> Left : 'not', #, -, ..
- Tables
- Iterators
- Arrays
- Strings
| # | Type | Description |
|---|---|---|
| 1 | nil | Used to differentiate the value from having some data or no(nil) data |
| 2 | boolean | Includes true and false as values. Generally used for condition checking. |
| 3 | number | Represents real numbers. ie: Double Precision Floating Point |
| 4 | string | Represents array of characters |
| 5 | function | Represents a method that is written in C or Lua. |
| 6 | userdata | Represents arbitrary C data. |
| 7 | thread | Represents independent threads of execution and it is used to implement coroutines. |
| 8 | table | Represent ordinary arrays, symbol tables, sets, records, graphs, trees, etc., and implements associative arrays. It can hold any value (except nil). |
Check Type
print(type("What is my type")) --> string
t = 10
print(type(5.8*t)) --> number
print(type(true)) --> boolean
print(type(print)) --> function
print(type(nil)) --> nil
print(type(type(ABC))) --> string