Global stocks sank Wednesday after US President Donald Trump said he was not satisfied with talks that are aimed at averting a trade war with China. Equities were also dented by poor eurozone economic data, and as Trump cast doubt on a planned summit with North Korean leader Kim Jong Un. “Trump (is) continuing to drive uncertainty over global trade,” said analyst Joshua Mahony at trading firm IG. “European markets are following their Asian counterparts lower, as a pessimistic tone from Trump is compounded by downbeat economic data,” he added. Markets had surged Monday after US Treasury Secretary Steven Mnuchin and Chinese Vice Premier Liu He said they had agreed to pull back from imposing threatened tariffs on billions of dollars of goods, and continue talks on a variety of trade issues. However, Trump has declared that he was “not satisfied” with the status of the talks, fuelling worries that the world’s top two economies could still slug out an economically pain
Lua Procedural Programming Language.
Members of the Computer Graphics Technology Group developed Lua in 1993. It is an imperative and procedural programming language that was designed as a scripting language. It is known for being simple yet powerful.
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 barriers (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.[5]
Lua is commonly described as a "multi-paradigm" language, providing a small set of general features that can be extended to fit different problem types. Lua does not contain explicit support for inheritance, but allows it to be implemented with metatables. Similarly, Lua allows programmers to implement namespaces, classes, and other related features using its single table implementation; first-class functions allow the employment of many techniques from functional programming; and full lexical scoping allows fine-grained information hiding to enforce the principle of least privilege.
In general, Lua strives to provide simple, 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 light—the full reference interpreter is only about 180 kB compiled[3]—and easily adaptable to a broad range of applications.
Lua is a dynamically typed language intended for use as an 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 values, numbers (double-precision floating point and 64-bit integers by default), and strings. Typical data structures such as arrays, sets, lists, and records can be represented using Lua's single native data structure, the table, which is essentially a heterogeneous associative array.
The classic "Hello, World!" program can be written as follows:[8]
or like so:
A comment in Lua starts with a double-hyphen and runs to the end of the line, similar to that of Ada, Eiffel, Haskell, SQL and VHDL. Multi-line strings & comments are adorned with double square brackets.
The factorial function is implemented as a function in this example:
Lua is a dynamically typed language intended for use as an 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 values, numbers (double-precision floating point and 64-bit integers by default), and strings. Typical data structures such as arrays, sets, lists, and records can be represented using Lua's single native data structure, the table, which is essentially a heterogeneous associative array.
Syntax[edit]
The classic "Hello, World!" program can be written as follows:[8]
print("Hello World!")
or like so:
print 'Hello World!'
A comment in Lua starts with a double-hyphen and runs to the end of the line, similar to that of Ada, Eiffel, Haskell, SQL and VHDL. Multi-line strings & comments are adorned with double square brackets.
The factorial function is implemented as a function in this example:
function factorial(n)
local
print("Hello World!")
print 'Hello World!'
function factorial(n)
local
Control flow[edit]
Lua has four types of loops: the while loop, the repeat loop (similar to a do while loop), the numeric for loop, and the generic for loop.
--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
--statements
--example: print(i)
end
The generic for loop:
for key, value in pairs(_G) do
print(key, value)
end
would iterate over the table _G using the standard iterator function pairs, until it returns nil.
You can also do a nested loop, which is a loop inside of another loop.
local objects = { "hello", "hi" }
for i,v in pairs(_G) do
for index,value in pairs(object) do
print(objects[i])
print(value)
end
end
Lua has four types of loops: the while loop, the repeat loop (similar to a do while loop), the numeric for loop, and the generic for loop.
--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
--statements
--example: print(i)
end
The generic for loop:
for key, value in pairs(_G) do
print(key, value)
end
would iterate over the table _G using the standard iterator function pairs, until it returns nil.
You can also do a nested loop, which is a loop inside of another loop.
local objects = { "hello", "hi" }
for i,v in pairs(_G) do
for index,value in pairs(object) do
print(objects[i])
print(value)
end
end
Functions[edit]
Lua's treatment of functions as first-class values is shown in the following example, where the print function's behavior is modified:
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
Any future calls to print will now be routed through the new function, and because of Lua's lexical scoping, the old print function will only be accessible by the new, modified print.
Lua also supports closures, as demonstrated below:
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 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
--This can also be achieved by calling the function in the following way:
print(addto(4)(3))
--[[ This is because we are calling the returned function from `addto(4)' with the argument `3' directly.
This also helps to reduce data cost and up performance if being called iteratively.
]]
A new closure for the variable x is created every time add to is called, so that each new anonymous function returned will always access its own x parameter. The closure is managed by Lua's garbage collector, just like any other object.
Lua's treatment of functions as first-class values is shown in the following example, where the print function's behavior is modified:
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
Any future calls to print will now be routed through the new function, and because of Lua's lexical scoping, the old print function will only be accessible by the new, modified print.
Lua also supports closures, as demonstrated below:
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 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
--This can also be achieved by calling the function in the following way:
print(addto(4)(3))
--[[ This is because we are calling the returned function from `addto(4)' with the argument `3' directly.
This also helps to reduce data cost and up performance if being called iteratively.
]]
A new closure for the variable x is created every time add to is called, so that each new anonymous function returned will always access its own x parameter. The closure is managed by Lua's garbage collector, just like any other object.
Tables[edit]
Tables are the most important data structures (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 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 is a hashed heterogeneous associative array.
Tables are created using the {}
constructor syntax.
a_table = {} -- Creates a new, empty table
Tables are always passed by reference (see Call by sharing).
A key (index) can be any value except nil
and NaN.
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.
A table is often used as structure (or record) by using strings as keys. Because such use is very common, Lua features a special syntax for accessing such fields.[9]
Tables are the most important data structures (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 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 is a hashed heterogeneous associative array.
Tables are created using the {}
constructor syntax.
a_table = {} -- Creates a new, empty table
Tables are always passed by reference (see Call by sharing).
A key (index) can be any value except nil
and NaN.
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.
A table is often used as structure (or record) by using strings as keys. Because such use is very common, Lua features a special syntax for accessing such fields.[9]
Comments
Post a Comment