Linden Scripting Language
Encyclopedia
Linden Scripting Language, or LSL, is the programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 used by residents of Second Life
Second Life
Second Life is an online virtual world developed by Linden Lab. It was launched on June 23, 2003. A number of free client programs, or Viewers, enable Second Life users, called Residents, to interact with each other through avatars...

, a virtual world
Virtual world
A virtual world is an online community that takes the form of a computer-based simulated environment through which users can interact with one another and use and create objects. The term has become largely synonymous with interactive 3D virtual environments, where the users take the form of...

 by Linden Lab
Linden Lab
Linden Research, Inc., d/b/a Linden Lab, is a privately held American Internet company that is best known as the creator of Second Life....

.

LSL has a syntax similar to C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 and allows objects to control the behavior of in-world objects of Second Life
Second Life
Second Life is an online virtual world developed by Linden Lab. It was launched on June 23, 2003. A number of free client programs, or Viewers, enable Second Life users, called Residents, to interact with each other through avatars...

 from the Internet via email, XML-RPC
XML-RPC
XML-RPC is a remote procedure call protocol which uses XML to encode its calls and HTTP as a transport mechanism. "XML-RPC" also refers generically to the use of XML for remote procedure call, independently of the specific protocol...

, and most recently, HTTP requests.

LSL design

Linden Scripting Language is a state-event driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

 scripting language
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...

, in the sense of a finite state machine
Finite state machine
A finite-state machine or finite-state automaton , or simply a state machine, is a mathematical model used to design computer programs and digital logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states...

.
A script consists of variables, function definitions, and one or more named states. Each state contains a description of how to react to events that occur while the program is within that state. The system sends events to the script, such as timers, movement, chat (from other agents), email, and collisions (with objects in the virtual world). Scripts can change most aspects of the state of the object and communicate with other objects and agents. As soon as a script is added to an object, and turned on, it begins to execute.

A script is tightly bound to the concept of virtual-world objects
3D modeling
In 3D computer graphics, 3D modeling is the process of developing a mathematical representation of any three-dimensional surface of object via specialized software. The product is called a 3D model...

(in the 3D modeling sense rather than in the object-oriented sense). An object in Second Life represents something like a chair or a wall, or possibly something invisible. Multiple scripts may be placed inside an object, where they all execute simultaneously.

There are over 300 library functions available. Users can also define additional functions. LSL is a strongly typed language that is compiled to bytecode
Bytecode
Bytecode, also known as p-code , is a term which has been used to denote various forms of instruction sets designed for efficient execution by a software interpreter as well as being suitable for further compilation into machine code...

 before runtime execution in a virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

 on one of Linden Lab's servers.

LSL's native data structure
Data structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...

s includes integers, floating point numbers, strings
String (computer science)
In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

, keys(UUID), vectors(used for 3D coordinates and RGB color expression) and rotation
Rotation
A rotation is a circular movement of an object around a center of rotation. A three-dimensional object rotates always around an imaginary line called a rotation axis. If the axis is within the body, and passes through its center of mass the body is said to rotate upon itself, or spin. A rotation...

s (quaternion
Quaternion
In mathematics, the quaternions are a number system that extends the complex numbers. They were first described by Irish mathematician Sir William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space...

s). There are also heterogeneous lists. There are no arrays; multiple list functions are used to adapt programs requiring array structures. There is no built-in persistent data storage, such as a file or database. On the other hand, scripts continue to run even when a user is not logged in, and if an object is saved (taken into inventory), and then re-introduced into the World later, it still maintains its previous state. In addition, the mechanisms for communicating via HTTP can be used to store a state externally.

Some functions in LSL have built-in delays, which range from a 0.1-second delay when (for example) requesting string data from a notecard; to a 20-second script pause after sending an e-mail message
Email
Electronic mail, commonly known as email or e-mail, is a method of exchanging digital messages from an author to one or more recipients. Modern email operates across the Internet or other computer networks. Some early email systems required that the author and the recipient both be online at the...

. The delays help prevent developers from writing LSL scripts that could overtax system resources. Memory available to LSL scripts (when compiled as mono
Mono (software)
Mono, pronounced , is a free and open source project led by Xamarin to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime....

) is capped at about 64 KiB
Kibibyte
The kibibyte is a multiple of the unit byte for quantities of digital information. The binary prefix kibi means 1024; therefore, 1 kibibyte is . The unit symbol for the kibibyte is KiB. The unit was established by the International Electrotechnical Commission in 1999 and has been accepted for use...

, which places a practical limit on how much a single script can do, however the ability to use multiple scripts and to call scripts from another script allows the user to pragmatically work around this 64 KiB cap.

Permission system

Certain actions in LSL require permissions:
  • take money from agent's account
  • take agent's controls
  • start or stop Animations on agent
  • attach/detach from agent
  • change links
  • track the agent's camera position and rotation
  • control the agent's camera


The permission system, however, is an issue for scripts owned by the land owner: those scripts can modify the parcel settings without requiring permissions. A malicious script can unsit avatars, ban and unban avatars, destroy the terrain that includes returning of objects by letting them fall out of the World, and gather the ip addresses of avatars by manipulating the media settings for that avatar.

Default LSL script

The default script, "Hello, Avatar", a hello world program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 that speaks (streams message to local chat ("heard" (printed) by all viewers (client
Client (computing)
A client is an application or system that accesses a service made available by a server. The server is often on another computer system, in which case the client accesses the service by way of a network....

s) within 20 meters (3D virtual environment) of the task)) when the script is first saved, initialized or reset (in this case, since the command is in the default "state", the first to be run on initialization) or 'touched' (a simple user interaction usually initiated using a mouse click), looks like:


default
{
state_entry
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer total_number)
{
llSay(0, "Touched.");
}
}

Mono

The revised version of Second Life's scripting virtual machine is based on Mono
Mono (software)
Mono, pronounced , is a free and open source project led by Xamarin to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime....

, the open source implementation of the Microsoft.NET framework. The Mono VM was introduced to several sims on the Second Life Beta grid for compatibility testing on 29 January 2008 and later that year on 20 August 2008 Linden Lab started deploying it on the production grid - with the entire production grid updated to use it on 29 August 2008.

While the LSL scripting language remained the same, scripts executed on the Mono underpinnings were up to 220 times faster in execution, but at the cost of a somewhat higher overhead when creating (rezzing) scripted objects and moving them from simulator to simulator.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK