Skip to content

ChengBinJin/Lua-Basic-Tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 

Repository files navigation

Lua-Basic-Tutorial

This tutorial follows John Sonmez Youtube tutorial and 游戏大师课 Youtuber tutorial for basics of Lua.

What is the Lua?

Lua is a lightweight, high-level, multi-paradigm programming language designed primarily for embedded use in applications. Lua is cross-platform, since the interpreter of compiled bytecode is writtten in ANSI C, and Lua has a relatively simple C API to embed it into applications.

Lua was originally designed in 1993 as a language for extending software applicationss to meet the increasing demand for customization at the time. It provided the basic facilities of most procedural programming languages, but more complicated or domain-specific features were not included; rather, it included mechanisms for extending the language, allowing programmers to implement such features. As Lua was intended to be a general embeddable extension language, the designers of Lua focused on improving its speed, portability, extensibility, and ease-of-use in development. (from wikipedia)

Types - 8 basic types

  • nil
  • boolean
  • number
  • string
  • userdata
  • function
  • thread
  • table

Operators

  • Arthmetic (+, -, *, /, ^, %)
  • Relational (<, >, <=, >=, ==, ~=)
    • Note: not equal ~= in Lua
  • Logical (and, not, or)
  • Other
    • Concatenation
      • "Hi" .."there"
    • Length
      • #suckers

If, Then, Else

if boolean expresion then
        -- do something
else
        -- do something else
end

Loops

  • While - while boolean expression do something end
  • Repeat - repeat something until boolean expression
  • For (Numberic) - for variable = start, end, step do something end
  • For (Generic) - for k, v in iterator do something end

Blocks and Scope

By default, all variables in Lua are globally scoped

Variadic Functions

function countStringLengths(...)
        --do stuff
        a, b, c = ...
end

Tables

Ex. (1): grades = {1, 2, 3}
Ex. (2): grades = {"John" = 89, "Steam" = 90}
Note: the index of tables in Lua starts from 1 not 0

Metamethods

  • __index
  • __newindex
  • Operators
    • __add
    • __sub
    • __mul
    • ...
  • __call
  • __tostring

Overview of Standard Libraries

  • Basic
  • Package
  • String
  • Table
  • I/O
  • Operating System
  • Debug

Keywords

and break do else
elseif end false for
function if in local
nil not or repeat
return then true until
while

About

This repository for the Lua basic tutorial following John Sonmez

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages