Giter Club home page Giter Club logo

guja's Introduction

guja

Guides

  1. hello-world - hello world
  2. comments
  3. factorial - simple resursive function, user input
  4. control-structures - if/else, while, for, etc.
  5. dofile - run a chunk from another file
  6. types - basic types: nil, boolean, string, userdata, function, thread, table. Also integer vs float
  7. math - examples from math library
  8. strings - examples, along with string library examples
  9. tables - lists, records, arrays
  10. functions
  11. io - Simple I/O, Complete I/O, basic file read/write
  12. os - Operating System, os library, to interact with machine, date
  13. pattern-matching - strings: finding, replacing, matching
  14. binary - pack and unpack data to binary
  15. Serialization (skipped)
  16. compilation
  17. errors - and how to handle them
  18. modules - modules, packages, and require
  19. iterators - going beyond for loop

Demos

  1. eight-queen - examples of functions to solve a chess problem
  2. word-frequency - find most frequent words in a text

Command Line

# enter code directly into command line
lua -e 'print("hello world")'
# interactive mode
lua -i

Random notes

  • Tables {} are the main data structure. They can be used as lists, sequences, arrays, etc.
  • There is no switch. use elseif instead
  • There is a goto. See control-structures
  • Functions are first-class values
    • they have the same rights as other types like strings, and can be stored as variables or in tables
  • Functions have lexical scoping - can access variables within their enclosing function

Reserved words

andelseiffunction localrepeatuntil
breakendgoto nilreturnwhile
dofalseif notthen
elseforin ortrue

Operators

<less than<=less than or equal to==equal to
>greater than>=greater than or equal to~=not equal to

Character Classes

  • Capitalize to represent the opposite, e.g., %A is all non-letter characters.
.all characters %gprintable except spaces %uuppercase
%aletters %llowercase %walphanumeric
%ccontrol characters %ppunctuation %xhexadecimal
%ddigits %sspaces

Precompiled code

Precompiled code is not always smaller, but it loads faster and it serves as a protection against accidental changes

# -o means create a new file
luac -o hello-world.lc hello-world.lua
# precompiled code can run with lua command
lua hello-world.lc

require

# Add LUA_PATH environmental variable to .bash_profile
export LUA_PATH="~/lua/?.lua;;"
# confirm with printenv LUA_PATH

guja's People

Contributors

herereadthis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.