0% found this document useful (0 votes)
9 views27 pages

Scripting Languages

The document explains how scripting languages work in web development, detailing the processes of server-side and client-side scripting. It highlights the advantages of using scripting languages for creating dynamic web pages and discusses various scripting languages such as Perl, Python, Ruby, ASP, PHP, and JavaScript. Additionally, it covers the use of scripting languages in game development, emphasizing their role in animation, gameplay logic, and event handling.

Uploaded by

DIVYAM GUPTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views27 pages

Scripting Languages

The document explains how scripting languages work in web development, detailing the processes of server-side and client-side scripting. It highlights the advantages of using scripting languages for creating dynamic web pages and discusses various scripting languages such as Perl, Python, Ruby, ASP, PHP, and JavaScript. Additionally, it covers the use of scripting languages in game development, emphasizing their role in animation, gameplay logic, and event handling.

Uploaded by

DIVYAM GUPTA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Scripting Languages

How it Works

Browser
Web
 1 - Request an HTML
Page
4 - Present HTML
Content

3 - Return HTML to


Web
Browser
Server HTML 2 - Retrieve requested
HTML
How Scripting Languages Work

Server runs
script
Client requests [ ASP / PHP / Ruby ]
page Script
Internet
Script
Completed HTML sent to builds
c lient HTML
c ode

Web Server HTML ready to


send HTML Code
Client Machine
With Web Browser

• The script, written by the website developer, generates the HTML code of the page requested.
• The HTML code is not actually a file. The code is actually held in the server’s memory until it is
sent directly to the client.
• A script may run other scripts, depending on its function. It will however still only give one
end result.
• A website does not have to be completely made up of either scripts or HTML files. It can use a
combination of the two.
What Are Scripts?
🞅 A new style of programming language different from system
programming languages
🞅 It does not matter what scripting language a website uses
because there are no compatibility issues with clients’ web
browsers.
🞅 Designed as glue language or system integration language
🞅 A single statement can execute huge number of machine
instructions
🞅 Can create dynamic web pages
🞅 Change based on user input
🞅 The client only ever sees the final HTML generated by the
script
and not the script itself.
🞅 Scripts often finish running in several milliseconds.
Most web servers can run many scripts simultaneously with
a minimal performance hit.
Two Types
🞅 Server-side Scripting Language
🞅 Can use huge resources of the server
🞅 Complete all processing in the server and send plain
pages to the client
🞅 Reduces client-side computation overhead
Server side scripting means that all of the code is executed on
the server before the data is passed to the user's browser.

🞅 Client-side Scripting Language


🞅 Does not involve server processing
🞅 Complete application is downloaded to the client browser
🞅 Client browser executes it locally
🞅 Are normally used to add functionality to web pages e.g.
different menu styles, graphic displays or dynamic
advertisements
Server-side scripting
Step 1 – client requests a web page

Serve
r
Server-side scripting
Step 2 – server executes the script, producing dynamic
HTML output

Serve
r
Server-side scripting
Step 3 – server returns dynamic HTML page to
browser

Serve
r
Client & Server side scripting
Web sites will often make use of both client-side and server-side
scripting.

Server side scripts:


return pages specific to the user e.g. social media feed, e-
commerce recommendations etc.

Client side scripts:


will be returned in the dynamic page to allow interactions such
as zooming images, clicking option buttons etc.
Static Web Pages
1. Client requests page

Internet
2. Web server sends the HTML file to the
c lient

Client Machine
Web Server
With Web Browser

• A simple website is made up of one or more static HTML files. This means the
page content does not change.
• The only way to update a page is for the author to edit the file.
• This is fine for small websites or those that require little updating.
• Static pages will not work for websites that need to deliver lots of custom and up-
to- date content: e-commerce, auctions, blogs, search engines, online banking
Dynamic Web Pages
• The facebook homepage could be

Static WebPage
considered static because it has
a fixed layout and content. It
does not change.

• After Login results page however


is dynamic. This means its
content can be changed.

Dynamic WebPage
• The only practical way to create
this page is by using a script

• The user never sees the work a


script does, only the end result it
sends back to their browser.
Perl, Python, Ruby
🞅 Perl
🞅 Found on all Windows and Linux servers
🞅 Can handle text manipulation tasks
🞅 Excellent web scripting language
🞅 high-traffic websites that use Perl extensively
include Priceline.com, Craigs List, IMDB

🞅 Python
🞅 Can be used as a script or a programming
language
🞅 OOP language with a lot of features which support of web
applications as well as software programs
🞅 Industrial Light & Magic: "The Phantom Menace", "The Mummy
Returns"
🞅 Walt Disney Feature Animation: uses scripts in their animation
production system.
🞅 Shopzilla: configuration management and deployment, automated
testing and internal tool development.
Perl Python, Ruby

🞅 Ruby
🞅 Various blogs, data processing applications
🞅 Twitter, Shopify, Groupon, HUlu

🞅 Ruby, Perl, Python, etc., are all open source

🞅 Rely on volunteers to
🞅 Write documentation
🞅 Write test cases
🞅 Maintain the systems
🞅 Port to new platforms
🞅 Fix bugs
🞅 Implement libraries
🞅 Implement new features
ASP-PHP
🞅 Active Server Pages (ASP)
🞅 Server side scripting language
🞅 Developed by Microsoft
🞅 Good at connecting to Microsoft databases
🞅 Runs only on Microsoft servers
🞅 Microsoft.com, GoDaddy, Skype, NYTimes.com

🞅 PHP (Hypertext Pre-Processor)


🞅 Especially good at connecting to MySQL
🞅 Generate Dynamic content and good User Interface
🞅 Server side execution
🞅Facebook, Wikipedia, Yahoo, Photo-bucket, &
WordPress
JavaScript
🞅 JavaScript
🞅 Java and JavaScript are two completely different
languages in both concept and design
🞅 Client-side & server-side scripting language
🞅 Enhance dynamics and interactive features of a web
page
🞅 Allows one to perform calculations, write interactive
games, add special effects, customize graphic
selections, create security passwords
🞅 used in millions of web pages
🞅to improve the design
🞅to validate forms
🞅to detect browsers
🞅to create cookies
JavaScript and HTML page
Tells where the JavaScript starts
<html>
<body>
<script type=“text/javascript”>
document.write(“Hello World!”);
</script>
Commands for writing output to a page
</body>
</html> Tells where the JavaScript ends

This code produce the output on an HTML page:


Hello World!
Advantage of Scripting Language

🞅 Scripting languages make the web development work


🞅 Easier
🞅 Faster
🞅 Best utilization of resources
Game Scripting
Language
Game Scripting Language
• Large games are built using various different languages. C++ is very good for
implementing flexible game engines which run fast. But as with any language,
C++ also has its disadvantages. Many games use scripting languages for
animation and gameplay logic.
• This has the advantage of quick prototyping and better organization of code.
Almost every non-trivial game engine uses some scripting language
nowadays.
• Game designers do not necessarily need a C++ compiler on their machine.
Designers need to use a language suitable for their domain.
• They have to spend their time designing, not programming. A scripting
language can expose only those features that they need to build the games
scenes/maps.
• It is beneficial if the game scripting language is interpreted rather than
compiled, as it greatly reduces the amount of time it takes the designer to
prototype a scene or level.
• Game developers usually use scripting languages to animate/direct
character conversations. For example, consider a role-playing game, they
tend to lead the player through a tree-shaped set of choices in
conversation.
• If the character in the game says something like, "Go into the mountains
to find the key", you might expect to find out more by typing the word
"mountain" or "key".
• Scripting languages are also used to handle events. Imagine in the
previous conversation, the character actually walks up to your player
and casts a spell that gave you additional protection on your quest to
retrieve the key.
• These events can be easily defined using scripting languages. This helps
in making stage directions in the game easier.
• The game developer can develop his own scripting language and
customize it according to his requirements. Assuming that the language
syntax is non-trivial, some tools can be used to help define lexicon and
grammar.
There are two tools which are widely used to help perform these tasks:
1. Lex: A utility that generates C programs to be used in simple lexical
analysis of text. In other words, it matches input streams with a series of
regular expressions.
2. Yacc: It stands for "yet another compiler compiler". This tool takes
context free grammar and a stream of tokens and is able to break down
the input stream into a hierarchical data structure. Each node in the
hierarchy corresponds to a statement in the language defined by the
grammar. Each statement is processed by a custom piece of code that
translates the original tokens into your target language, usually a series of
simple statements composed of operators and operands.
Both Lex and Yacc require association of a regular expression or grammar
fragment with an action written in C. The developer is still responsible for
writing the C code to output something that can be used to interpret the
source script into a series of executable or interpretable commands and
parameters.
Interpretation Vs. Compiler
There are two different ways to implement programming languages:
1. Interpretation: A program called an interpreter looks at each line of your
program in turn, works out what it means, executes it, and then goes onto
the next line.
2. Compilation: A program called a compiler reads your program and
translates it into machine code. Then the computer executes the machine
code.
Compilation is like translating a French knitting pattern into English, then
reading the English. Interpretation is like using a French dictionary on each
word in turn as you knit. If there is a loop in the knitting pattern, then the
latter method means you will end up re-translating the same word over
and over again.
Compilation is harder, but the result is more efficient. Also, the internal
representation of compiled programs loses the original structure.
The differences between compilers and interpreters are listed in Table 8.2.
• The performance penalty of interpretation might not be a problem in
certain scenarios.
• If scripts are used to deliver character conversations, handle simple
events and launch other C++ processes it is doubtful that the player
would notice any performance problems.
• One of the benefits of using a scripting language during development is
that the game designer could modify the script and re-run it for ultra-
fast development without reloading the game.
• If the game system can handle this, it will save a lot of time and would
result in a better game.
Languages

• There are many scripting languages suited for game


programming. Lua is perhaps the most popular game scripting
language.
• Other choices include: AngelScript, GameMonkey, Io, Pawn,
Squirrel and Scheme. Sometimes heavyweight languages are
also used, like Python or Ruby.
• These languages are usually quite a bit harder to embed.
Lua
• Lua has its own unique syntax which is very similar to Basic. It is very
fast and compiles into fairly small byte code. It is very dynamic and
variables do not need to be declared before use.
• The functions can be stored in variables. Lua makes extensive use of
tables (associative arrays), which are its only complex data type.
Tables are able to mimic classes and objects, by using some entries
to store functions and some entries to store data.
• Lua has been used extensively in the game industry, has an active
online community and a large base of open source modules. It is
also used by some fairly impressive commercial games, including
SimCity4, World of Warcraft, FarCry, etc.
Python
• Python has been around for a while and is the choice for many computer
games. It is extremely well supported and documented, and is essentially a
fully functioning modern programming language. The entire modern game
could be written in Python, by writing the core engine in C++ and calling it
from within Python.
• An important feature called “generator” is present in Python, which is a
function that can return control to the calling code and resume where it left
off the next time it is called, thereby preserving the value of local variables.
This is extremely useful for scripting events and stage direction in games.
• Python is extensively used in various games, including Eve Online and CivIV.
It is not particularly easy to embed, and requires additional libraries like
Boost before becoming actually useful to the C++ programmer as an
embedded language. Also, it is quite slow, even by scripting standards.
• It does, however, have an excellent built-in support for objects, classes, and
all the modern programming features that make programming easier.

You might also like