CSC/ECE 517 Fall 2010/ch6 6a RJ: Difference between revisions
No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
=== '''Lua''' === | === '''Lua''' === | ||
Lua is a powerful, fast, lightweight, embeddable scripting language. | Lua is a powerful, fast, lightweight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.[http://www.lua.org/about.html [2]]] Lua is free open-source software, distributed under a very liberal license (the well-known MIT license). It can be used for any purpose, including commercial purposes, at absolutely no cost. Just download it and use it. | ||
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.[http://www.lua.org/about.html [2]]] | |||
Lua is free open-source software, distributed under a very liberal license (the well-known MIT license). It can be used for any purpose, including commercial purposes, at absolutely no cost. Just download it and use it. | |||
==== '''History of Lua''' ==== | ==== '''History of Lua''' ==== |
Revision as of 04:01, 17 November 2010
Survey of selected Delegation-based Programming Languages
Delegation-based programming languages, also known as Prototype-based programming languages, represent a style of object-oriented programming in which classes are not present, and behavior reuse (known as inheritance in class-based languages) is performed via a process of cloning existing objects that serve as prototypes. This model can also be known as class-less, prototype-oriented or instance-based programming. Delegation is the language feature that supports prototype-based programming.
The original, and most canonical, example of a prototype-based language is the programming language Self developed by David Ungar and Randall Smith. Since the late 1990s, the classless programming style has grown increasingly popular, and has been adopted for the languages Javascript, ActionScript, Cecil, NewtonScript, Io, Moo, REBOL, Lisaac, Lua and several others.[1] This topic will briefly review features of three Delegation-based programming languages: Lua, Io, and Actionscript.
Lua
Lua is a powerful, fast, lightweight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.[2]] Lua is free open-source software, distributed under a very liberal license (the well-known MIT license). It can be used for any purpose, including commercial purposes, at absolutely no cost. Just download it and use it.
History of Lua
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. [3] The design of the Lua programming language was influenced by the programming languages Scheme, SNOBAL, Modula-2, CLU, and C++.
Lua and Object Oriented Programming
Lua isn't an object oriented languages in the sense that you define classes, create objects with a new method, define interfaces and declare variables to be private or protected ... but never the less is a tool in which you can use object oriented techniques with (indeed) a freedom and flexibility that you don't have with a straitjacket language such as Java.[4]
Have a look at this code ...
Firstly, we define a couple of named pieces of code (functions) which take a table as their parameter, and we provide functionality withing them that manipulates the table:
function effage(animule)
return animule.age * animule.factor end
function stone(thecrows)
return "as da hills" end
We then define a number of tables, each representing a single "something" [object] which contains attributes / properties / characteristic values (choose whatever you feel is the most appropriate word. Significantly, we also add in to the table the function code, just defined above, which can operate on the other elements within that table. We can do this because functions in Lua are held in "first class variable" just like any other user supplied elements, and that an assignment copies a reference, so that we're not cloning hundreds of copies of what could be substantial code.
gypsy = {breed = "dog", age = 3, weight = 28,
factor = 7, name = 'Gypsy Ellis', efa = effage}
rocky = {breed = "rock", weight = 28,
type = "Granite", name = 'Rocky Bamboa', efa = stone}
charlie = {breed = "cat", age = 13, weight = 4,
factor = 6, name = "Charlie Ellis", efa = effage}
flipper = {breed = "dolphin", age = 7, weight = 300,
factor = 2, name = "Flipper Lichtenstein", efa = effage}
Although "structured" programmers might have chosen to have an array of breeds, an array of ages, etc, we have chosen to use a separate table for each of the disparate value types associated with an individual item - and we can now make up a table of each of those items - a table of tables, if you like, or an "array of objects" if you would like me to start using OO terminology:
pets = {gypsy, charlie, rocky, flipper}
We can then loop through our array of objects, accessing individual member elements (attributes / properties) by name, and running pieces of code which are referenced from within each of them to perform actions on the data they hold ...so that those functions have noe turned (in OO terms) into methods. With different methods referenced within differing objects, you'll see that we've implemented polymorphism via the back door!
for k,v in pairs(pets) do
print (k,v,v.name) print ("yay",v.efa(v)) end
Info about Lua Language goes here.
Javascript
Info about Javascript Language goes here.
Actionscript
Info about Actionscript Language goes here.
Lua
Info about Lua Language goes here.
Io
Info about Io Language goes here.
Delegation-based Programming Languages compared to Class-based Programming Languages
Intro
Delegation-based Programming Languages compared to C++
Delegation-based Programming Languages compared to Java
Delegation-based Programming Languages compared to Ruby
References
[1] http://en.wikipedia.org/wiki/Prototype-based_programming