Simpson's paradox: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
−sp
"disappears" => "disappears or reverses" - early papers only talked about disappearance, Blyth named the reversal "Simpson's Paradox"
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{for|use of the Lua programming language in Wikipedia|Wikipedia:Lua}}
In the exhilaration of locating a casino gambling website, many people eliminate their brains fully and begin to gamble without planning. For a couple hours of fun, most stop with no cash to sacrifice, or worse, a pending appropriate fee. Seasoned participants discover these specific things overtime, and sadly, many, after sacrificing money or legal hassles. For newbies in web casino gambling, below are a few essential regulations that may save from unnecessary failures and legal problems.<br><br>The principles regarding casino gaming or any kind of betting use a fluid character. They're simply modified and typically, vary among states and places. Some states let gambling, while the scenario of the authorized Vegas casinos. But other forms of betting remain illegal, or at times, stay unregulated. This is particularly so for most forms of online-gambling. Thus, it's one of its most elementary policies to analyze and be advised of the guidelines about web gambling within your spot. The best way to get this done isn't by hearsay, fairly, your absolute best solution would be to request the local government or regulators if betting online is authorized or restricted inside your state. Do not forget that no level of online-gambling enjoyment is worth a prison term.<br><br>If betting online is authorized inside your location, you are absolve to search for sportsbook websites or online casinos to begin gambling. However, subscription is standard process to start your gambling career. This frequently involves information that is personal like banking account number, address, cellphone number, your email, as well as your name. Delicate info like these are in threat of being intercepted by hackers or identity thieves. To prevent this, produce server safety an issue in picking your casino betting site. Trustworthy sites post information about their safety technology inside their sites. Another approach is by validating these details by inquiring the operators of your website, either through the use of an alternate email or by telephone.<br><br>When you're satisfied with their security procedures, don't register only yet. Understanding the casino betting sites you're employing and bet on provides you with advantage. Study opinions in regards to the websites or look at websites for a legitimate experience. Websites usually have an info page such as for instance FAQs page or an "About Us" site. Most robust and established websites also provide free trials of the casino or poker software. Obtain these and attempt playing free of charge. Enjoying offers you better insight and invite one to assess the merits of the web site. For those who have several possibilities, obtain their free softwares to find out which pays your gaming needs.<br><br>Of course, casino gambling can also be about earning. It's to your comfort if you are educated about the pay out treatments or bank selections that the casino site presents. Pay-out delays in many cases are brought on by inefficient and gradual pay-outs. People concede that sluggish returns cause turmoil and requires the enjoyment out of enjoying. An efficient bank process additionally indicates excellent customerservice. This implies that the internet site requires your fun and ease really.<br><br>Lastly, gaming online is also about enjoyment. Knowing the casino gambling activities before enrolling makes you willing to enjoy the encounter. Browse the directions and game rules before placing bets and enjoying. It's correct that losing is part of the sport. But, dropping since you don't have a clue about half of what you are accomplishing isn't exciting and can set you back treasured income. Using free casino gaming online courses and other ways boosts the enjoyable component because they enhance your sport. Nothing is more fun than really earning. As you can see on [http://www.amateurnetzwerk.com/index.php?m=member_blog&p=view&id=7493&sid=55069 click this link now].
{{Infobox programming language
| name                  = Lua
| logo                  = [[File:Lua-logo-nolabel.svg|128px]]
|paradigm=[[Multi-paradigm]]: [[scripting language|scripting]], [[imperative programming|imperative]] ([[procedural programming|procedural]], [[prototype-based programming|prototype-based]] [[object-oriented programming|object-oriented]]), [[functional programming|functional]]
| year                  = {{start date and age|1993}}
| designer              = [[Roberto Ierusalimschy]]<br /> Waldemar Celes<br /> Luiz Henrique de Figueiredo
| developer              =
| latest_release_version = 5.2.3
| latest_release_date    = {{Start date|2013|12|07}}
| latest_preview_version =
| latest preview date    =
| typing                = [[Dynamic typing|dynamic]], [[Type system#Strong and weak typing|strong]], [[Duck typing|duck]]
| implementations=[http://www.lua.org/download.html Lua], [http://luajit.org/ LuaJIT], [http://code.google.com/p/llvm-lua/ LLVM-Lua], [http://code.google.com/p/lua-alchemy/ Lua Alchemy]
| programming_language = [[C (programming language)|C]]
| dialects              = [http://metalua.luaforge.net/ Metalua], [http://idle.thomaslauer.com/ Idle], [http://www.nongnu.org/gsl-shell/ GSL Shell]
| influenced_by          = [[C++]], [[CLU (programming language)|CLU]], [[Modula-2|Modula]], [[Scheme (programming language)|Scheme]], [[SNOBOL]]
| influenced=[[Io (programming language)|Io]]<!--2002-->, [[GameMonkey Script|GameMonkey]]<!--2003-->, [[Squirrel (programming language)|Squirrel]]<!--2003-->, [[Falcon (programming language)|Falcon]]<!--2003-->, [[MiniD]]<!--2006-->
| operating_system      = [[Cross-platform]]
| license                = [[MIT License]]
| website                = {{URL|http://www.lua.org/}}
| wikibooks              =
}}
 
'''Lua''' ({{IPAc-en|ˈ|l|uː|ə}} {{respell|LOO|ə}}, from {{lang-pt|[[wikt:lua#Portuguese|lua]]}} {{IPA-pt|ˈlu.(w)ɐ|}} meaning ''[[moon]]''; explicitly not "LUA"<ref name=luaabout>{{cite web| url = http://www.lua.org/about.html#name| title = About Lua| publisher = Lua.org| accessdate = 2013-06-19}}</ref>) is a lightweight [[Multi-paradigm programming language|multi-paradigm]] [[programming language]] designed as a [[scripting language]] with extensible semantics as a primary goal. Lua is [[cross-platform]] since it is written in [[ANSI C]].<ref name=luaabout>{{cite web| url = http://www.lua.org/about.html#why| title = About Lua| publisher = Lua.org| accessdate = 2011-08-11}}</ref> Lua has a relatively simple [[C (programming language)|C]] [[Application programming interface|API]].<ref>{{cite web |url=http://www.foreignaffairs.com/articles/139332/yuri-takhteyev/from-brazil-to-wikipedia?page=2 |title=From Brazil to Wikipedia |work=[[Foreign Affairs]] |author=Yuri Takhteyev |date=April 21, 2013 |accessdate=April 25, 2013}}</ref>
 
== 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]].
 
From 1977 until 1992, Brazil had a policy of strong [[trade barrier]]s (called a market reserve) for computer hardware and software. In that atmosphere, Tecgraf's clients could not afford, either politically or financially, to buy customized software from abroad. Those reasons led Tecgraf to implement the basic tools it needed from scratch.<ref name=hopl2007>{{Cite book| last1 = Ierusalimschy | first1 = R.| author1-link = Roberto Ierusalimschy| last2 = Figueiredo| first2 = L. H. | last3 = Celes| first3 = W.| contribution = The evolution of Lua| contribution-url = http://www.lua.org/doc/hopl.pdf| doi = 10.1145/1238844.1238846| title = Proc. of ACM HOPL III| url = http://www.acm.org/sigs/sigplan/hopl| year = 2007| pages = 2–1–2–26| isbn = 978-1-59593-766-7}}</ref>
 
Lua's historical "father and mother" were data-description/configuration languages ''SOL'' (Simple Object Language) and ''DEL'' (data-entry language).<ref name=luahist2001>{{cite web|url=http://www.lua.org/history.html|title=The evolution of an extension language: a history of Lua|accessdate=2008-12-18|year=2001}}
<!-- {{Cite journal| last1 = Ierusalimschy | first1 = R. | author1-link = Roberto Ierusalimschy| last2 = Figueiredo | first2 = L. H.| last3 = Celes | first3 = W. | contribution = The evolution of an extension language: a history of Lua| contribution-url = http://www.lua.org/history.html| title = Proc. of V Brazilian Symposium on Prog. Lang.| year = 2001| pages = B–14–B–28}} --></ref> They had been independently developed at Tecgraf in 1992–1993 to add some flexibility into two different projects (both were interactive graphical programs for engineering applications at [[Petrobras]] company). There was a lack of any flow control structures in SOL and DEL, and Petrobras felt a growing need to add full programming power to them.
 
As the language's authors wrote, in ''The Evolution of Lua'':
 
{{quote|In 1993, the only real contender was [[Tcl]], which had been explicitly designed to be embedded into applications. However, Tcl had unfamiliar syntax, did not offer good support for data description, and ran only on Unix platforms. We did not consider [[Lisp (programming language)|LISP]] or [[Scheme (programming language)|Scheme]] because of their unfriendly syntax. [[Python (programming language)|Python]] was still in its infancy. In the free, do-it-yourself atmosphere that then reigned in Tecgraf, it was quite natural that we should try to develop our own scripting language&nbsp;... Because many potential users of the language were not professional programmers, the language should avoid cryptic syntax and semantics. The implementation of the new language should be highly portable, because Tecgraf's clients had a very diverse collection of computer platforms. Finally, since we expected that other Tecgraf products would also need to embed a scripting language, the new language should follow the example of SOL and be provided as a library with a C API.<ref name=hopl2007 />}}
 
Lua 1.0 was designed in such a way that its object constructors, being then slightly different from the current light and flexible style, incorporated the data-description syntax of SOL (hence the name Lua – ''sol'' is Portuguese for sun; ''lua'' is moon). Lua [[Syntax (programming languages)|syntax]] for control structures was mostly borrowed from [[Modula]] (if, while, repeat/until), but also had taken influence from [[CLU (programming language)|CLU]] (multiple assignments and multiple returns from function calls, as a simpler alternative to [[Call by reference|reference parameters]] or explicit [[pointer (computer programming)|pointer]]s), [[C++]] ("neat idea of allowing a [[local variable]] to be declared only where we need it"<ref name=hopl2007 />), [[SNOBOL]] and [[AWK]] ([[associative array]]s). In an article published in ''[[Dr. Dobb's Journal]]'', Lua's creators also state that LISP and Scheme with their single, ubiquitous data structure mechanism (the [[List (computing)|list]]) were a major influence on their decision to develop the table as the primary data structure of Lua.<ref name=ddj96>{{Cite news| last1 = Figueiredo | first1 = L. H. | last2 = Ierusalimschy | first2 = R. | last3 = Celes| first3 = W. | title = Lua: an Extensible Embedded Language. A few metamechanisms replace a host of features| magazine = Dr. Dobb's Journal| volume = 21| issue = 12| pages = 26–33| date = December 1996| url = http://www.lua.org/ddj.html}}</ref>
 
Lua [[semantics]] have been increasingly influenced by Scheme over time,<ref name=hopl2007 /> especially with the introduction of [[anonymous function]]s and full lexical scoping.
 
Versions of Lua prior to version 5.0 were released under a license similar to the [[BSD licenses|BSD license]]. From version 5.0 onwards, Lua has been licensed under the [[MIT License]].  Both are [[permissive free software licences]] and are almost identical.
 
==Features==
Lua is commonly described as a “[[Multi-paradigm programming language|multi-paradigm]]” language, providing a small set of general features that can be extended to fit different problem types, rather than providing a more complex and rigid specification to match a single paradigm. Lua, for instance, does not contain explicit support for [[Inheritance (object-oriented programming)|inheritance]], but allows it to be implemented relatively easily with [[metatable]]s. Similarly, Lua allows programmers to implement [[namespaces]], [[Class (computer science)|classes]], and other related features using its single table implementation; [[first-class function]]s allow the employment of many powerful techniques from [[functional programming]]; and full lexical [[Scope (programming)|scoping]] allows fine-grained [[information hiding]] to enforce the [[principle of least privilege]].
 
In general, Lua strives to provide flexible meta-features that can be extended as needed, rather than supply a feature-set specific to one programming paradigm. As a result, the base language is [[Lightweight programming language|light]] – the full reference [[interpreter (computing)|interpreter]] is only about 180&nbsp;[[Kilobyte|kB]] compiled<ref name=luaabout /> – and easily adaptable to a broad range of applications.
 
Lua is a [[dynamically typed]] language intended for use as an [[Scripting language|extension]] or [[scripting language]], and is compact enough to fit on a variety of host platforms. It supports only a small number of atomic data structures such as [[Boolean data type|boolean]] values, [[number]]s (double-precision [[floating point]] by default), and [[string (computer science)|strings]]. Typical data structures such as [[Array data structure|arrays]], [[set (computer science)|sets]], [[List (computing)|lists]], and [[record (computer science)|record]]s can be represented using Lua's single native data structure, the table, which is essentially a heterogeneous [[associative array]].
 
Lua implements a small set of advanced features such as [[first-class function]]s, [[garbage collection (computer science)|garbage collection]], [[Closure (computer science)|closures]], proper [[Tail recursion|tail call]]s, [[Type conversion|coercion]] (automatic conversion between string and number values at run time), [[coroutine]]s (cooperative multitasking) and [[Dynamic loading|dynamic module loading]].
 
By including only a minimum set of data types, Lua attempts to strike a balance between power and size.
 
=== Example code ===
 
The classic [[hello world program]] can be written as follows:
<syntaxhighlight lang="lua">
print('Hello World!')
</syntaxhighlight>
 
[[Comment (computer programming)|Comment]]s use the following syntax, similar to that of [[Ada (programming language)|Ada]], [[Eiffel (programming language)|Eiffel]], [[Haskell (programming language)|Haskell]], [[SQL]] and [[VHDL]]:
<syntaxhighlight lang="lua">
-- A comment in Lua starts with a double-hyphen and runs to the end of the line.
 
--[[ Multi-line strings & comments
    are adorned with double square brackets. ]]
 
--[=[ Comments like this can have other --[[comments]] nested. ]=]
</syntaxhighlight>
 
The [[factorial]] function is implemented as a function in this example:
<syntaxhighlight lang="lua">
function factorial(n)
  local x = 1
  for i = 2,n do
    x = x * i
  end
  return x
end
</syntaxhighlight>
 
=== Loops ===
Lua has four types of [[loop (computing)|loop]]s: the [[while loop|<tt>while</tt> loop]], the <tt>repeat</tt> loop (similar to a [[do while loop|<tt> do while</tt> loop]]), the [[for loop|<tt>for</tt> loop]], and the generic <tt>for</tt> loop.
 
<syntaxhighlight lang="lua">
--condition = true
 
while condition do
  --statements
end
 
repeat
  --statements
until condition
 
for i = first,last,delta do    --delta may be negative, allowing the for loop to count down or up
  print(i)
end
</syntaxhighlight>
 
The generic <tt>for</tt> loop:
<syntaxhighlight lang="lua">
for key, value in pairs(_G) do
  print(key, value)
end
</syntaxhighlight>
would iterate over the table <tt>_G</tt> using the standard iterator function <tt>pairs</tt>, until it returns <tt>nil</tt>.
 
=== Functions ===
Lua's treatment of functions as [[first-class function|first-class]] values is shown in the following example, where the print function's behavior is modified:
<syntaxhighlight lang="lua">
do
  local oldprint = print  -- Store current print function as oldprint
  function print(s)        -- Redefine print function, the usual print function can still be used through oldprint. The new one has only one argument
    oldprint(s == "foo" and "bar" or s)
  end
end
</syntaxhighlight>
Any future calls to <tt>print</tt> will now be routed through the new function, and because of Lua's [[Scope (programming)#Lexical scoping|lexical scoping]], the old print function will only be accessible by the new, modified print.
 
Lua also supports [[Closure (computer science)|closures]], as demonstrated below:
<syntaxhighlight lang="lua">
function addto(x)
  -- Return a new function that adds x to the argument
  return function(y)
    --[[ When we refer to the variable x, which is outside of the current
        scope and whose lifetime would be shorter than that of this anonymous
        function, Lua creates a closure.]]
    return x + y
  end
end
fourplus = addto(4)
print(fourplus(3))  -- Prints 7
</syntaxhighlight>
A new closure for the variable <tt>x</tt> is created every time <tt>addto</tt> is called, so that each new anonymous function returned will always access its own <tt>x</tt> parameter. The closure is managed by Lua's garbage collector, just like any other object.
 
=== Tables ===
Tables are the most important data structure (and, by design, the only built-in [[composite data type]]) in Lua, and are the foundation of all user-created types. They are conceptually similar to [[associative array|associative arrays in PHP, dictionaries in Python and Hashes in Ruby or Perl]].
 
A table is a collection of key and data pairs, where the data is referenced by key; in other words, it's a [[hash table|hashed]] [[Heterogeneity|heterogeneous]] [[associative array]]. A key (index) can be any value but nil and [[NaN]].  A numeric key of <tt>1</tt> is considered distinct from a string key of <tt>"1"</tt>.
 
Tables are created using the <code>{}</code> constructor syntax:
<syntaxhighlight lang="lua">
a_table = {} -- Creates a new, empty table
</syntaxhighlight>
Tables are always passed by reference:
<syntaxhighlight lang="lua">
a_table = {x = 10}  -- Creates a new table, with one entry mapping "x" to the number 10.
print(a_table["x"]) -- Prints the value associated with the string key, in this case 10.
b_table = a_table
b_table["x"] = 20  -- The value in the table has been changed to 20.
print(b_table["x"]) -- Prints 20.
print(a_table["x"]) -- Also prints 20, because a_table and b_table both refer to the same table.
</syntaxhighlight>
 
==== As record ====
A table is often used as [[object composition|structure]] (or [[Record (computer science)|record]]) by using [[string (computer science)|strings]] as keys. Because such use is very common, Lua features a special syntax for accessing such fields.
Example:
<syntaxhighlight lang="lua">
point = { x = 10, y = 20 }  -- Create new table
print(point["x"])            -- Prints 10
print(point.x)              -- Has exactly the same meaning as line above
</syntaxhighlight>
 
==== As namespace ====
By using a table to store related functions, it can act as a namespace.
<syntaxhighlight lang="lua">
Point = {}
 
Point.new = function(x, y)
  return {x = x, y = y}
end
 
Point.set_x = function(point, x)
  point.x = x
end
</syntaxhighlight>
 
==== As array ====
By using a numerical key, the table resembles an [[array data type]]. Lua arrays are 1-based: the first index is 1 rather than 0 as it is for many other programming languages (though an explicit index of 0 is allowed).
 
A simple array of strings:
<syntaxhighlight lang="lua">
array = { "a", "b", "c", "d" }  -- Indices are assigned automatically.
print(array[2])                  -- Prints "b". Automatic indexing in Lua starts at 1.
print(#array)                    -- Prints 4.  # is the length operator for tables and strings.
array[0] = "z"                  -- Zero is a legal index.
print(#array)                    -- Still prints 4, as Lua arrays are 1-based.
</syntaxhighlight>
The length of a table <math>t</math> is defined to be any integer index <math>n</math> such that <math>t[n]</math> is not <tt>nil</tt> and <math>t[n+1]</math> is <tt>nil</tt>; moreover, if <math>t[1]</math> is <tt>nil</tt>, <math>n</math> can be zero. For a regular array, with non-nil values from 1 to a given <math>n</math>, its length is exactly that <math>n</math>, the index of its last value. If the array has "holes" (that is, nil values between other non-nil values), then <tt>#t</tt> can be any of the indices that directly precedes a <tt>nil</tt> value (that is, it may consider any such nil value as the end of the array).<ref>{{cite web|url=http://www.lua.org/manual/5.1/manual.html#2.5.5|title=Lua 5.1 Reference Manual|accessdate=2012-10-16|year=2012}}</ref>
 
An array of objects:
<syntaxhighlight lang="lua">
function Point(x, y)        -- "Point" object constructor
  return { x = x, y = y }  -- Creates and returns a new object (table)
end
array = { Point(10, 20), Point(30, 40), Point(50, 60) }  -- Creates array of points
print(array[2].y)                                        -- Prints 40
</syntaxhighlight>
Using a hash map to emulate an array normally is slower than using an actual array; however, Lua tables are optimized for use as arrays<ref name=lobject_h_array>{{cite web|url=http://www.lua.org/source/5.1/lobject.h.html#array|title=Lua 5.1 Source Code|accessdate=2011-03-24|year=2006}}</ref> to help avoid this issue.<!-- I'd like to find a message on the mailing list from one of the developers, but I can't. Oh well, source code is a pretty trustworthy reference. -->
 
=== Metatables ===
Extensible semantics is a key feature of Lua, and the [[metatable]] concept allows Lua's tables to be customized in powerful ways.  The following example demonstrates an "infinite" table.  For any <math>n</math>, <tt>fibs[n]</tt> will give the <math>n</math><sup>th</sup> [[Fibonacci number]] using [[dynamic programming]] and [[memoization]].
<syntaxhighlight lang="lua">
fibs = { 1, 1 }                                -- Initial values for fibs[1] and fibs[2].
setmetatable(fibs, {
  __index = function(values, n)                --[[ __index is a function predefined by Lua,
                                                    it is called if key "n" does not exist. ]]
    values[n] = values[n - 1] + values[n - 2]  -- Calculate and memoize fibs[n].
    return values[n]
  end
})
</syntaxhighlight>
 
=== Object-oriented programming ===
Although Lua does not have a built-in concept of [[class (computer science)|classes]], they can be implemented using two language features: [[first-class function]]s and tables. By placing functions and related data into a table, an object is formed. [[Inheritance (object-oriented programming)|Inheritance]] (both single and multiple) can be implemented via the [[metatable]] mechanism, telling the object to look up nonexistent methods and fields in parent object(s).
 
There is no such concept as "class" with these techniques; rather, [[prototype-based programming|prototypes]] are used, as in the programming languages [[Self (programming language)|Self]] or [[JavaScript]]. New objects are created either with a [[factory method pattern|factory method]] (that constructs new objects from scratch), or by cloning an existing object.
 
Lua provides some [[syntactic sugar]] to facilitate object orientation. To declare [[Method (computer science)|member functions]] inside a prototype table, one can use <tt>function table:func(args)</tt>, which is equivalent to <tt>function table.func(self, args)</tt>. Calling class methods also makes use of the colon: <tt>object:func(args)</tt> is equivalent to <tt>object.func(object, args)</tt>.
 
Creating a basic [[Vector (geometry)|vector]] object:
<syntaxhighlight lang="lua">
Vector = {}                  -- Create a table to hold the class methods
function Vector:new(x, y, z)  -- The constructor
  local object = { x = x, y = y, z = z }
  setmetatable(object, { __index = Vector })  -- Inheritance
  return object
end
function Vector:magnitude()  -- Another member function
  -- Reference the implicit object using self
  return math.sqrt(self.x^2 + self.y^2 + self.z^2)
end
 
vec = Vector:new(0, 1, 0)    -- Create a vector
print(vec:magnitude())        -- Call a member function using ":" (output: 1)
print(vec.x)                  -- Access a member variable using "." (output: 0)
</syntaxhighlight>
 
== Internals ==
Lua programs are not [[interpreted language|interpreted]] directly from the textual Lua file, but are [[compiler|compiled]] into [[bytecode]] which is then run on the Lua [[virtual machine]]. The compilation process is typically transparent to the user and is performed during [[Run time (program lifecycle phase)|run-time]], but it can be done offline in order to increase loading performance or reduce the memory footprint of the host environment by leaving out the compiler.
 
Like most CPUs, and unlike most virtual machines (which are [[stack machine|stack-based]]), the Lua VM is [[register machine|register-based]], and therefore more closely resembles an actual hardware design. The register architecture both avoids excessive copying of values and reduces the total number of instructions per function. The virtual machine of Lua 5 is one of the first register-based pure VMs to have a wide use.<ref name=lua5impl>{{Cite journal| last1 = Ierusalimschy | first1 = R. | last2 = Figueiredo | first2 = L. H. | last3 = Celes | first3 = W. | title = The implementation of Lua 5.0| journal = J. Of Universal Comp. Sci.| volume = 11| issue = 7| pages = 1159–1176| year = 2005| url = http://www.jucs.org/jucs_11_7/the_implementation_of_lua/jucs_11_7_1159_1176_defigueiredo.html}}</ref> [[Perl 6|Perl]]'s
[[Parrot virtual machine|Parrot]] and [[Android (operating system)|Android]]'s [[Dalvik virtual machine|Dalvik]] are two other well-known register-based VMs.
 
This example is the bytecode listing of the factorial function defined above (as shown by the <tt>luac</tt> 5.1 compiler):<ref name=luavm51instr>{{cite web| author = Kein-Hong Man| title = A No-Frills Introduction to Lua 5.1 VM Instructions| year = 2006| url = http://luaforge.net/docman/view.php/83/98/ANoFrillsIntroToLua51VMInstructions.pdf}}</ref>
 
function <factorial.lua:1,6> (10 instructions, 40 bytes at 003D5818)
1 param, 3 slots, 0 upvalues, 1 local, 3 constants, 0 functions
        1      [2]    EQ              0 0 -1  ; - 0
        2      [2]    JMP            2      ; to 5
        3      [3]    LOADK          1 -2    ; 1
        4      [3]    RETURN          1 2
        5      [5]    GETGLOBAL      1 -3    ; factorial
        6      [5]    SUB            2 0 -2  ; - 1
        7      [5]    CALL            1 2 2
        8      [5]    MUL            1 0 1
        9      [5]    RETURN          1 2
        10      [6]    RETURN          0 1
 
== C API ==
Lua is intended to be embedded into other applications, and accordingly it provides a robust, easy-to-use [[C (programming language)|C]] [[Application Programming Interface|API]]. The API is divided into two parts: the Lua core and the Lua auxiliary library.<ref name="luarefman">{{cite web| url = http://www.lua.org/manual/5.2/| title = Lua 5.2 Reference Manual| publisher = Lua.org| accessdate = 2012-10-23}}</ref>
 
The Lua API is fairly straightforward because its design eliminates the need for manual [[Reference counting|reference management]] in C code, unlike [[Python (programming language)|Python]]'s API. The API, like the language, is minimalistic. Advanced functionality is provided by the auxiliary library, which consists largely of [[preprocessor]] [[Macro (computer science)|macros]] which make complex table operations more palatable.
 
=== Stack ===
The Lua C API is [[Stack (data structure)|stack]] based. Lua provides functions to push and pop most simple C data types (integers, floats, etc.) to and from the stack, as well as functions for manipulating tables through the stack. The Lua stack is somewhat different from a traditional stack; the stack can be indexed directly, for example. Negative indices indicate offsets from the top of the stack (for example, &minus;1 is the last element), while positive indices indicate offsets from the bottom.
 
Marshalling data between C and Lua functions is also done using the stack. To call a Lua function, arguments are pushed onto the stack, and then the <tt>lua_call</tt> is used to call the actual function. When writing a C function to be directly called from Lua, the arguments are popped from the stack.
 
=== Example ===
Here is an example of calling a Lua function from C:
<syntaxhighlight lang="c">
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
 
int main(void)
{
    lua_State *L = luaL_newstate();
    if (luaL_dostring(L, "function foo (x,y) return x+y end")) {
        lua_close(L);
        exit(EXIT_FAILURE);
    }
 
    lua_getglobal(L, "foo");
    lua_pushinteger(L, 5);
    lua_pushinteger(L, 3);
    lua_call(L, 2, 1);
    printf("Result: %d\n", lua_tointeger(L, -1));
    lua_close(L);
    return 0;
}
</syntaxhighlight>
 
Running this example gives:
<pre>$ gcc -o example example.c -llua
$ ./example
Result: 8
</pre>
 
=== Special tables ===
The C API also provides several special tables, located at various “pseudo-indices” in the Lua stack. At <tt>LUA_GLOBALSINDEX</tt> is the globals table, <tt>_G</tt> from within Lua, which is the main [[namespace]]. There is also a registry located at <tt>LUA_REGISTRYINDEX</tt> where C programs can store Lua values for later retrieval.
 
=== Extension and binding ===
It is possible to write extension modules using the Lua API. Extension modules are [[Library (computing)#Dynamic linking|shared objects]] which can be used to extend the functionality of the interpreter by providing native facilities to Lua scripts. From the Lua side, such a module appears as a namespace table holding its functions and variables. Lua scripts may load extension modules using <tt>require</tt>,<ref name=luarefman /> just like modules written in Lua itself.
 
A growing collection of modules known as ''rocks'' are available through a [[package management system]] called ''LuaRocks'',<ref>{{cite web| url = http://www.luarocks.org/| title = LuaRocks| publisher = LuaRocks wiki| accessdate=2009-05-24}}</ref> in the spirit of [[CPAN]], [[RubyGems]] and [[Python eggs|Python Eggs]].
Other modules can be found through the ''Lua Addons'' directory of [http://lua-users.org lua-users.org] wiki.<ref>{{cite web| url = http://lua-users.org/wiki/LuaAddons| title = Lua Addons| publisher = Lua-users wiki| accessdate=2009-05-24}}</ref>
 
There are several packages for creating graphical user interfaces, Perl/POSIX regular expressions, encryption, file compression, and many others. Prewritten Lua [[Language binding|bindings]] exist for most popular programming languages, including other scripting languages.<ref>{{cite web| url = http://lua-users.org/wiki/BindingCodeToLua| title = Binding Code To Lua| publisher = Lua-users wiki| accessdate = 2009-05-24}}</ref> For C++, there are a number of template-based approaches and some automatic binding generators.
 
== Applications ==
 
===Video games===
{{Maincat|Lua-scripted video games}}
 
In [[game development|video game development]], Lua is widely used as a [[scripting language]] by [[Game programmer#Scripter|game programmer]]s, perhaps owing to how easy it is to embed, its fast execution, and its short [[learning curve]].<ref>{{cite web |url=http://stackoverflow.com/questions/38338/why-is-lua-considered-a-game-language |title=Why is Lua considered a game language? |publisher=[[Stack Overflow]] |accessdate=2010-04-23}}</ref>
 
In 2003, a poll conducted by [[GameDev.net]] showed Lua as a most popular scripting language for game programming.<ref>http://web.archive.org/web/20031207171619/http://gamedev.net/gdpolls/viewpoll.asp?ID=163</ref> On January 12, 2012, Lua was announced as a winner of the Front Line Award 2011 from the magazine ''[[Game Developer (magazine)|Game Developer]]'' in the category Programming Tools.<ref>[http://www.gdmag.com/blog/2012/01/front-line-award-winners.php Front Line Award Winners Announced]</ref>
<!--
PLEASE DO NOT ADD Roblox or WoW or any other specific game. Lua is *way* too widely used for us to mention every game, it's unfair to single out just a few, and there's not a good neutral way to pick which would be included.
Please use [[Category:Lua-scripted video games]] or [[Category:Lua-scriptable game engines]] instead.
-->
 
===Other===
{{Refimprove section|date=February 2012}}
Other applications using Lua include:
<!--
Note for editors:
 
  1) any EXTERNAL or RED links are considered NON-NOTABLE and will be removed. You should exert yourself to create an article showing its [[Wikipedia:Notability]] first. See [[WP:WTAF]] for more info.
 
  2) do NOT list any GAMES or game scripting software (such as **ROBLOX**).  Lua games are just too numerous to fit into this article.
 
This section is NOT a DIRECTORY of Lua-related software – please do not perform any classifications besides the ABC sorting. If you feel it is growing too big, just clean it up – drop all entries that violate the above policy, remove a few that you feel are unimportant.
 
Thank you for your understanding.
-->
* [[3DMLW|3DMLW plugin]] uses Lua scripting for animating [[3D computer graphics|3D]] and handling different events.
* [[Adobe Photoshop Lightroom]] uses Lua for its user interface.
* [[Aerospike database|Aerospike Database]] uses Lua as its internal scripting language for its 'UDF' (User Defined Function) capabilities - similar to procedures
* [[Apache HTTP Server]] can use Lua anywhere in the request process (since version 2.3, via the core mod_lua module).
* [[Artweaver]] graphics editor uses Lua for scripting filters.
* [[Awesome (window manager)|Awesome]], a [[window manager]], is written partly in Lua, also using it as its configuration file format
* [[CHDK|The Canon Hack Development Kit]] (CHDK), an open source firmware for Canon cameras, uses Lua as one of two scripting languages.
* [[Celestia]], the astronomy educational program, uses Lua as its scripting language.
* [[Cheat Engine]], a memory editor/debugger, enables Lua scripts to be embedded in its "cheat table" files, and even includes a GUI designer.
* [[Cisco Systems|Cisco]] uses Lua to implement Dynamic Access Policies within the Adaptive Security Appliance.
* Custom applications for the [[Creative Technology]] [[Creative ZEN#ZEN X-Fi2|Zen X-Fi2]] portable media player can be created in Lua.
* [[Damn Small Linux]] uses Lua to provide desktop-friendly interfaces for command-line utilities without sacrificing lots of disk space.
* [[Dolphin Computer Access]] uses Lua scripting to make inaccessible applications [[Accessibility|accessible]] for [[Visual impairment|visually impaired]] computer users with their [[screen reader]] – SuperNova.
* Eyeon's [[Eyeon Fusion|Fusion]] compositor uses embedded Lua for internal and external scripts and also plugin prototyping.
* A fork of the [[Nintendo Entertainment System|NES]] [[emulator]] [[FCE Ultra]] called FCEUX allows for extensions or modifications to games via Lua scripts.
* [[Flame (malware)|Flame]], a large and highly sophisticated piece of [[malware]] being used for cyber [[espionage]].<ref>{{cite web|last=Zetter|first=Kim|title=Meet 'Flame,' The Massive Spy Malware Infiltrating Iranian Computers|publisher=[[Wired News]]|date=May 28, 2012|url=http://www.wired.com/threatlevel/2012/05/flame/}}</ref>
* [[Foldit]], a science-oriented game in [[protein folding]], uses Lua for user scripts. Some of those scripts have been the aim of an article in [[Proceedings of the National Academy of Sciences of the United States of America|PNAS]].<ref>[http://www.pnas.org/content/early/2011/11/02/1115898108 Algorithm discovery by protein folding game players]</ref>
* [[FreePOPs]], an extensible mail proxy, uses Lua to power its web front-end.
* [[Freeswitch]], An open-source telephony platform designed to facilitate the creation of voice and chat driven products in which Lua can be used as a scripting language for call control and call flow among other things.
* [[Ginga (SBTVD Middleware)|Ginga]], the middleware for Brazilian Digital Television System ([[ISDB-T International|SBTVD or ISDB-T]]), uses Lua as a script language to its declarative environment, Ginga-NCL. In Ginga-NCL, Lua is integrated as media objects (called NCLua) inside NCL ([[Nested Context Language]]) documents.
* [[GrafX2]], a pixel-art editor, can run Lua scripts for simple picture processing or generative illustration.
* [[iClone]], a 3D real-time animation studio to create animation movies uses Lua in the controls of its new physic simulation.
* The drawing editor [[Ipe (program)|Ipe]] (mainly used for producing figures with [[LaTeX]] labeling) uses Lua for its functionality and script extensions.
* The IRC bot [http://project.malikania.fr/irccd irccd] uses Lua for creating plugins.
* [[Lego Mindstorms NXT]] and [[Lego Mindstorms NXT 2.0|NXT 2.0]] can be scripted with Lua using third-party software.<ref>[http://www.hempeldesigngroup.com/lego/pbLua/ pbLua]</ref>
* [[lighttpd]] web server uses Lua for hook scripts as well as a modern replacement for the [[Cache Meta Language]].
* Version 2.01 of the profile management software for [[Logitech]]'s [[Logitech G15|G15]] gaming keyboard uses Lua as its scripting language.
* [[LuaTeX]], the designated successor of [[pdfTeX]], allows extensions to be written in Lua.
* [[MySQL Workbench]] uses Lua for its extensions & add-ons.
* [[MySQL Proxy]] uses Lua for its extensions
* [[Nginx]] has a powerful embedded Lua module that provides an API for accessing Nginx facilities like socket handling, for example.<ref>[http://wiki.nginx.org/HttpLuaModule HttpLuaModule]. Wiki.nginx.org. Retrieved on 2013-07-17.</ref>
* [[nmap]] network security scanner uses Lua as the basis for its scripting language, called ''nse''.<ref>{{cite web|title=Nmap Scripting Engine|url=http://nmap.org/book/nse.html|accessdate=2010-04-10}}</ref>
* Wavecom's GSM firmware [[Open AT OS]] allows user applications to be written in Lua.
* [[Project Dogwaffle|Project Dogwaffle Professional]] offers Lua scripting to make filters through the DogLua filter. Lua filters can be shared between Project Dogwaffle, [[GIMP]], Pixarra Twistedbrush and ArtWeaver.
* [[Prosody (software)|Prosody]] is a [[cross-platform]] [[Extensible Messaging and Presence Protocol|Jabber/XMPP]] [[Server (computing)|server]] written in Lua.
* [[Reason (software)|Reason]] digital audio workstation, Lua is used to describe Remote codecs.
* [[Redis]] is an open source key-value database, in which Lua can be used (starting with version 2.6) to write complex functions that run in the server itself, thus extending its functionality.<ref>{{cite web|title=Redis Lua scripting|url=http://redis.io/commands/eval}}</ref>
* [[Renoise]] audio tracker, in which Lua scripting is used to extend functionality.
<!--
PLEASE do NOT add Roblox or any other specific game. Lua is *way* too widely used for us to mention every game, it's unfair to single out just a few, and there's not a good neutral way to pick which would be included.
-->
* [[Rockbox]], the open-source digital audio player firmware, supports plugins written in Lua.
<!-- Read the comments people! -->
* New versions of [[SciTE]] editor can be extended using Lua.
* [[Snort (software)|Snort]] intrusion detection system includes a Lua interpreter since 3.0 beta release.<ref>{{cite web|title=Lua in Snort 3.0|url=http://www.linuxsecurity.com/content/view/128135/171/|accessdate=2010-04-10}}</ref>
* The [[Squeezebox (network music player)|Squeezebox]] music players from Logitech support plugins written in Lua on recent models (Controller, Radio and Touch).
* [[Teamspeak]] has a Lua scripting plugin for modifications.
* [[Tarantool|Tarantool/Box NoSQL database]] uses Lua as its stored procedures language
* [[TI-Nspire]] calculators contain applications written in Lua, since TI added Lua scripting support with a calculator-specific API in OS 3+.
* [[Vim (text editor)|Vim]] has Lua scripting support starting with version 7.3.<ref>{{cite web|title=Vim documentation: if_lua|url=http://vimdoc.sourceforge.net/htmldoc/if_lua.html|accessdate=2011-08-17}}</ref>
 
* [[VLC media player]] uses Lua to provide scripting support.
 
* [[WeeChat]] IRC client allows scripts to be written in Lua.
 
* [[Wikipedia]] since March 2013,<ref>http://www.mediawiki.org/wiki/Lua_scripting</ref>  Lua is used as a new [[templating language]], and its [[:Category:Lua-based templates|template library]] is growing.
* [http://www.mediawiki.org/wiki/Extension:Scribunto MediaWiki/Scribunto], the extension that enables Lua as [[templating language]] on [[MediaWiki]] sites, such as  Wikipedia and other [[Wikimedia Foundation]] wikis.<ref>[[Wikipedia:Wikipedia Signpost/2012-01-30/Technology report|Technology report]], ''[[Wikipedia:Wikipedia Signpost|Wikipedia Signpost]]'' (30 January 2012)</ref>
 
* [[WinGate]] proxy server allows event processing and policy to execute lua scripts with access to internal WinGate objects.
 
* [[Wireshark]] network packet analyzer allows protocol dissectors and post-dissector taps to be written in Lua.<ref>{{cite web|title=Lua in Wireshark|url=http://wiki.wireshark.org/Lua|accessdate=2010-04-10}}</ref>
<!--
PLEASE DO NOT ADD ROBLOX or WoW or any other specific game. Lua is *way* too widely used for us to mention every game, it's unfair to single out just a few, and there's not a good neutral way to pick which would be included.
-->
 
== References ==
{{reflist|30em}}
 
==Further reading==
{{Multicol}}
 
=== Books ===
* {{Cite book | last1 = Gutschmidt | first1 = T. | title = Game Programming with Python, Lua, and Ruby | year = 2003 | publisher = Course Technology PTR | isbn = 1-59200-077-0 }}
* {{Cite book | last1 = Schuytema | first1 = P. | last2 = Manyen | first2 = M. | title = Game Development with Lua | year = 2005 | publisher = Charles River Media | isbn = 1-58450-404-8 }}
* {{Cite book | last1 = Jung  | first1 = K. | last2 = Brown | first2 = A. | title = Beginning Lua Programming | year = 2007 | publisher = [[Wrox Press]] | isbn = 0-470-06917-1 | url = http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470069171.html }}
* {{Cite book| editor-last  = Figueiredo | editor-first  = L. H. | editor2-last = Celes | editor2-first = W. | editor3-last = Ierusalimschy | editor3-first = R. | title = Lua Programming Gems | publisher = Lua.org | year = 2008 | isbn = 978-85-903798-4-3 | url = http://www.lua.org/gems/ }}
* {{Cite book | last = Takhteyev  | first = Yuri | title = Coding Places: Software Practice in a South American City | year = 2012 | publisher = [[The MIT Press]] | isbn = 0262018071 | url = http://codingplaces.net/ }} Chapters 6 and 7 are dedicated to Lua, while others look at software in Brazil more broadly.
* {{cite book | last=Varma | first=Jayant | title=Learn Lua for iOS Game Development | publisher=[[Apress]] | year=2012 | isbn=1430246626 | url=http://www.amazon.com/exec/obidos/ASIN/1430246626/lua-docs-20 }}
* {{Cite book | last1 = Ierusalimschy | first1 = R. | title = Programming in Lua | edition = 3rd | year = 2013 | publisher = Lua.org | isbn = 85-903798-5-X | url = http://www.lua.org/pil/ }} (The 1st ed. is available [http://www.lua.org/pil/contents.html online].)
<!--UPDATEME to 5.2: * {{Cite book | last1 = Ierusalimschy | first1= R. | last2 = Figueiredo | first2 = L. H. | last3 = Celes  | first3 = W. | title = Lua 5.1 Reference Manual | year= 2006 | publisher = Lua.org | isbn= 85-903798-3-3 | url = http://www.lua.org/manual/5.1/ }}-->
 
{{Multicol-break}}
 
===Articles===
* {{cite web | url=http://www.gamedev.net/page/resources/_/technical/game-programming/an-introduction-to-lua-r1932 | title=An Introduction to Lua | publisher=[[GameDev.net]] | date=29 April 2003 | accessdate=January 3, 2013 | author=Matheson, Ash}}
* {{cite web|url=http://www.onlamp.com/pub/a/onlamp/2006/02/16/introducing-lua.html|title=Introducing Lua|last=Fieldhouse|first=Keith|date=16 February 2006|work=ONLamp.com|publisher=[[O'Reilly Media]]}}
* {{cite web|url=http://www.ibm.com/developerworks/linux/library/l-lua.html|title=Embeddable scripting with Lua|last=Streicher|first=Martin|date=28 April 2006|work=developerWorks|publisher=[[IBM]]}}
* {{cite journal |last=Quigley|first=Joseph|date=1 June 2007|title=A Look at Lua|journal=[[Linux Journal]]|url=http://www.linuxjournal.com/article/9605}}
* {{cite news|url=http://www.computerworld.com.au/article/260022/a-z_programming_languages_lua/|title=The A-Z of Programming Languages: Lua|last=Hamilton|first=Naomi|date=11 September 2008|work=[[Computerworld]]|publisher=[[IDG]]}} Interview with Roberto Ierusalimschy.
* {{cite journal |url=http://queue.acm.org/detail.cfm?id=1983083|title=Passing a Language through the Eye of a Needle|last1=Ierusalimschy|first1=Roberto|last2=de Figueiredo|first2=Luiz Henrique |last3=Celes|first3=Waldemar|date=12 May 2011|journal=[[ACM Queue]]|publisher=[[Association for Computing Machinery|ACM]]}} How the embeddability of Lua impacted its design.
* [http://www.lua.org/papers.html Lua papers and theses]
{{Multicol-end}}
 
== External links ==
{{commons category|Lua (programming language)}}
{{wikibooks|Lua Functional Programming}}
{{Wikiversity | Lua}}
{{MediaWiki|Lua}}
* {{official website|http://www.lua.org/}}
* [http://lua-users.org lua-users.org] – Community website for and by users (and authors) of Lua
* [http://www.eluaproject.net/en_overview.html eLua – Embedded Lua]
* [http://luaforge.net Projects in Lua]
* [http://code.google.com/p/squilu/ SquiLu Squirrel modified with Lua libraries]
 
{{Lua programming language}}
{{FOSS}}
{{Use dmy dates|date=April 2011}}
 
{{DEFAULTSORT:Lua (Programming Language)}}
[[Category:Lua (programming language)| ]]
[[Category:Brazilian inventions]]
[[Category:Cross-platform software]]
[[Category:Embedded systems]]
[[Category:Free compilers and interpreters]]
[[Category:Free computer libraries]]
[[Category:Free software programmed in C]]
[[Category:Object-oriented programming languages]]
[[Category:Prototype-based programming languages]]
[[Category:Register-based virtual machines]]
[[Category:Scripting languages]]
[[Category:Software using the MIT license]]
[[Category:Programming languages created in 1993]]

Latest revision as of 14:26, 5 January 2015

In the exhilaration of locating a casino gambling website, many people eliminate their brains fully and begin to gamble without planning. For a couple hours of fun, most stop with no cash to sacrifice, or worse, a pending appropriate fee. Seasoned participants discover these specific things overtime, and sadly, many, after sacrificing money or legal hassles. For newbies in web casino gambling, below are a few essential regulations that may save from unnecessary failures and legal problems.

The principles regarding casino gaming or any kind of betting use a fluid character. They're simply modified and typically, vary among states and places. Some states let gambling, while the scenario of the authorized Vegas casinos. But other forms of betting remain illegal, or at times, stay unregulated. This is particularly so for most forms of online-gambling. Thus, it's one of its most elementary policies to analyze and be advised of the guidelines about web gambling within your spot. The best way to get this done isn't by hearsay, fairly, your absolute best solution would be to request the local government or regulators if betting online is authorized or restricted inside your state. Do not forget that no level of online-gambling enjoyment is worth a prison term.

If betting online is authorized inside your location, you are absolve to search for sportsbook websites or online casinos to begin gambling. However, subscription is standard process to start your gambling career. This frequently involves information that is personal like banking account number, address, cellphone number, your email, as well as your name. Delicate info like these are in threat of being intercepted by hackers or identity thieves. To prevent this, produce server safety an issue in picking your casino betting site. Trustworthy sites post information about their safety technology inside their sites. Another approach is by validating these details by inquiring the operators of your website, either through the use of an alternate email or by telephone.

When you're satisfied with their security procedures, don't register only yet. Understanding the casino betting sites you're employing and bet on provides you with advantage. Study opinions in regards to the websites or look at websites for a legitimate experience. Websites usually have an info page such as for instance FAQs page or an "About Us" site. Most robust and established websites also provide free trials of the casino or poker software. Obtain these and attempt playing free of charge. Enjoying offers you better insight and invite one to assess the merits of the web site. For those who have several possibilities, obtain their free softwares to find out which pays your gaming needs.

Of course, casino gambling can also be about earning. It's to your comfort if you are educated about the pay out treatments or bank selections that the casino site presents. Pay-out delays in many cases are brought on by inefficient and gradual pay-outs. People concede that sluggish returns cause turmoil and requires the enjoyment out of enjoying. An efficient bank process additionally indicates excellent customerservice. This implies that the internet site requires your fun and ease really.

Lastly, gaming online is also about enjoyment. Knowing the casino gambling activities before enrolling makes you willing to enjoy the encounter. Browse the directions and game rules before placing bets and enjoying. It's correct that losing is part of the sport. But, dropping since you don't have a clue about half of what you are accomplishing isn't exciting and can set you back treasured income. Using free casino gaming online courses and other ways boosts the enjoyable component because they enhance your sport. Nothing is more fun than really earning. As you can see on click this link now.