Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade São José dos Campos, 2011.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Programming Languages and Paradigms The C Programming Language.
Roberto Ierusalimschy PUC-Rio, Brazil
Introduction to the C# Programming Language for the VB Programmer.
12-Jun-15 JavaScript Language Fundamentals I. 2 About JavaScript JavaScript is not Java, or even related to Java The original name for JavaScript was.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
VB .NET Programming Fundamentals
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Spatial Dynamical Modeling with TerraME Tiago Carneiro Gilberto Câmara Pedro Andrade Licence: Creative Commons ̶̶̶̶ By Attribution ̶̶̶̶ Non Commercial.
Python quick start guide
References: 1. “Programming in LUA, 2 nd ed.”, Roberto Lerusalmschy Chapters “Lua Reference Manual” (included in Lua installation or online)
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
While Loops CMSC 201. Overview Today we will learn about: Looping Structures While loops.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
How to Create a Videogame By: Connor McCann. Java Java is one of many programming languages Java is used to run web browsers and most PC video games I.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Games Development 2 Lua Scripting CO3301 Week 6. Contents Introducing Lua –Comparison with Python Lua Language Overview Interfacing Lua with C++
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
More Lua. Expressions Arithmetic operators */-+ “real” numbers only ^ exponentiation a%b == a - floor(a/b)*b x%1 gives fractional part, x-x%1 integer.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Visual Basic Programming I 56:150 Information System Design.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
“The world’s most misunderstood language has become the world’s most popular programming language” Akshay Arora
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
Expressions and Data Types Professor Robin Burke.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
Euphoria Programming Language CSC 507 Kasilingam Vimalan.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade Tiago G. S. Carneiro Gilberto Câmara Münster, 2014.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade Münster, 2013.
Prepared by Mustafa CAMURLI.  Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer.
Introdução a Linguagem de Modelagem TerraML Dr. Tiago Garcia de Senna Carneiro TerraLAB - Laboratório INPE/UFOP para Simulação e Modelagem dos Sistemas.
Introdução a Linguagem de Modelagem TerraML
Programming Languages and Paradigms
JavaScript Syntax and Semantics
بسم الله الرحمن الرحیم.
Programming Paradigms
Lua for TerraME: A Short Introduction
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Catharine West Bo Aye Saljin LaRocca references
Tutorial 10: Programming with javascript
Programming Languages and Paradigms
CIS 136 Building Mobile Apps
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Introduction to Python
Presentation transcript:

Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade São José dos Campos, 2011

Lua  Robust: it has been used in many industrial applications.  Fast: several benchmarks show Lua as the fastest language in the realm of interpreted scripting languages.  Portable: Lua is distributed in a small package and builds out-of- the-box in all platforms that have an ANSI/ISO C compiler.  Embeddable: it can be embeded easily into other applications.  Powerful (but simple): Lua provides meta-mechanisms for implementing features, instead of having a host of features directly in the language.  Small: The tarball for Lua takes 860K uncompressed. The source contains around lines of C. Under Linux, the interpreter takes 153K and the library, 203K.  Free: distributed under MIT license

Lua and the Web Where is Lua?  Inside Brazil  Petrobras, the Brazilian Oil Company  Embratel (the main telecommunication company in Brazil)  many other companies  Outside Brazil  Lua is used in hundreds of projects, both commercial and academic  CGILua still in restricted use  until recently all documentation was in Portuguese LUA is the language of choice for computer games [Ierusalimschy et al, 1996] source: the LUA team

Variables and Values  Case sensitive  semicolon may optionally follow any statement a = 1 b = a*2 a = 1; b = a*2 a = 1 b = a*2 print(a) print(b)

Types  nil  boolean  number  string  table  function

nil  Everything that does not exist print(type(c)) c = 10 print(type(c)) print(type(c > 2)) c = nil print(type(c)) print(type("a string!!")) print(type(print))

Boolean  false/true  nil and false are false, everything else is true  zero and the empty string are true in conditional tests  operators and, or, and not print(true and false) print(true and (false or true)) print(false or (true and false) or (true and true))

Number  the only type for numeric values  double-precision floating-point number  arithmetic operators: +, –, *, /  exponent (^) and modulo (%)  boolean operators (, =, ~=, and ==). A = * 4 a = A ^ 2 b = A % 7 print(a) print(b) print(a > b) print(b ~= 2)

Parentheses  Always optional (except in the case of function call)  When in doubt, use parentheses a+-i (a+(-i)) < ((b/2)+1) 5+x^2*8 5+((x^2)*8) a (a < y) and (y <= z) –x^y^z –(x^(y^z))

String  single or double quotes  operator.. print("hello") print('hello') x = 2 print ("x = "..x)

If statement  An if statement tests condition and executes its then-part or its else-part (optional) accordingly. a = 6; b = 5 if a<0 then print("a < 0") end if a = b") end if a<b then print("a < b") elseif a < b + 5 then print("b < a < b+5") else print("a > b+5") end

For statement  A numeric for has the following syntax: for var = exp1, exp2, exp3 do something end  That loop will execute something for each value of var from exp1 to exp2, using exp3 as the step to increment var. This third expression is optional; for i = 1, 10 do print(i) end for i = 1, 10, 2 do print(i) end

Table  The only structured data type.  Implements associative arrays, which can be indexed not only with numbers, but also with strings or any other value of the language, except nil. x = {1,3,2,6,4,3,7} print(x[1]) x[1] =x[2] + x[3] print(x[1]) print(table.getn(x)) for i = 1, table.getn(x) do print(x[i]) end

Table  Table values can be named loc = { cover = "forest", distRoad = 0.3, distUrban = 2 } print(loc["cover"]) print(loc.cover) loc.distRoad = loc.distRoad^2 loc.distTotal = loc.distRoad + loc.distUrban print(loc.distTotal) loc.deforestationPot = 1/loc.distTotal print(loc.deforestationPot)

Function  A function can carry out a specific task (commonly called procedure) or compute and return values.  A function is a first-class value in Lua.  Functions can be stored in variables and in tables, can be passed as arguments, and can be returned by other functions, giving great flexibility to the language. print(8*9, 9/8) a = math.sin(3) + math.cos(10)

High-order Function  Functions can also be parameters to other functions. This kind of function is what we call a higher-order function. x={1, 3, 2, 6, 4} function myprint(a) print(a) end table.foreach(x, myprint) table.foreach(x, function(a) print(a) end) table.foreach(x, print)

Tables with functions  Table may have their own functions. loc = { cover = "forest", distRoad = 0.3, distUrban = 2 } loc.deforestPot = function(myloc) return 1/(myloc.distRoad + myloc.distUrban) end print(loc.deforestPot(loc)) print(loc:deforestPot())

Tables with functions  We can declare a class in Lua by creating a function that takes a table constructor as argument. function MyLocation(locdata) locdata.covertype = "forest" locdata.deforPot = function(self) return 1/(self.distRoad + self.distUrban) end return locdata end loc = MyLocation({distRoad = 0.3, distUrban = 2}) loc = MyLocation{distRoad = 0.3, distUrban = 2} print(loc.covertype) print(loc:deforPot())

Standard libraries  Basic (print, type, tostring, tonumber, …)  String (string.find, string.gsub, string.format, …)  Table (table.insert, table.remove, table.sort, table.getn …)  Math (math.random, math.sin, math.exp, …)  IO (io.open, io.read, io.close, …)  OS (os.clock, os.execute, …)  Debug (debug.getinfo, debug.getlocal, …)

Comments  double hyphen (--) until the end of the line.  block comments start with --[[ and run until ]] print("hello") -- print("hello") --[[ print(10) -- no action (comment) --]]