بسم الله الرحمن الرحیم.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Introducing JavaScript
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
Programming Languages and Paradigms The C Programming Language.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Lua By: Michael Coffman Peter Sussman. History Lua means ‘moon’ in Portuguese First appeared in 1993 Created by Roberto Ierusalimschy, Luiz Henrique de.
The Web Warrior Guide to Web Design Technologies
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Lua Matthew Spain | Kerry Zhao. Agenda Overview of Lua Language Details Application Areas Demo Conclusion.
References: 1. “Programming in LUA, 2 nd ed.”, Roberto Lerusalmschy Chapters “Lua Reference Manual” (included in Lua installation or online)
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Topics Scope Scope and Lifetime Referencing Environments.
1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
H3D API Training  Part 3.1: Python – Quick overview.
1 JavaScript 1. 2 Java vs. JavaScript Java –Is a high level programming language –Is platform independent –Runs on a standardized virtual machine.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Lua: The Programming Language. Some Things that Need to be Said Because of increasing demand for customizable applications, the trend nowadays is to split.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Documentation / References Python Full Documentation – Python Quick Reference –
Games Development 2 Lua Scripting CO3301 Week 6. Contents Introducing Lua –Comparison with Python Lua Language Overview Interfacing Lua with C++
Fantasy && Smart 吴航.  Some concepts  Differences between Lua & C++  Application.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
John Imboden. What is Lua  Embeddable scripting language  Creators: Roberto Lerusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes  Designed.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
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.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
By Mr. Muhammad Pervez Akhtar
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Review Expressions and operators Iteration – while-loop – for-loop.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Chapter 8 Statement-Level Control Structures. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements.
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.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
Prepared by Mustafa CAMURLI.  Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade São José dos Campos, 2011.
Cody Scoggins, Dion de Jong, Victor Reynolds References:  902/is-lua-interesting-from-a- programming-language-design-
Functions.
Lua Extending References:
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Concepts of Programming Languages
A bit of C programming Lecture 3 Uli Raich.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Variables, Expressions, and IO
JavaScript Syntax and Semantics
Getting Started with C.
Lua for TerraME: A Short Introduction
Computer Science 210 Computer Organization
Chapter 10: Implementing Subprograms Sangho Ha
CS5220 Advanced Topics in Web Programming JavaScript Basics
Unit 6 part 3 Test Javascript Test.
What is Lua? Brandon Burgess Csc 415.
Catharine West Bo Aye Saljin LaRocca references
COM-152: Computer Programming Types, Variables, Operators Part 1 of 2
Tutorial 10: Programming with javascript
Programming Languages and Paradigms
The Lua Chunk Vault, an enhancement to epics base
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Presentation transcript:

بسم الله الرحمن الرحیم

Lua Real embeddable Script Language

History Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer Graphics Technology Group (Tecgraf) at the Pontifical Catholic University of Rio de Janeiro, in Brazil.

What is Lua dynamic language scripting language Embedded in C/C++, Java, Fortran, C#,Perl, Ruby, Ada, etc. portability simplicity small size

Like basic Types: "nil" "boolean" "number""string" "table" "function" "thread" “userdata” Comment --one Line comment --[[ Multi-line comments]] multiple assignments a,b=10,20 ---- Operators + - * / % = .. # and or not == ~= >= <= < > () []

function name ( args ) body [return values] end do block end if exp then block {elseif exp then block} [else block] end while exp do block end repeat block until exp for var = start, end [, step] do block end for vars in iterator do block end Break local a=12 Local a=function (args) body [return values] end

boolean b=true b=false number I=12.3 table t = {} t = {"yes", "no", "?"} t = {x=5, y=10} t = {x=5, y=10; "yes", "no"} t[“x”]=”rahim”; t.x=”firouzi” string s=”rahim” s='firouzi' S= [=[ multi line string ]=]

OOP Use table for oop Example obj→func(p1,p2) ====> Obj:func(p1,p2) == obj[“func”](obj,p1,p2) Use table for module io.print(p1) == io[“print”](p1) OOP example local Vector = {} Vector.__index = Vector function Vector:new(x, y, z) -- The constructor return setmetatable({x = x, y = y, z = z}, Vector) end function Vector:magnitude() -- Another method return math.sqrt(self.x^2 + self.y^2 + self.z^2)

Useful function type(var) print( … ) ipairs (t) pairs (t) _G _VERSION

lib string string.len (s) string.sub (s, i [, j]) string.upper (s) string.lower (s) string.format (s [, args]) IO io.read (formats) io.write (values) Math math.sqrt (x) math.sin (a) math.cos (a)

lib file io.open (fn [, m]) file:close () file:read (formats) file:lines () file:write (values) file:flush () OS os.execute (cmd) os.exit ([code]) os.time ([tt]) os.date ([fmt [, t]])

How to run lua program Interpretor Lua sudo apt-get install luaX.X lua Embedded in other programming Use lib

Embedded An embedded style language is a kind of computer language whose commands appear intermixed with those of a base language. Lua example:adobe lightroom Python example:Gimp ,Blander Scheme example:gdb,gEDA JavaScript → ECMAScript example: web browsers TCL example:NS-2

Embedded Use stack to communication by lua Make state Add c function in state Run lua script for preset Call lua function by c

embedded Main program Lua program Function link Call function return

C example #include <stdio.h> #include <lua.h> //Lua main library (lua_*) #include <lauxlib.h> //Lua auxiliary library (luaL_*) int main(void) { //create a Lua state lua_State *L = luaL_newstate(); //load and execute a string if (luaL_dostring(L, "function foo (x,y) return x+y end")) { lua_close(L); return -1; } //push value of global "foo" (the function defined above) //to the stack, followed by integers 5 and 3 lua_getglobal(L, "foo"); lua_pushinteger(L, 5); lua_pushinteger(L, 3); lua_call(L, 2, 1); //call a function with two arguments and one return value printf("Result: %d\n", lua_tointeger(L, -1)); //print integer value of item at stack top lua_close(L); //close Lua state return 0; wikipedia

Add function static int hello (lua_State *L) { double f = luaL_checknumber(L, 1); lua_pushstring(L, “hello world”); return 1; } … lua_pushcfunction(L, hello); lua_setglobal(L, “hello”); ...

Try

Tanks