initial release
This commit is contained in:
BIN
cosmic rage/Dina.fon
Normal file
BIN
cosmic rage/Dina.fon
Normal file
Binary file not shown.
188
cosmic rage/Example_filters.lua
Normal file
188
cosmic rage/Example_filters.lua
Normal file
@@ -0,0 +1,188 @@
|
||||
-- ---------------------------------------------------------------
|
||||
-- Example Trigger filters (paste into "filter by" script box
|
||||
-- in the trigger list).
|
||||
-- ---------------------------------------------------------------
|
||||
|
||||
|
||||
function send_to_script (name, trigger)
|
||||
return trigger.send_to == sendto.script and
|
||||
trigger.enabled
|
||||
end -- send_to_script
|
||||
|
||||
function enabled (name, trigger)
|
||||
return trigger.enabled
|
||||
end -- enabled
|
||||
|
||||
function disabled (name, trigger)
|
||||
return not trigger.enabled
|
||||
end -- disabled
|
||||
|
||||
function keep_evaluating (name, trigger)
|
||||
return trigger.keep_evaluating
|
||||
end -- keep_evaluating
|
||||
|
||||
function badscript (name, trigger)
|
||||
return not trigger.script_valid and
|
||||
trigger.script ~= ""
|
||||
end -- badscript
|
||||
|
||||
function temporary (name, trigger)
|
||||
return trigger.temporary
|
||||
end -- temporary
|
||||
|
||||
function matched (name, trigger)
|
||||
return trigger.times_matched > 0
|
||||
end -- matched
|
||||
|
||||
function unmatched (name, trigger)
|
||||
return trigger.times_matched == 0
|
||||
end -- unmatched
|
||||
|
||||
-- if they cancel, show everything
|
||||
function everything (name, trigger)
|
||||
return true
|
||||
end -- everything
|
||||
|
||||
-- choose which function to use
|
||||
result = utils.listbox ("Choose type of filtering", "Triggers",
|
||||
{
|
||||
send_to_script = "Send to script and enabled",
|
||||
enabled = "Enabled items",
|
||||
disabled = "Disabled items",
|
||||
badscript = "Script name not found",
|
||||
keep_evaluating = "Keep evaluating",
|
||||
temporary = "Temporary triggers",
|
||||
matched = "Ones that matched something",
|
||||
unmatched = "Ones that never matched",
|
||||
},
|
||||
"badscript") -- default
|
||||
|
||||
-- use that function
|
||||
filter = _G [result] or everything
|
||||
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------
|
||||
-- Example Alias filters (paste into "filter by" script box
|
||||
-- in the alias list).
|
||||
-- ---------------------------------------------------------------
|
||||
|
||||
function send_to_script (name, alias)
|
||||
return alias.send_to == sendto.script and
|
||||
alias.enabled
|
||||
end -- send_to_script
|
||||
|
||||
function enabled (name, alias)
|
||||
return alias.enabled
|
||||
end -- enabled
|
||||
|
||||
function disabled (name, alias)
|
||||
return not alias.enabled
|
||||
end -- disabled
|
||||
|
||||
function keep_evaluating (name, alias)
|
||||
return alias.keep_evaluating
|
||||
end -- keep_evaluating
|
||||
|
||||
function badscript (name, alias)
|
||||
return not alias.script_valid and
|
||||
alias.script ~= ""
|
||||
end -- badscript
|
||||
|
||||
function temporary (name, alias)
|
||||
return alias.temporary
|
||||
end -- temporary
|
||||
|
||||
function matched (name, alias)
|
||||
return alias.times_matched > 0
|
||||
end -- matched
|
||||
|
||||
function unmatched (name, alias)
|
||||
return alias.times_matched == 0
|
||||
end -- unmatched
|
||||
|
||||
-- if they cancel, show everything
|
||||
function everything (name, alias)
|
||||
return true
|
||||
end -- everything
|
||||
|
||||
-- choose which function to use
|
||||
result = utils.listbox ("Choose type of filtering", "Aliases",
|
||||
{
|
||||
send_to_script = "Send to script and enabled",
|
||||
enabled = "Enabled items",
|
||||
disabled = "Disabled items",
|
||||
badscript = "Script name not found",
|
||||
keep_evaluating = "Keep evaluating",
|
||||
temporary = "Temporary aliases",
|
||||
matched = "Ones that matched something",
|
||||
unmatched = "Ones that never matched",
|
||||
},
|
||||
"badscript") -- default
|
||||
|
||||
-- use that function
|
||||
filter = _G [result] or everything
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------
|
||||
-- Example Timer filters (paste into "filter by" script box
|
||||
-- in the timer list).
|
||||
-- ---------------------------------------------------------------
|
||||
|
||||
|
||||
function send_to_script (name, timer)
|
||||
return timer.send_to == sendto.script and
|
||||
timer.enabled
|
||||
end -- send_to_script
|
||||
|
||||
function enabled (name, timer)
|
||||
return timer.enabled
|
||||
end -- enabled
|
||||
|
||||
function disabled (name, timer)
|
||||
return not timer.enabled
|
||||
end -- disabled
|
||||
|
||||
function one_shot (name, timer)
|
||||
return timer.one_shot
|
||||
end -- one_shot
|
||||
|
||||
function badscript (name, timer)
|
||||
return not timer.script_valid and
|
||||
timer.script ~= ""
|
||||
end -- badscript
|
||||
|
||||
function temporary (name, timer)
|
||||
return timer.temporary
|
||||
end -- temporary
|
||||
|
||||
function fired (name, timer)
|
||||
return timer.times_fired > 0
|
||||
end -- fired
|
||||
|
||||
function not_fired (name, timer)
|
||||
return timer.times_fired == 0
|
||||
end -- not_fired
|
||||
|
||||
-- if they cancel, show everything
|
||||
function everything (name, timer)
|
||||
return true
|
||||
end -- everything
|
||||
|
||||
-- choose which function to use
|
||||
result = utils.listbox ("Choose type of filtering", "Timers",
|
||||
{
|
||||
send_to_script = "Send to script and enabled",
|
||||
enabled = "Enabled items",
|
||||
disabled = "Disabled items",
|
||||
badscript = "Script name not found",
|
||||
one_shot = "One-shot timers",
|
||||
temporary = "Temporary timers",
|
||||
fired = "Ones that fired",
|
||||
not_fired = "Ones that never fired",
|
||||
},
|
||||
"badscript") -- default
|
||||
|
||||
-- use that function
|
||||
filter = _G [result] or everything
|
||||
|
||||
BIN
cosmic rage/MUSHCLIENT.HLP
Normal file
BIN
cosmic rage/MUSHCLIENT.HLP
Normal file
Binary file not shown.
BIN
cosmic rage/MUSHclient.exe
Normal file
BIN
cosmic rage/MUSHclient.exe
Normal file
Binary file not shown.
78
cosmic rage/MUSHclient.ini
Normal file
78
cosmic rage/MUSHclient.ini
Normal file
@@ -0,0 +1,78 @@
|
||||
[CtrlBars-Summary]
|
||||
Bars=7
|
||||
ScreenCX=1280
|
||||
ScreenCY=720
|
||||
[CtrlBars-Bar0]
|
||||
BarID=59392
|
||||
XPos=-2
|
||||
YPos=-2
|
||||
Docking=1
|
||||
MRUDockID=0
|
||||
MRUDockLeftPos=-2
|
||||
MRUDockTopPos=-2
|
||||
MRUDockRightPos=263
|
||||
MRUDockBottomPos=24
|
||||
MRUFloatStyle=8196
|
||||
MRUFloatXPos=-1
|
||||
MRUFloatYPos=688
|
||||
[CtrlBars-Bar1]
|
||||
BarID=59393
|
||||
[CtrlBars-Bar2]
|
||||
BarID=128
|
||||
XPos=-2
|
||||
YPos=22
|
||||
Docking=1
|
||||
MRUDockID=0
|
||||
MRUDockLeftPos=-2
|
||||
MRUDockTopPos=22
|
||||
MRUDockRightPos=476
|
||||
MRUDockBottomPos=48
|
||||
MRUFloatStyle=8196
|
||||
MRUFloatXPos=-1
|
||||
MRUFloatYPos=688
|
||||
[CtrlBars-Bar3]
|
||||
BarID=32944
|
||||
XPos=-2
|
||||
YPos=46
|
||||
Docking=1
|
||||
MRUDockID=0
|
||||
MRUDockLeftPos=-2
|
||||
MRUDockTopPos=46
|
||||
MRUDockRightPos=239
|
||||
MRUDockBottomPos=72
|
||||
MRUFloatStyle=8196
|
||||
MRUFloatXPos=-1
|
||||
MRUFloatYPos=0
|
||||
[CtrlBars-Bar4]
|
||||
BarID=32988
|
||||
XPos=-2
|
||||
YPos=-2
|
||||
Docking=1
|
||||
MRUDockID=0
|
||||
MRUDockLeftPos=-2
|
||||
MRUDockTopPos=-2
|
||||
MRUDockRightPos=1005
|
||||
MRUDockBottomPos=19
|
||||
MRUFloatStyle=4
|
||||
MRUFloatXPos=-1
|
||||
MRUFloatYPos=0
|
||||
[CtrlBars-Bar5]
|
||||
BarID=59419
|
||||
Bars=7
|
||||
Bar#0=0
|
||||
Bar#1=59392
|
||||
Bar#2=0
|
||||
Bar#3=128
|
||||
Bar#4=0
|
||||
Bar#5=32944
|
||||
Bar#6=0
|
||||
[CtrlBars-Bar6]
|
||||
BarID=59422
|
||||
Bars=3
|
||||
Bar#0=0
|
||||
Bar#1=32988
|
||||
Bar#2=0
|
||||
[Recent File List]
|
||||
File1=C:\Users\mario\Cosmic Rage Soundpack GIT\Mush Repo\Mush-Soundpack\cosmic rage\worlds\Cosmic Rage\cosmic rage.MCL
|
||||
File2=D:\my files\repos\Mush-Soundpack\cosmic rage\worlds\Cosmic Rage\cosmic rage.MCL
|
||||
File3=C:\Users\user\Documents\Mush\MUSHclient\worlds\Cosmic Rage\cosmic rage.MCL
|
||||
BIN
cosmic rage/audio.dll
Normal file
BIN
cosmic rage/audio.dll
Normal file
Binary file not shown.
BIN
cosmic rage/bass.dll
Normal file
BIN
cosmic rage/bass.dll
Normal file
Binary file not shown.
28
cosmic rage/docs/JSON License.txt
Normal file
28
cosmic rage/docs/JSON License.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
The following license is applied to all documents in this project with the
|
||||
exception of the 'tests' directory at the root.
|
||||
The 'tests' directory is dual-licenses Public Domain / MIT, whichever is
|
||||
least restrictive in your legal jurisdiction.
|
||||
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2008 Thomas Harning Jr. <harningt@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
--
|
||||
24
cosmic rage/docs/Lua Colors LICENSE.txt
Normal file
24
cosmic rage/docs/Lua Colors LICENSE.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
Copyright (c) 2007, 2008 Yuri Takhteyev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
--
|
||||
206
cosmic rage/docs/LuaJSON.txt
Normal file
206
cosmic rage/docs/LuaJSON.txt
Normal file
@@ -0,0 +1,206 @@
|
||||
LuaJSON(3)
|
||||
==========
|
||||
:Author: Thomas Harning
|
||||
:Email: harningt@gmail.com
|
||||
:Date: 2009/04/29
|
||||
|
||||
NAME
|
||||
----
|
||||
luajson - JSON encoder/decoder for Lua
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
require("json")
|
||||
|
||||
json.decode("json-string" [, parameters])
|
||||
|
||||
json.decode.getDecoder(parameters)
|
||||
|
||||
json.encode(lua_value [, parameters])
|
||||
|
||||
json.encode.getEncoder(parameters)
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
json.decode("json-string" [, parameters])::
|
||||
Obtains a JSON decoder using `getDecoder` with the parameters specified,
|
||||
then performs the decoding operation.
|
||||
|
||||
json.encode(lua_value [, parameters])::
|
||||
Obtains a JSON encoder using `getEncoder` with the parameters specified,
|
||||
then performs the encoding operation.
|
||||
|
||||
json.decode.getDecoder(parameters)::
|
||||
Obtains a JSON decoder configured with the given parameters or defaults.
|
||||
|
||||
json.encode.getEncoder(parameters)::
|
||||
Obtains a JSON encoder configured with the given parameters or defaults.
|
||||
|
||||
json.encode.strict::
|
||||
A default parameter specification containing 'strict' rules for encoding
|
||||
|
||||
json.decode.strict::
|
||||
A default parameter specification containing 'strict' rules for decoding
|
||||
|
||||
=== COMMON PARAMETERS
|
||||
|
||||
initialObject : boolean::
|
||||
Specifies if the outermost element be an array or object
|
||||
|
||||
allowUndefined : boolean::
|
||||
Specifies if 'undefined' is an allowed value
|
||||
|
||||
null : any::
|
||||
Placeholder object for null values
|
||||
|
||||
undefined : any::
|
||||
Placeholder for undefined values
|
||||
|
||||
number.nan : boolean::
|
||||
Specifies if NaN is an allowed value
|
||||
|
||||
number.inf : boolean::
|
||||
Specifies if +/-Infinity is an allowed value
|
||||
|
||||
=== ENCODER-SPECIFIC PARAMETERS
|
||||
|
||||
preProcess : `function(object)`::
|
||||
Called for every value to be encoded, optionally altering.
|
||||
If returns `nil` then no value change occurs.
|
||||
|
||||
output : function::
|
||||
Function that returns an encoder specification (TBD), if null
|
||||
default used that returns a string.
|
||||
|
||||
array.isArray : `function(object)`::
|
||||
If `true`/`false` returned, then the value is authoritatively
|
||||
an array or not
|
||||
|
||||
strings.xEncode : boolean::
|
||||
Specifies if binary values are to be encoded with \xNN rather than \uNNNN
|
||||
|
||||
strings.encodeSet : string::
|
||||
http://www.lua.org/manual/5.1/manual.html#5.4.1[gmatch-style] set of
|
||||
characters that need to be escaped (to be contained in `[]`)
|
||||
|
||||
strings.encodeSetAppend : string::
|
||||
Set of characters that need to be escaped (to be contained in `[]`).
|
||||
Appended to the current encodeSet.
|
||||
|
||||
==== Default Configuration
|
||||
[source,lua]
|
||||
----
|
||||
array.isArray == json-util's isArray implementation
|
||||
allowUndefined = true
|
||||
number.nan = true
|
||||
number.inf = true
|
||||
strings.xEncode = false
|
||||
strings.encodeSet = '\\"/%z\1-\031'
|
||||
----
|
||||
|
||||
==== Strict Configuration
|
||||
[source,lua]
|
||||
----
|
||||
initialObject = true
|
||||
allowUndefined = false
|
||||
number.nan = false
|
||||
number.inf = false
|
||||
----
|
||||
|
||||
=== DECODER-SPECIFIC PARAMETERS
|
||||
|
||||
unicodeWhitespace : boolean::
|
||||
Specifies if unicode whitespace characters are counted
|
||||
|
||||
array.trailingComma / object.trailingComma : boolean::
|
||||
Specifies if extraneous trailing commas are ignored in declaration
|
||||
|
||||
calls.defs : map<string | LPEG, function | boolean>::
|
||||
Defines set of specifically permitted function definitions.
|
||||
If boolean value, determines if allowed or not, decoded as a call object.
|
||||
Function return-value is the decoded result.
|
||||
Function definition: `function(name, [arguments])` : output-value
|
||||
|
||||
calls.allowUndefined : boolean::
|
||||
Specifies if undefined call definitions are decoded as call objects.
|
||||
|
||||
number.frac : boolean::
|
||||
Specifies if numbers can have a decimal component (ex: `.01`)
|
||||
|
||||
number.exp : boolean::
|
||||
Specifies if exponents are allowed (ex: `1e2`)
|
||||
|
||||
number.hex : boolean::
|
||||
Specifies if hexadecimal numbers are allowed (ex: `0xDEADBEEF`)
|
||||
|
||||
object.number : boolean::
|
||||
Specifies if numbers can be object keys
|
||||
|
||||
object.identifier : boolean::
|
||||
Specifies if unquoted 'identifiers' can be object keys (matching `[A-Za-z_][A-Za-z0-9_]*`)
|
||||
|
||||
strings.badChars : string::
|
||||
Set of characters that should not be present in a string
|
||||
|
||||
strings.additionalEscapes : LPeg expression::
|
||||
LPeg expression to handle output (ex: `lpeg.C(1)` would take `\k` and spit out `k`)
|
||||
|
||||
strings.escapeCheck : non-consuming LPeg expression::
|
||||
LPeg expression to check if a given character is allowed to be an escape value
|
||||
|
||||
strings.decodeUnicode::
|
||||
`function (XX, YY)` handling \uXXYY situation to output decoded unicode sequence
|
||||
|
||||
strings.strict_quotes : boolean::
|
||||
Specifies if the `'` character is considered a quoting specifier
|
||||
|
||||
==== Default configuration
|
||||
|
||||
[source,lua]
|
||||
----
|
||||
unicodeWhitespace = true
|
||||
initialObject = false
|
||||
allowUndefined = true
|
||||
array.trailingComma = true
|
||||
number.frac = true
|
||||
number.exp = true
|
||||
number.hex = false
|
||||
object.number = true
|
||||
object.identifier = true
|
||||
object.trailingComma = true
|
||||
strings.badChars = '' -- No characters considered bad in a string
|
||||
strings.additionalEscapes = false, -- disallow untranslated escapes
|
||||
strings.escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'),
|
||||
strings.decodeUnicode = utf8DecodeUnicode,
|
||||
strings.strict_quotes = false
|
||||
----
|
||||
|
||||
==== Strict configuration
|
||||
|
||||
[source,lua]
|
||||
----
|
||||
initialObject = true
|
||||
allowUndefined = false
|
||||
array.trailingComma = false
|
||||
object.identifier = false
|
||||
object.trailingComma = false
|
||||
strings.badChars = '\b\f\n\r\t\v'
|
||||
strings.additionalEscapes = false -- no additional escapes
|
||||
strings.escapeCheck = #lpeg.S('bfnrtv/\\"u') --only these are allowed to be escaped
|
||||
strings.strict_quotes = true
|
||||
----
|
||||
|
||||
AUTHOR
|
||||
------
|
||||
Written by Thomas Harning Jr., <harningt@gmail.com>
|
||||
|
||||
REFERENCES
|
||||
----------
|
||||
http://www.inf.puc-rio.br/~roberto/lpeg[LPeg]
|
||||
|
||||
http://json.org[JSON]
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright (C) 2008-2009 Thomas Harning Jr. Free use of this software is granted
|
||||
under the terms of the MIT license.
|
||||
132
cosmic rage/docs/LuaSocket_documentation/dns.html
Normal file
132
cosmic rage/docs/LuaSocket_documentation/dns.html
Normal file
@@ -0,0 +1,132 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: DNS support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, DNS, Network, Library, Support">
|
||||
<title>LuaSocket: DNS support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- dns ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=dns>DNS</h2>
|
||||
|
||||
<p>
|
||||
Name resolution functions return <em>all</em> information obtained from the
|
||||
resolver in a table of the form:
|
||||
</p>
|
||||
|
||||
<blockquote><tt>
|
||||
resolved = {<br>
|
||||
name = <i>canonic-name</i>,<br>
|
||||
alias = <i>alias-list</i>,<br>
|
||||
ip = <i>ip-address-list</i><br>
|
||||
}
|
||||
</tt> </blockquote>
|
||||
|
||||
<p>
|
||||
Note that the <tt>alias</tt> list can be empty.
|
||||
</p>
|
||||
|
||||
<!-- gethostname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=gethostname>
|
||||
socket.dns.<b>gethostname()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns the standard host name for the machine as a string.
|
||||
</p>
|
||||
|
||||
<!-- tohostname +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=tohostname>
|
||||
socket.dns.<b>tohostname(</b>address<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts from IP address to host name.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a string with the canonic host name of the given
|
||||
<tt>address</tt>, followed by a table with all information returned by
|
||||
the resolver. In case of error, the function returns <b><tt>nil</tt></b>
|
||||
followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- toip +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=toip>
|
||||
socket.dns.<b>toip(</b>address<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts from host name to IP address.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or host name.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Returns a string with the first IP address found for <tt>address</tt>,
|
||||
followed by a table with all information returned by the resolver.
|
||||
In case of error, the function returns <b><tt>nil</tt></b> followed by an error
|
||||
message.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:07 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
289
cosmic rage/docs/LuaSocket_documentation/ftp.html
Normal file
289
cosmic rage/docs/LuaSocket_documentation/ftp.html
Normal file
@@ -0,0 +1,289 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: FTP support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, FTP, Network, Library, Support">
|
||||
<title>LuaSocket: FTP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=ftp>FTP</h2>
|
||||
|
||||
<p>
|
||||
FTP (File Transfer Protocol) is a protocol used to transfer files
|
||||
between hosts. The <tt>ftp</tt> namespace offers thorough support
|
||||
to FTP, under a simple interface. The implementation conforms to
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc0959.txt">RFC 959</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
High level functions are provided supporting the most common operations.
|
||||
These high level functions are implemented on top of a lower level
|
||||
interface. Using the low-level interface, users can easily create their
|
||||
own functions to access <em>any</em> operation supported by the FTP
|
||||
protocol. For that, check the implementation.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To really benefit from this module, a good understanding of
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
LTN012, Filters sources and sinks</a> is necessary.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>ftp</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the FTP module and any libraries it requires
|
||||
local ftp = require("socket.ftp")
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
URLs MUST conform to
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc1738.txt">RFC
|
||||
1738</a>, that is, an URL is a string in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<tt>
|
||||
[ftp://][<user>[:<password>]@]<host>[:<port>][/<path>][<i>type</i>=a|i]</tt>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
The following constants in the namespace can be set to control the default behavior of
|
||||
the FTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>PASSWORD</tt>: default anonymous password.
|
||||
<li> <tt>PORT</tt>: default port used for the control connection;
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;
|
||||
<li> <tt>USER</tt>: default anonymous user;
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- ftp.get ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=get>
|
||||
ftp.<b>get(</b>url<b>)</b><br>
|
||||
ftp.<b>get{</b><br>
|
||||
host = <i>string</i>,<br>
|
||||
sink = <i>LTN12 sink</i>,<br>
|
||||
argument <i>or</i> path = <i>string</i>,<br>
|
||||
[user = <i>string</i>,]<br>
|
||||
[password = <i>string</i>]<br>
|
||||
[command = <i>string</i>,]<br>
|
||||
[port = <i>number</i>,]<br>
|
||||
[type = <i>string</i>,]<br>
|
||||
[step = <i>LTN12 pump step</i>,]<br>
|
||||
[create = <i>function</i>]<br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
The <tt>get</tt> function has two forms. The simple form has fixed
|
||||
functionality: it downloads the contents of a URL and returns it as a
|
||||
string. The generic form allows a <em>lot</em> more control, as explained
|
||||
below.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
If the argument of the <tt>get</tt> function is a table, the function
|
||||
expects at least the fields <tt>host</tt>, <tt>sink</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
sink that will receive the downloaded data. <tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
optional arguments are the following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>user</tt>, <tt>password</tt>: User name and password used for
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";
|
||||
<li><tt>command</tt>: The FTP command used to obtain data. Defaults to
|
||||
"<tt>retr</tt>", but see example below;
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
If successful, the simple version returns the URL contents as a
|
||||
string, and the generic function returns 1. In case of error, both
|
||||
functions return <b><tt>nil</tt></b> and an error message describing the
|
||||
error.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
|
||||
-- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br",
|
||||
-- and get file "lua.tar.gz" from directory "pub/lua" as binary.
|
||||
f, e = ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua/lua.tar.gz;type=i")
|
||||
</pre>
|
||||
|
||||
<pre class=example>
|
||||
-- load needed modules
|
||||
local ftp = require("socket.ftp")
|
||||
local ltn12 = require("ltn12")
|
||||
local url = require("socket.url")
|
||||
|
||||
-- a function that returns a directory listing
|
||||
function nlst(u)
|
||||
local t = {}
|
||||
local p = url.parse(u)
|
||||
p.command = "nlst"
|
||||
p.sink = ltn12.sink.table(t)
|
||||
local r, e = ftp.get(p)
|
||||
return r and table.concat(t), e
|
||||
end
|
||||
</pre>
|
||||
|
||||
<!-- put ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=put>
|
||||
ftp.<b>put(</b>url, content<b>)</b><br>
|
||||
ftp.<b>put{</b><br>
|
||||
host = <i>string</i>,<br>
|
||||
source = <i>LTN12 sink</i>,<br>
|
||||
argument <i>or</i> path = <i>string</i>,<br>
|
||||
[user = <i>string</i>,]<br>
|
||||
[password = <i>string</i>]<br>
|
||||
[command = <i>string</i>,]<br>
|
||||
[port = <i>number</i>,]<br>
|
||||
[type = <i>string</i>,]<br>
|
||||
[step = <i>LTN12 pump step</i>,]<br>
|
||||
[create = <i>function</i>]<br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
The <tt>put</tt> function has two forms. The simple form has fixed
|
||||
functionality: it uploads a string of content into a URL. The generic form
|
||||
allows a <em>lot</em> more control, as explained below.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
If the argument of the <tt>put</tt> function is a table, the function
|
||||
expects at least the fields <tt>host</tt>, <tt>source</tt>, and one of
|
||||
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
|
||||
precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is
|
||||
the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source that will provide the contents to be uploaded.
|
||||
<tt>Argument</tt> or
|
||||
<tt>path</tt> give the target path to the resource in the server. The
|
||||
optional arguments are the following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>user</tt>, <tt>password</tt>: User name and password used for
|
||||
authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";
|
||||
<li><tt>command</tt>: The FTP command used to send data. Defaults to
|
||||
"<tt>stor</tt>", but see example below;
|
||||
<li><tt>port</tt>: The port to used for the control connection. Defaults to 21;
|
||||
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
|
||||
"<tt>a</tt>". Defaults to whatever is the server default;
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
Both functions return 1 if successful, or <b><tt>nil</tt></b> and an error
|
||||
message describing the reason for failure.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
|
||||
-- Log as user "fulano" on server "ftp.example.com",
|
||||
-- using password "silva", and store a file "README" with contents
|
||||
-- "wrong password, of course"
|
||||
f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
|
||||
"wrong password, of course")
|
||||
</pre>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ftp support
|
||||
local ftp = require("socket.ftp")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- Log as user "fulano" on server "ftp.example.com",
|
||||
-- using password "silva", and append to the remote file "LOG", sending the
|
||||
-- contents of the local file "LOCAL-LOG"
|
||||
f, e = ftp.put{
|
||||
host = "ftp.example.com",
|
||||
user = "fulano",
|
||||
password = "silva",
|
||||
command = "appe",
|
||||
argument = "LOG",
|
||||
source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
|
||||
}
|
||||
</pre>
|
||||
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:18 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
333
cosmic rage/docs/LuaSocket_documentation/http.html
Normal file
333
cosmic rage/docs/LuaSocket_documentation/http.html
Normal file
@@ -0,0 +1,333 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: HTTP support">
|
||||
<meta name="keywords" content="Lua, HTTP, Library, WWW, Browser, Network, Support">
|
||||
<title>LuaSocket: HTTP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=http>HTTP</h2>
|
||||
|
||||
<p>
|
||||
HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange
|
||||
information between web-browsers and servers. The <tt>http</tt>
|
||||
namespace offers full support for the client side of the HTTP
|
||||
protocol (i.e.,
|
||||
the facilities that would be used by a web-browser implementation). The
|
||||
implementation conforms to the HTTP/1.1 standard,
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC
|
||||
2616</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The module exports functions that provide HTTP functionality in different
|
||||
levels of abstraction. From the simple
|
||||
string oriented requests, through generic
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based, down to even lower-level if you bother to look through the source code.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>http</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the HTTP module and any libraries it requires
|
||||
local http = require("socket.http")
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
URLs must conform to
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc1738.txt">RFC
|
||||
1738</a>,
|
||||
that is, an URL is a string in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
[http://][<user>[:<password>]@]<host>[:<port>][/<path>]
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
MIME headers are represented as a Lua table in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<table summary="MIME headers in Lua table">
|
||||
<tr><td><tt>
|
||||
headers = {<br>
|
||||
field-1-name = <i>field-1-value</i>,<br>
|
||||
field-2-name = <i>field-2-value</i>,<br>
|
||||
field-3-name = <i>field-3-value</i>,<br>
|
||||
...<br>
|
||||
field-n-name = <i>field-n-value</i><br>
|
||||
}
|
||||
</tt></td></tr>
|
||||
</table>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
Field names are case insensitive (as specified by the standard) and all
|
||||
functions work with lowercase field names.
|
||||
Field values are left unmodified.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: MIME headers are independent of order. Therefore, there is no problem
|
||||
in representing them in a Lua table.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The following constants can be set to control the default behavior of
|
||||
the HTTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>PORT</tt>: default port used for connections;
|
||||
<li> <tt>PROXY</tt>: default proxy used for connections;
|
||||
<li> <tt>TIMEOUT</tt>: sets the timeout for all I/O operations;
|
||||
<li> <tt>USERAGENT</tt>: default user agent reported to server.
|
||||
</ul>
|
||||
|
||||
<!-- http.request ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=request>
|
||||
http.<b>request(</b>url [, body]<b>)</b><br>
|
||||
http.<b>request{</b><br>
|
||||
url = <i>string</i>,<br>
|
||||
[sink = <i>LTN12 sink</i>,]<br>
|
||||
[method = <i>string</i>,]<br>
|
||||
[headers = <i>header-table</i>,]<br>
|
||||
[source = <i>LTN12 source</i>],<br>
|
||||
[step = <i>LTN12 pump step</i>,]<br>
|
||||
[proxy = <i>string</i>,]<br>
|
||||
[redirect = <i>boolean</i>,]<br>
|
||||
[create = <i>function</i>]<br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
The request function has two forms. The simple form downloads
|
||||
a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
|
||||
on strings. The generic form performs any HTTP method and is
|
||||
<a href=http://lua-users.org/wiki/FiltersSourcesAndSinks>LTN12</a> based.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
If the first argument of the <tt>request</tt> function is a string, it
|
||||
should be an <tt>url</tt>. In that case, if a <tt>body</tt>
|
||||
is provided as a string, the function will perform a <tt>POST</tt> method
|
||||
in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
|
||||
<tt>url</tt>
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
If the first argument is instead a table, the most important fields are
|
||||
the <tt>url</tt> and the <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>sink</tt> that will receive the downloaded content.
|
||||
Any part of the <tt>url</tt> can be overridden by including
|
||||
the appropriate field in the request table.
|
||||
If authentication information is provided, the function
|
||||
uses the Basic Authentication Scheme (see <a href="#authentication">note</a>)
|
||||
to retrieve the document. If <tt>sink</tt> is <tt><b>nil</b></tt>, the
|
||||
function discards the downloaded data. The optional parameters are the
|
||||
following:
|
||||
</p>
|
||||
<ul>
|
||||
<li><tt>method</tt>: The HTTP request method. Defaults to "GET";
|
||||
<li><tt>headers</tt>: Any additional HTTP headers to send with the request;
|
||||
<li><tt>source</tt>: <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source to provide the request body. If there
|
||||
is a body, you need to provide an appropriate "<tt>content-length</tt>"
|
||||
request header field, or the function will attempt to send the body as
|
||||
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;
|
||||
<li><tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to move data.
|
||||
Defaults to the LTN12 <tt>pump.step</tt> function.
|
||||
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;
|
||||
<li><tt>redirect</tt>: Set to <tt><b>false</b></tt> to prevent the
|
||||
function from automatically following 301 or 302 server redirect messages;
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
In case of failure, the function returns <tt><b>nil</b></tt> followed by an
|
||||
error message. If successful, the simple form returns the response
|
||||
body as a string, followed by the response status code, the response
|
||||
headers and the response status line. The generic function returns the same
|
||||
information, except the first return value is just the number 1 (the body
|
||||
goes to the <tt>sink</tt>).
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Even when the server fails to provide the contents of the requested URL (URL not found, for example),
|
||||
it usually returns a message body (a web page informing the
|
||||
URL was not found or some other useless page). To make sure the
|
||||
operation was successful, check the returned status <tt>code</tt>. For
|
||||
a list of the possible values and their meanings, refer to <a
|
||||
href="http://www.cs.princeton.edu/~diego/rfc/rfc2616.txt">RFC
|
||||
2616</a>.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Here are a few examples with the simple interface:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the http module
|
||||
local io = require("io")
|
||||
local http = require("socket.http")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- connect to server "www.cs.princeton.edu" and retrieves this manual
|
||||
-- file from "~diego/professional/luasocket/http.html" and print it to stdout
|
||||
http.request{
|
||||
url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html",
|
||||
sink = ltn12.sink.file(io.stdout)
|
||||
}
|
||||
|
||||
-- connect to server "www.example.com" and tries to retrieve
|
||||
-- "/private/index.html". Fails because authentication is needed.
|
||||
b, c, h = http.request("http://www.example.com/private/index.html")
|
||||
-- b returns some useless page telling about the denied access,
|
||||
-- h returns authentication information
|
||||
-- and c returns with value 401 (Authentication Required)
|
||||
|
||||
-- tries to connect to server "wrong.host" to retrieve "/"
|
||||
-- and fails because the host does not exist.
|
||||
r, e = http.request("http://wrong.host/")
|
||||
-- r is nil, and e returns with value "host not found"
|
||||
</pre>
|
||||
|
||||
<p class=description>
|
||||
And here is an example using the generic interface:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the http module
|
||||
http = require("socket.http")
|
||||
|
||||
-- Requests information about a document, without downloading it.
|
||||
-- Useful, for example, if you want to display a download gauge and need
|
||||
-- to know the size of the document in advance
|
||||
r, c, h = http.request {
|
||||
method = "HEAD",
|
||||
url = "http://www.tecgraf.puc-rio.br/~diego"
|
||||
}
|
||||
-- r is 1, c is 200, and h would return the following headers:
|
||||
-- h = {
|
||||
-- date = "Tue, 18 Sep 2001 20:42:21 GMT",
|
||||
-- server = "Apache/1.3.12 (Unix) (Red Hat/Linux)",
|
||||
-- ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT",
|
||||
-- ["content-length"] = 15652,
|
||||
-- ["connection"] = "close",
|
||||
-- ["content-Type"] = "text/html"
|
||||
-- }
|
||||
</pre>
|
||||
|
||||
<p class=note id=post>
|
||||
Note: When sending a POST request, simple interface adds a
|
||||
"<tt>Content-type: application/x-www-form-urlencoded</tt>"
|
||||
header to the request. This is the type used by
|
||||
HTML forms. If you need another type, use the generic
|
||||
interface.
|
||||
</p>
|
||||
|
||||
<p class=note id=authentication>
|
||||
Note: Some URLs are protected by their
|
||||
servers from anonymous download. For those URLs, the server must receive
|
||||
some sort of authentication along with the request or it will deny
|
||||
download and return status "401 Authentication Required".
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
The HTTP/1.1 standard defines two authentication methods: the Basic
|
||||
Authentication Scheme and the Digest Authentication Scheme, both
|
||||
explained in detail in
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2068.txt">RFC 2068</a>.
|
||||
</p>
|
||||
|
||||
<p class=note>The Basic Authentication Scheme sends
|
||||
<tt><user></tt> and
|
||||
<tt><password></tt> unencrypted to the server and is therefore
|
||||
considered unsafe. Unfortunately, by the time of this implementation,
|
||||
the wide majority of servers and browsers support the Basic Scheme only.
|
||||
Therefore, this is the method used by the toolkit whenever
|
||||
authentication is required.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load required modules
|
||||
http = require("socket.http")
|
||||
mime = require("mime")
|
||||
|
||||
-- Connect to server "www.example.com" and tries to retrieve
|
||||
-- "/private/index.html", using the provided name and password to
|
||||
-- authenticate the request
|
||||
b, c, h = http.request("http://fulano:silva@www.example.com/private/index.html")
|
||||
|
||||
-- Alternatively, one could fill the appropriate header and authenticate
|
||||
-- the request directly.
|
||||
r, c = http.request {
|
||||
url = "http://www.example.com/private/index.html",
|
||||
headers = { authentication = "Basic " .. (mime.b64("fulano:silva")) }
|
||||
}
|
||||
</pre>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:26 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
208
cosmic rage/docs/LuaSocket_documentation/index.html
Normal file
208
cosmic rage/docs/LuaSocket_documentation/index.html
Normal file
@@ -0,0 +1,208 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="The LuaSocket Homepage">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Network, Library, Support, Internet">
|
||||
<title>LuaSocket: Network support for the Lua language </title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- whatis +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=whatis>What is LuaSocket?</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket is a <a href="http://www.lua.org">Lua</a> extension library
|
||||
that is composed by two parts: a C core that provides support for the TCP
|
||||
and UDP transport layers, and a set of Lua modules that add support for
|
||||
functionality commonly needed by applications that deal with the Internet.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The core support has been implemented so that it is both efficient and
|
||||
simple to use. It is available to any Lua application once it has been
|
||||
properly initialized by the interpreter in use. The code has been tested
|
||||
and runs well on several Windows and Unix platforms. </p>
|
||||
|
||||
<p>
|
||||
Among the support modules, the most commonly used implement the
|
||||
<a href=smtp.html>SMTP</a>
|
||||
(sending e-mails),
|
||||
<a href=http.html>HTTP</a>
|
||||
(WWW access) and
|
||||
<a href=ftp.html>FTP</a>
|
||||
(uploading and downloading files) client
|
||||
protocols. These provide a very natural and generic interface to the
|
||||
functionality defined by each protocol.
|
||||
In addition, you will find that the
|
||||
<a href=mime.html>MIME</a> (common encodings),
|
||||
<a href=url.html>URL</a>
|
||||
(anything you could possible want to do with one) and
|
||||
<a href=ltn12.html>LTN12</a>
|
||||
(filters, sinks, sources and pumps) modules can be very handy.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The library is available under the same
|
||||
<a href="http://www.lua.org/copyright.html">
|
||||
terms and conditions</a> as the Lua language, the MIT license. The idea is
|
||||
that if you can use Lua in a project, you should also be able to use
|
||||
LuaSocket.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Copyright © 2004-2007 Diego Nehab. All rights reserved. <br>
|
||||
Author: <A href="http://www.cs.princeton.edu/~diego">Diego Nehab</a>
|
||||
</p>
|
||||
|
||||
<!-- download +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=download>Download</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket version 2.0.2 is now available for download! It is
|
||||
compatible with Lua 5.1, and has
|
||||
been tested on Windows XP, Linux, and Mac OS X. Chances
|
||||
are it works well on most UNIX distributions and Windows flavors.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The library can be downloaded in source code from the
|
||||
<a href=http://luaforge.net/projects/luasocket/>LuaSocket
|
||||
project page</a> at LuaForge.
|
||||
Besides the full C and Lua source code for the library, the distribution
|
||||
contains several examples, this user's manual and basic test procedures.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Danilo Tuler is maintaining Win32 binaries for LuaSocket, which are also
|
||||
available from LuaForge. These are compatible with the
|
||||
<a href=http://luaforge.net/projects/luabinaries>LuaBinaries</a>,
|
||||
also available from LuaForge.
|
||||
</p>
|
||||
|
||||
<p> Take a look at the <a
|
||||
href=installation.html>installation</a> section of the
|
||||
manual to find out how to properly install the library.
|
||||
</p>
|
||||
|
||||
<!-- thanks +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=thanks>Special thanks</h2>
|
||||
|
||||
<p>
|
||||
Throughout LuaSocket's history, many people gave suggestions that helped
|
||||
improve it. For that, I thank the Lua community.
|
||||
Special thanks go to
|
||||
David Burgess, who has helped push the library to a new level of quality and
|
||||
from whom I have learned a lot of stuff that doesn't show up in RFCs.
|
||||
Special thanks also to Carlos Cassino, who played a big part in the
|
||||
extensible design seen in the C core of LuaSocket 2.0. Mike Pall
|
||||
has been helping a lot too! Thanks to you all!
|
||||
</p>
|
||||
|
||||
<!-- whatsnew +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=new>What's New</h2>
|
||||
|
||||
<p>
|
||||
2.0.2 is just a bug-fix/update release.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> Improved: http.request() now supports deprecated
|
||||
HTTP/0.9 servers (Florian Berger);
|
||||
<li> Fixed: could return "timedout" instead of "timeout" (Leo Leo);
|
||||
<li> Fixed: crash when reading '*a' on closed socket (Paul Ducklin);
|
||||
<li> Fixed: return values are consistent when reading from closed sockets;
|
||||
<li> Fixed: case sensitivity in headers of multipart
|
||||
messages in smtp.message() (Graham Henstridge);
|
||||
<li> Fixed a couple instances of error() being called instead of
|
||||
base.error(). These would cause an error when an error was
|
||||
reported :) (Ketmar Dark);
|
||||
<li> Fixed: test script now uses pairs() iterator instead
|
||||
of the old Lua syntax (Robert Dodier).
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
2.0.1 is just a bug-fix/update release.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> Updated: now using <tt>compat-5.1r5</tt>;
|
||||
<li> Improved: <tt>http.request</tt> is more robust to
|
||||
malformed URLs (Adrian Sietsma);
|
||||
<li> Improved: the simple <tt>http.request</tt> interface sends a
|
||||
"<tt>Content-type: application/x-www-form-urlencoded</tt>"
|
||||
header (William Trenker);
|
||||
<li> Improved: <tt>http.request</tt> is robust to evil
|
||||
servers that send inappropriate 100-continue messages
|
||||
(David Burgess);
|
||||
<li> Fixed: <tt>http.request</tt> was using the old host header during
|
||||
redirects (Florian Berger);
|
||||
<li> Fixed: sample <tt>unix.c</tt> had fallen through the
|
||||
cracks during development (Matthew Percival);
|
||||
<li> Fixed: error code was not being propagated correctly in
|
||||
ftp.lua (David Burgess).
|
||||
</ul>
|
||||
|
||||
<!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=old>Old Versions</h2>
|
||||
|
||||
<p>
|
||||
All previous versions of the LuaSocket library can be downloaded <a
|
||||
href="http://www.cs.princeton.edu/~diego/professional/luasocket/old">
|
||||
here</a>. Although these versions are no longer supported, they are
|
||||
still available for those that have compatibility issues.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Wed Oct 3 02:07:59 BRT 2007
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
163
cosmic rage/docs/LuaSocket_documentation/installation.html
Normal file
163
cosmic rage/docs/LuaSocket_documentation/installation.html
Normal file
@@ -0,0 +1,163 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: Introduction to the core">
|
||||
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network, Support,
|
||||
Installation">
|
||||
<title>LuaSocket: Installation</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- installation ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2>Installation</h2>
|
||||
|
||||
<p> LuaSocket 2.0.2 uses the new package system for Lua 5.1.
|
||||
All Lua library developers are encouraged to update their libraries so that
|
||||
all libraries can coexist peacefully and users can benefit from the
|
||||
standardization and flexibility of the standard.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Those stuck with Lua 5.0 will need the
|
||||
<a href=http://www.keplerproject.org/compat/>compat-5.1</a>
|
||||
module. It is maintained by
|
||||
<a href=http://www.keplerproject.org/>The Kepler
|
||||
Project</a>'s team, and implements the Lua 5.1 package proposal
|
||||
on top of Lua 5.0. </p>
|
||||
|
||||
<p> Here we will only describe the standard distribution.
|
||||
If the standard doesn't meet your needs, we refer you to the
|
||||
Lua discussion list, where any question about the package
|
||||
scheme will likely already have been answered. </p>
|
||||
|
||||
<h3>Directory structure</h3>
|
||||
|
||||
<p> On Unix systems, the standard distribution uses two base
|
||||
directories, one for system dependent files, and another for system
|
||||
independent files. Let's call these directories <tt><CDIR></tt>
|
||||
and <tt><LDIR></tt>, respectively.
|
||||
For instance, in my laptop, I use '<tt>/usr/local/lib/lua/5.0</tt>' for
|
||||
<tt><CDIR></tt> and '<tt>/usr/local/share/lua/5.0</tt>' for
|
||||
<tt><LDIR></tt>. On Windows, sometimes only one directory is used, say
|
||||
'<tt>c:\program files\lua\5.0</tt>'. Here is the standard LuaSocket
|
||||
distribution directory structure:</p>
|
||||
|
||||
<pre class=example>
|
||||
<LDIR>/compat-5.1.lua
|
||||
<LDIR>/ltn12.lua
|
||||
<LDIR>/socket.lua
|
||||
<CDIR>/socket/core.dll
|
||||
<LDIR>/socket/http.lua
|
||||
<LDIR>/socket/tp.lua
|
||||
<LDIR>/socket/ftp.lua
|
||||
<LDIR>/socket/smtp.lua
|
||||
<LDIR>/socket/url.lua
|
||||
<LDIR>/mime.lua
|
||||
<CDIR>/mime/core.dll
|
||||
</pre>
|
||||
|
||||
<p> Naturally, on Unix systems, <tt>core.dll</tt>
|
||||
would be replaced by <tt>core.so</tt>.
|
||||
</p>
|
||||
|
||||
<p> In order for the interpreter to find all LuaSocket components, three
|
||||
environment variables need to be set. The first environment variable tells
|
||||
the interpreter to load the <tt>compat-5.1.lua</tt> module at startup: </p>
|
||||
|
||||
<pre class=example>
|
||||
LUA_INIT=@<LDIR>/compat-5.1.lua
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
This is only need for Lua 5.0! Lua 5.1 comes with
|
||||
the package system built in, of course.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The other two environment variables instruct the compatibility module to
|
||||
look for dynamic libraries and extension modules in the appropriate
|
||||
directories and with the appropriate filename extensions.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
LUA_PATH=<LDIR>/?.lua;?.lua
|
||||
LUA_CPATH=<CDIR>/?.dll;?.dll
|
||||
</pre>
|
||||
|
||||
<p> Again, naturally, on Unix systems the shared library extension would be
|
||||
<tt>.so</tt> instead of <tt>.dll</tt>.</p>
|
||||
|
||||
<h3>Using LuaSocket</h3>
|
||||
|
||||
<p> With the above setup, and an interpreter with shared library support,
|
||||
it should be easy to use LuaSocket. Just fire the interpreter and use the
|
||||
<tt>require</tt> function to gain access to whatever module you need:</p>
|
||||
|
||||
<pre class=example>
|
||||
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
|
||||
> socket = require("socket")
|
||||
> print(socket._VERSION)
|
||||
--> LuaSocket 2.0.2
|
||||
</pre>
|
||||
|
||||
<p> Each module loads their dependencies automatically, so you only need to
|
||||
load the modules you directly depend upon: </p>
|
||||
|
||||
<pre class=example>
|
||||
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
|
||||
> http = require("socket.http")
|
||||
> print(http.request("http://www.cs.princeton.edu/~diego/professional/luasocket"))
|
||||
--> homepage gets dumped to terminal
|
||||
</pre>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:30 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
333
cosmic rage/docs/LuaSocket_documentation/introduction.html
Normal file
333
cosmic rage/docs/LuaSocket_documentation/introduction.html
Normal file
@@ -0,0 +1,333 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: Introduction to the core">
|
||||
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network,
|
||||
Library, Support">
|
||||
<title>LuaSocket: Introduction to the core</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- introduction +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2>Introduction</h2>
|
||||
|
||||
<p>
|
||||
LuaSocket is a <a href="http://www.lua.org">Lua</a> extension library
|
||||
that is composed by two parts: a C core that provides support for the TCP
|
||||
and UDP transport layers, and a set of Lua modules that add support for
|
||||
the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and
|
||||
downloading files) protocols and other functionality commonly needed by
|
||||
applications that deal with the Internet. This introduction is about the C
|
||||
core.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Communication in LuaSocket is performed via I/O objects. These can
|
||||
represent different network domains. Currently, support is provided for TCP
|
||||
and UDP, but nothing prevents other developers from implementing SSL, Local
|
||||
Domain, Pipes, File Descriptors etc. I/O objects provide a standard
|
||||
interface to I/O across different domains and operating systems.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The API design had two goals in mind. First, users
|
||||
experienced with the C API to sockets should feel comfortable using LuaSocket.
|
||||
Second, the simplicity and the feel of the Lua language should be
|
||||
preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified.
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
One of the simplifications is the receive pattern capability.
|
||||
Applications can read data from stream domains (such as TCP)
|
||||
line by line, block by block, or until the connection is closed.
|
||||
All I/O reads are buffered and the performance differences between
|
||||
different receive patterns are negligible.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Another advantage is the flexible timeout control
|
||||
mechanism. As in C, all I/O operations are blocking by default. For
|
||||
example, the <a href=tcp.html#send><tt>send</tt></a>,
|
||||
<a href=tcp.html#receive><tt>receive</tt></a> and
|
||||
<a href=tcp.html#accept><tt>accept</tt></a> methods
|
||||
of the TCP domain will block the caller application until
|
||||
the operation is completed (if ever!). However, with a call to the
|
||||
<a href=tcp.html#settimeout><tt>settimeout</tt></a>
|
||||
method, an application can specify upper limits on
|
||||
the time it can be blocked by LuaSocket (the "<tt>total</tt>" timeout), on
|
||||
the time LuaSocket can internally be blocked by any OS call (the
|
||||
"<tt>block</tt>" timeout) or a combination of the two. Each LuaSocket
|
||||
call might perform several OS calls, so that the two timeout values are
|
||||
<em>not</em> equivalent.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Finally, the host name resolution is transparent, meaning that most
|
||||
functions and methods accept both IP addresses and host names. In case a
|
||||
host name is given, the library queries the system's resolver and
|
||||
tries the main IP address returned. Note that direct use of IP addresses
|
||||
is more efficient, of course. The
|
||||
<a href=dns.html#toip><tt>toip</tt></a>
|
||||
and <a href=dns.html#tohostname><tt>tohostname</tt></a>
|
||||
functions from the DNS module are provided to convert between host names and IP addresses.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Together, these changes make network programming in LuaSocket much simpler
|
||||
than it is in C, as the following sections will show.
|
||||
</p>
|
||||
|
||||
<!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=tcp>TCP</h3>
|
||||
|
||||
<p>
|
||||
TCP (Transfer Control Protocol) is reliable stream protocol. In other
|
||||
words, applications communicating through TCP can send and receive data as
|
||||
an error free stream of bytes. Data is split in one end and
|
||||
reassembled transparently on the other end. There are no boundaries in
|
||||
the data transfers. The library allows users to read data from the
|
||||
sockets in several different granularities: patterns are available for
|
||||
lines, arbitrary sized blocks or "read up to connection closed", all with
|
||||
good performance.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The library distinguishes three types of TCP sockets: <em>master</em>,
|
||||
<em>client</em> and <em>server</em> sockets.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Master sockets are newly created TCP sockets returned by the function
|
||||
<a href=tcp.html#tcp><tt>socket.tcp</tt></a>. A master socket is
|
||||
transformed into a server socket
|
||||
after it is associated with a <em>local</em> address by a call to the
|
||||
<a href=tcp.html#bind><tt>bind</tt></a> method followed by a call to the
|
||||
<a href=tcp.html#listen><tt>listen</tt></a>. Conversely, a master socket
|
||||
can be changed into a client socket with the method
|
||||
<a href=tcp.html#connect><tt>connect</tt></a>,
|
||||
which associates it with a <em>remote</em> address.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
On server sockets, applications can use the
|
||||
<a href=tcp.html#accept><tt>accept</tt></a> method
|
||||
to wait for a client connection. Once a connection is established, a
|
||||
client socket object is returned representing this connection. The
|
||||
other methods available for server socket objects are
|
||||
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
||||
<a href=tcp.html#settimeout><tt>settimeout</tt></a>, and
|
||||
<a href=tcp.html#close><tt>close</tt></a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Client sockets are used to exchange data between two applications over
|
||||
the Internet. Applications can call the methods
|
||||
<a href=tcp.html#send><tt>send</tt></a> and
|
||||
<a href=tcp.html#receive><tt>receive</tt></a>
|
||||
to send and receive data. The other methods
|
||||
available for client socket objects are
|
||||
<a href=tcp.html#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=tcp.html#getpeername><tt>getpeername</tt></a>,
|
||||
<a href=tcp.html#setoption><tt>setoption</tt></a>,
|
||||
<a href=tcp.html#settimeout><tt>settimeout</tt></a>,
|
||||
<a href=tcp.html#shutdown><tt>shutdown</tt></a>, and
|
||||
<a href=tcp.html#close><tt>close</tt></a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Example:
|
||||
</p>
|
||||
<blockquote>
|
||||
<p>
|
||||
A simple echo server, using LuaSocket. The program binds to an ephemeral
|
||||
port (one that is chosen by the operating system) on the local host and
|
||||
awaits client connections on that port. When a connection is established,
|
||||
the program reads a line from the remote end and sends it back, closing
|
||||
the connection immediately. You can test it using the telnet
|
||||
program.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load namespace
|
||||
local socket = require("socket")
|
||||
-- create a TCP socket and bind it to the local host, at any port
|
||||
local server = assert(socket.bind("*", 0))
|
||||
-- find out which port the OS chose for us
|
||||
local ip, port = server:getsockname()
|
||||
-- print a message informing what's up
|
||||
print("Please telnet to localhost on port " .. port)
|
||||
print("After connecting, you have 10s to enter a line to be echoed")
|
||||
-- loop forever waiting for clients
|
||||
while 1 do
|
||||
-- wait for a connection from any client
|
||||
local client = server:accept()
|
||||
-- make sure we don't block waiting for this client's line
|
||||
client:settimeout(10)
|
||||
-- receive the line
|
||||
local line, err = client:receive()
|
||||
-- if there was no error, send it back to the client
|
||||
if not err then client:send(line .. "\n") end
|
||||
-- done with client, close the object
|
||||
client:close()
|
||||
end
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<!-- udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=udp>UDP</h3>
|
||||
|
||||
<p>
|
||||
UDP (User Datagram Protocol) is a non-reliable datagram protocol. In
|
||||
other words, applications communicating through UDP send and receive
|
||||
data as independent blocks, which are not guaranteed to reach the other
|
||||
end. Even when they do reach the other end, they are not guaranteed to be
|
||||
error free. Data transfers are atomic, one datagram at a time. Reading
|
||||
only part of a datagram discards the rest, so that the following read
|
||||
operation will act on the next datagram. The advantages are in
|
||||
simplicity (no connection setup) and performance (no error checking or
|
||||
error correction).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Note that although no guarantees are made, these days
|
||||
networks are so good that, under normal circumstances, few errors
|
||||
happen in practice.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
An UDP socket object is created by the
|
||||
<a href=udp.html#udp><tt>socket.udp</tt></a> function. UDP
|
||||
sockets do not need to be connected before use. The method
|
||||
<a href=udp.html#sendto><tt>sendto</tt></a>
|
||||
can be used immediately after creation to
|
||||
send a datagram to IP address and port. Host names are not allowed
|
||||
because performing name resolution for each packet would be forbiddingly
|
||||
slow. Methods
|
||||
<a href=udp.html#receive><tt>receive</tt></a> and
|
||||
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
||||
can be used to retrieve datagrams, the latter returning the IP and port of
|
||||
the sender as extra return values (thus being slightly less
|
||||
efficient).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When communication is performed repeatedly with a single peer, an
|
||||
application should call the
|
||||
<a href=udp.html#setpeername><tt>setpeername</tt></a> method to specify a
|
||||
permanent partner. Methods
|
||||
<a href=udp.html#sendto><tt>sendto</tt></a> and
|
||||
<a href=udp.html#receivefrom><tt>receivefrom</tt></a>
|
||||
can no longer be used, but the method
|
||||
<a href=udp.html#send><tt>send</tt></a> can be used to send data
|
||||
directly to the peer, and the method
|
||||
<a href=udp.html#receive><tt>receive</tt></a>
|
||||
will only return datagrams originating
|
||||
from that peer. There is about 30% performance gain due to this practice.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To associate an UDP socket with a local address, an application calls the
|
||||
<a href=udp.html#setsockname><tt>setsockname</tt></a>
|
||||
method <em>before</em> sending any datagrams. Otherwise, the socket is
|
||||
automatically bound to an ephemeral address before the first data
|
||||
transmission and once bound the local address cannot be changed.
|
||||
The other methods available for UDP sockets are
|
||||
<a href=udp.html#getpeername><tt>getpeername</tt></a>,
|
||||
<a href=udp.html#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=udp.html#settimeout><tt>settimeout</tt></a>,
|
||||
<a href=udp.html#setoption><tt>setoption</tt></a> and
|
||||
<a href=udp.html#close><tt>close</tt></a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Example:
|
||||
</p>
|
||||
<blockquote>
|
||||
<p>
|
||||
A simple daytime client, using LuaSocket. The program connects to a remote
|
||||
server and tries to retrieve the daytime, printing the answer it got or an
|
||||
error message.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- change here to the host an port you want to contact
|
||||
local host, port = "localhost", 13
|
||||
-- load namespace
|
||||
local socket = require("socket")
|
||||
-- convert host name to ip address
|
||||
local ip = assert(socket.dns.toip(host))
|
||||
-- create a new UDP object
|
||||
local udp = assert(socket.udp())
|
||||
-- contact daytime host
|
||||
assert(udp:sendto("anything", ip, port))
|
||||
-- retrieve the answer and print results
|
||||
io.write(assert(udp:receive()))
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<!-- More +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=more>Support modules</h3>
|
||||
|
||||
<p> Although not covered in the introduction, LuaSocket offers
|
||||
much more than TCP and UDP functionality. As the library
|
||||
evolved, support for <a href=http.html>HTTP</a>, <a href=ftp.html>FTP</a>,
|
||||
and <a href=smtp.html>SMTP</a> were built on top of these. These modules
|
||||
and many others are covered by the <a href=reference.html>reference manual</a>.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:36 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
430
cosmic rage/docs/LuaSocket_documentation/ltn12.html
Normal file
430
cosmic rage/docs/LuaSocket_documentation/ltn12.html
Normal file
@@ -0,0 +1,430 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: LTN12 support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Filters, Source, Sink,
|
||||
Pump, Support, Library">
|
||||
<title>LuaSocket: LTN12 module</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- ltn12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=ltn12>LTN12</h2>
|
||||
|
||||
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
LTN012, Filters sources and sinks</a>. This manual simply describes the
|
||||
functions. Please refer to the LTN for a deeper explanation of the
|
||||
functionality provided by this module.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>ltn12</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the LTN21 module
|
||||
local ltn12 = require("ltn12")
|
||||
</pre>
|
||||
|
||||
<!-- filters ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id="filter">Filters</h3>
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="filter.chain">
|
||||
ltn12.filter.<b>chain(</b>filter<sub>1</sub>, filter<sub>2</sub>
|
||||
[, ... filter<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a filter that passes all data it receives through each of a
|
||||
series of given filters.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Filter<sub>1</sub></tt> to <tt>filter<sub>N</sub></tt> are simple
|
||||
filters.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the chained filter.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
The nesting of filters can be arbitrary. For instance, the useless filter
|
||||
below doesn't do anything but return the data that was passed to it,
|
||||
unaltered.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load required modules
|
||||
local ltn12 = require("ltn12")
|
||||
local mime = require("mime")
|
||||
|
||||
-- create a silly identity filter
|
||||
id = ltn12.filter.chain(
|
||||
mime.encode("quoted-printable"),
|
||||
mime.encode("base64"),
|
||||
mime.decode("base64"),
|
||||
mime.decode("quoted-printable")
|
||||
)
|
||||
</pre>
|
||||
|
||||
<!-- cycle ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="filter.cycle">
|
||||
ltn12.filter.<b>cycle(</b>low [, ctx, extra]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a high-level filter that cycles though a low-level filter by
|
||||
passing it each chunk and updating a context between calls.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Low</tt> is the low-level filter to be cycled,
|
||||
<tt>ctx</tt> is the initial context and <tt>extra</tt> is any extra
|
||||
argument the low-level filter might take.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the high-level filter.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- the base64 mime filter factory
|
||||
encodet['base64'] = function()
|
||||
return ltn12.filter.cycle(b64, "")
|
||||
end
|
||||
</pre>
|
||||
|
||||
<!-- pumps ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id="pump">Pumps</h3>
|
||||
|
||||
<!-- all ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="pump.all">
|
||||
ltn12.pump.<b>all(</b>source, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Pumps <em>all</em> data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
If successful, the function returns a value that evaluates to
|
||||
<b><tt>true</tt></b>. In case
|
||||
of error, the function returns a <b><tt>false</tt></b> value, followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- step +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="pump.step">
|
||||
ltn12.pump.<b>step(</b>source, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Pumps <em>one</em> chunk of data from a <tt>source</tt> to a <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
If successful, the function returns a value that evaluates to
|
||||
<b><tt>true</tt></b>. In case
|
||||
of error, the function returns a <b><tt>false</tt></b> value, followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- sinks ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id="sink">Sinks</h3>
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.chain">
|
||||
ltn12.sink.<b>chain(</b>filter, sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a new sink that passes data through a <tt>filter</tt> before sending it to a given <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<!-- error ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.error">
|
||||
ltn12.sink.<b>error(</b>message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a sink that aborts transmission with the error
|
||||
<tt>message</tt>.
|
||||
</p>
|
||||
|
||||
<!-- file +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.file">
|
||||
ltn12.sink.<b>file(</b>handle, message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a sink that sends data to a file.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a sink that sends all data to the given <tt>handle</tt>
|
||||
and closes the file when done, or a sink that aborts the transmission with
|
||||
the error <tt>message</tt>
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
In the following example, notice how the prototype is designed to
|
||||
fit nicely with the <tt>io.open</tt> function.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- copy a file
|
||||
ltn12.pump.all(
|
||||
ltn12.source.file(io.open("original.png")),
|
||||
ltn12.sink.file(io.open("copy.png"))
|
||||
)
|
||||
</pre>
|
||||
|
||||
<!-- null +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.null">
|
||||
ltn12.sink.<b>null()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a sink that ignores all data it receives.
|
||||
</p>
|
||||
|
||||
<!-- simplify +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.simplify">
|
||||
ltn12.sink.<b>simplify(</b>sink<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a simple sink given a fancy <tt>sink</tt>.
|
||||
</p>
|
||||
|
||||
<!-- table ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="sink.table">
|
||||
ltn12.sink.<b>table(</b>[table]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a sink that stores all chunks in a table. The chunks can later be
|
||||
efficiently concatenated into a single string.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Table</tt> is used to hold the chunks. If
|
||||
<tt><b>nil</b></tt>, the function creates its own table.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the sink and the table used to store the chunks.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load needed modules
|
||||
local http = require("socket.http")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- a simplified http.get function
|
||||
function http.get(u)
|
||||
local t = {}
|
||||
local respt = request{
|
||||
url = u,
|
||||
sink = ltn12.sink.table(t)
|
||||
}
|
||||
return table.concat(t), respt.headers, respt.code
|
||||
end
|
||||
</pre>
|
||||
|
||||
<!-- sinks ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id="source">Sources</h3>
|
||||
|
||||
<!-- cat ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.cat">
|
||||
ltn12.source.<b>cat(</b>source<sub>1</sub> [, source<sub>2</sub>, ...,
|
||||
source<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a new source that produces the concatenation of the data produced
|
||||
by a number of sources.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Source<sub>1</sub></tt> to <tt>source<sub>N</sub></tt> are the original
|
||||
sources.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the new source.
|
||||
</p>
|
||||
|
||||
<!-- chain ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.chain">
|
||||
ltn12.source.<b>chain(</b>source, filter<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a new <tt>source</tt> that passes data through a <tt>filter</tt>
|
||||
before returning it.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the new source.
|
||||
</p>
|
||||
|
||||
<!-- empty ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.empty">
|
||||
ltn12.source.<b>empty()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns an empty source.
|
||||
</p>
|
||||
|
||||
<!-- error ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.error">
|
||||
ltn12.source.<b>error(</b>message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a source that aborts transmission with the error
|
||||
<tt>message</tt>.
|
||||
</p>
|
||||
|
||||
<!-- file +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.file">
|
||||
ltn12.source.<b>file(</b>handle, message<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates a source that produces the contents of a file.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Handle</tt> is a file handle. If <tt>handle</tt> is <tt><b>nil</b></tt>,
|
||||
<tt>message</tt> should give the reason for failure.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a source that reads chunks of data from
|
||||
given <tt>handle</tt> and returns it to the user,
|
||||
closing the file when done, or a source that aborts the transmission with
|
||||
the error <tt>message</tt>
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
In the following example, notice how the prototype is designed to
|
||||
fit nicely with the <tt>io.open</tt> function.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the ltn12 module
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- copy a file
|
||||
ltn12.pump.all(
|
||||
ltn12.source.file(io.open("original.png")),
|
||||
ltn12.sink.file(io.open("copy.png"))
|
||||
)
|
||||
</pre>
|
||||
|
||||
<!-- simplify +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.simplify">
|
||||
ltn12.source.<b>simplify(</b>source<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a simple source given a fancy <tt>source</tt>.
|
||||
</p>
|
||||
|
||||
<!-- string +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="source.string">
|
||||
ltn12.source.<b>string(</b>string<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a source that produces the contents of a
|
||||
<tt>string</tt>, chunk by chunk.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:41 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
cosmic rage/docs/LuaSocket_documentation/luasocket.png
Normal file
BIN
cosmic rage/docs/LuaSocket_documentation/luasocket.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
476
cosmic rage/docs/LuaSocket_documentation/mime.html
Normal file
476
cosmic rage/docs/LuaSocket_documentation/mime.html
Normal file
@@ -0,0 +1,476 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: MIME support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, MIME, Library, Support">
|
||||
<title>LuaSocket: MIME module</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=mime>MIME</h2>
|
||||
|
||||
<p>
|
||||
The <tt>mime</tt> namespace offers filters that apply and remove common
|
||||
content transfer encodings, such as Base64 and Quoted-Printable.
|
||||
It also provides functions to break text into lines and change
|
||||
the end-of-line convention.
|
||||
MIME is described mainly in
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2045.txt">RFC 2045</a>,
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2046.txt">2046</a>,
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2047</a>,
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2047.txt">2048</a>, and
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2048.txt">2049</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
All functionality provided by the MIME module
|
||||
follows the ideas presented in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
LTN012, Filters sources and sinks</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>mime</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the MIME module and everything it requires
|
||||
local mime = require("mime")
|
||||
</pre>
|
||||
|
||||
|
||||
<!-- High-level +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=high>High-level filters</h3>
|
||||
|
||||
<!-- normalize ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="normalize">
|
||||
mime.<b>normalize(</b>[marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts most common end-of-line markers to a specific given marker.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Marker</tt> is the new marker. It defaults to CRLF, the canonic
|
||||
end-of-line marker defined by the MIME standard.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a filter that performs the conversion.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: There is no perfect solution to this problem. Different end-of-line
|
||||
markers are an evil that will probably plague developers forever.
|
||||
This function, however, will work perfectly for text created with any of
|
||||
the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF),
|
||||
or the DOS (CRLF) conventions. Even if the data has mixed end-of-line
|
||||
markers, the function will still work well, although it doesn't
|
||||
guarantee that the number of empty lines will be correct.
|
||||
</p>
|
||||
|
||||
<!-- decode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="decode">
|
||||
mime.<b>decode(</b>"base64"<b>)</b><br>
|
||||
mime.<b>decode(</b>"quoted-printable"<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a filter that decodes data from a given transfer content
|
||||
encoding.
|
||||
</p>
|
||||
|
||||
<!-- encode +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="encode">
|
||||
mime.<b>encode(</b>"base64"<b>)</b><br>
|
||||
mime.<b>encode(</b>"quoted-printable" [, mode]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a filter that encodes data according to a given transfer content
|
||||
encoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
In the Quoted-Printable case, the user can specify whether the data is
|
||||
textual or binary, by passing the <tt>mode</tt> strings "<tt>text</tt>" or
|
||||
"<tt>binary</tt>". <tt>Mode</tt> defaults to "<tt>text</tt>".
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Although both transfer content encodings specify a limit for the line
|
||||
length, the encoding filters do <em>not</em> break text into lines (for
|
||||
added flexibility).
|
||||
Below is a filter that converts binary data to the Base64 transfer content
|
||||
encoding and breaks it into lines of the correct size.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
base64 = ltn12.filter.chain(
|
||||
mime.encode("base64"),
|
||||
mime.wrap("base64")
|
||||
)
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
Note: Text data <em>has</em> to be converted to canonic form
|
||||
<em>before</em> being encoded.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
base64 = ltn12.filter.chain(
|
||||
mime.normalize(),
|
||||
mime.encode("base64"),
|
||||
mime.wrap("base64")
|
||||
)
|
||||
</pre>
|
||||
|
||||
<!-- stuff +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="stuff">
|
||||
mime.<b>stuff()</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a filter that performs stuffing of SMTP messages.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The <a href=smtp.html#send><tt>smtp.send</tt></a> function
|
||||
uses this filter automatically. You don't need to chain it with your
|
||||
source, or apply it to your message body.
|
||||
</p>
|
||||
|
||||
<!-- wrap +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="wrap">
|
||||
mime.<b>wrap(</b>"text" [, length]<b>)</b><br>
|
||||
mime.<b>wrap(</b>"base64"<b>)</b><br>
|
||||
mime.<b>wrap(</b>"quoted-printable"<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a filter that breaks data into lines.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
The "<tt>text</tt>" line-wrap filter simply breaks text into lines by
|
||||
inserting CRLF end-of-line markers at appropriate positions.
|
||||
<tt>Length</tt> defaults 76.
|
||||
The "<tt>base64</tt>" line-wrap filter works just like the default
|
||||
"<tt>text</tt>" line-wrap filter with default length.
|
||||
The function can also wrap "<tt>quoted-printable</tt>" lines, taking care
|
||||
not to break lines in the middle of an escaped character. In that case, the
|
||||
line length is fixed at 76.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
For example, to create an encoding filter for the Quoted-Printable transfer content encoding of text data, do the following:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
qp = ltn12.filter.chain(
|
||||
mime.normalize(),
|
||||
mime.encode("quoted-printable"),
|
||||
mime.wrap("quoted-printable")
|
||||
)
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
Note: To break into lines with a different end-of-line convention, apply
|
||||
a normalization filter after the line break filter.
|
||||
</p>
|
||||
|
||||
<!-- Low-level ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h3 id=low>Low-level filters</h3>
|
||||
|
||||
<!-- b64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="b64">
|
||||
A, B = mime.<b>b64(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Base64 encoding.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The simplest use of this function is to encode a string into it's
|
||||
Base64 transfer content encoding. Notice the extra parenthesis around the
|
||||
call to <tt>mime.b64</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.b64("diego:password")))
|
||||
--> ZGllZ286cGFzc3dvcmQ=
|
||||
</pre>
|
||||
|
||||
<!-- dot +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<p class=name id="dot">
|
||||
A, n = mime.<b>dot(</b>m [, B]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform SMTP stuffing and enable transmission of
|
||||
messages containing the sequence "CRLF.CRLF".
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the stuffed version of <tt>B</tt>. '<tt>n</tt>' gives the
|
||||
number of characters from the sequence CRLF seen in the end of <tt>B</tt>.
|
||||
'<tt>m</tt>' should tell the same, but for the previous chunk.
|
||||
</p>
|
||||
|
||||
<p class=note>Note: The message body is defined to begin with
|
||||
an implicit CRLF. Therefore, to stuff a message correctly, the
|
||||
first <tt>m</tt> should have the value 2.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((string.gsub(mime.dot(2, ".\r\nStuffing the message.\r\n.\r\n."), "\r\n", "\\n")))
|
||||
--> ..\nStuffing the message.\n..\n..
|
||||
</pre>
|
||||
|
||||
<p class=note>
|
||||
Note: The <a href=smtp.html#send><tt>smtp.send</tt></a> function
|
||||
uses this filter automatically. You don't need to
|
||||
apply it again.
|
||||
</p>
|
||||
|
||||
<!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="eol">
|
||||
A, B = mime.<b>eol(</b>C [, D, marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform end-of-line marker translation.
|
||||
For each chunk, the function needs to know if the last character of the
|
||||
previous chunk could be part of an end-of-line marker or not. This is the
|
||||
context the function receives besides the chunk. An updated version of
|
||||
the context is returned after each new chunk.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the translated version of <tt>D</tt>. <tt>C</tt> is the
|
||||
ASCII value of the last character of the previous chunk, if it was a
|
||||
candidate for line break, or 0 otherwise.
|
||||
<tt>B</tt> is the same as <tt>C</tt>, but for the current
|
||||
chunk. <tt>Marker</tt> gives the new end-of-line marker and defaults to CRLF.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- translates the end-of-line marker to UNIX
|
||||
unix = mime.eol(0, dos, "\n")
|
||||
</pre>
|
||||
|
||||
<!-- qp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="qp">
|
||||
A, B = mime.<b>qp(</b>C [, D, marker]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Quoted-Printable encoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the encoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> encoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
Throughout encoding, occurrences of CRLF are replaced by the
|
||||
<tt>marker</tt>, which itself defaults to CRLF.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The simplest use of this function is to encode a string into it's
|
||||
Quoted-Printable transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.qp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.qp("ma<6D><61>")))
|
||||
--> ma=E7=E3=
|
||||
</pre>
|
||||
|
||||
<!-- qpwrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="qpwrp">
|
||||
A, m = mime.<b>qpwrp(</b>n [, B, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to break Quoted-Printable text into lines.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: Besides breaking text into lines, this function makes sure the line
|
||||
breaks don't fall in the middle of an escaped character combination. Also,
|
||||
this function only breaks lines that are bigger than <tt>length</tt> bytes.
|
||||
</p>
|
||||
|
||||
<!-- unb64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="unb64">
|
||||
A, B = mime.<b>unb64(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to perform Base64 decoding.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is the empty string
|
||||
and <tt>B</tt> returns whatever couldn't be decoded.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The simplest use of this function is to decode a string from it's
|
||||
Base64 transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.unb64("ZGllZ286cGFzc3dvcmQ=")))
|
||||
--> diego:password
|
||||
</pre>
|
||||
|
||||
<!-- unqp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="unqp">
|
||||
A, B = mime.<b>unqp(</b>C [, D]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to remove the Quoted-Printable transfer content encoding
|
||||
from data.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is the decoded version of the largest prefix of
|
||||
<tt>C..D</tt>
|
||||
that can be decoded unambiguously. <tt>B</tt> has the remaining bytes of
|
||||
<tt>C..D</tt>, <em>before</em> decoding.
|
||||
If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is augmented with
|
||||
the encoding of the remaining bytes of <tt>C</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The simplest use of this function is to decode a string from it's
|
||||
Quoted-Printable transfer content encoding.
|
||||
Notice the extra parenthesis around the call to <tt>mime.unqp</tt>, to discard the second return value.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
print((mime.qp("ma=E7=E3=")))
|
||||
--> ma<6D><61>
|
||||
</pre>
|
||||
|
||||
<!-- wrp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="wrp">
|
||||
A, m = mime.<b>wrp(</b>n [, B, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Low-level filter to break text into lines with CRLF marker.
|
||||
Text is assumed to be in the <a href=#normalize><tt>normalize</tt></a> form.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>A</tt> is a copy of <tt>B</tt>, broken into lines of at most
|
||||
<tt>length</tt> bytes (defaults to 76).
|
||||
'<tt>n</tt>' should tell how many bytes are left for the first
|
||||
line of <tt>B</tt> and '<tt>m</tt>' returns the number of bytes
|
||||
left in the last line of <tt>A</tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: This function only breaks lines that are bigger than
|
||||
<tt>length</tt> bytes. The resulting line length does not include the CRLF
|
||||
marker.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:44 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
54
cosmic rage/docs/LuaSocket_documentation/reference.css
Normal file
54
cosmic rage/docs/LuaSocket_documentation/reference.css
Normal file
@@ -0,0 +1,54 @@
|
||||
body {
|
||||
margin-left: 1em;
|
||||
margin-right: 1em;
|
||||
font-family: "Verdana", sans-serif;
|
||||
}
|
||||
|
||||
tt {
|
||||
font-family: "Andale Mono", monospace;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 { margin-left: 0em; }
|
||||
|
||||
|
||||
h3 { padding-top: 1em; }
|
||||
|
||||
p { margin-left: 1em; }
|
||||
|
||||
p.name {
|
||||
font-family: "Andale Mono", monospace;
|
||||
padding-top: 1em;
|
||||
margin-left: 0em;
|
||||
}
|
||||
|
||||
a[href] { color: #00007f; }
|
||||
|
||||
blockquote { margin-left: 3em; }
|
||||
|
||||
pre.example {
|
||||
background: #ccc;
|
||||
padding: 1em;
|
||||
margin-left: 1em;
|
||||
font-family: "Andale Mono", monospace;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin-left: 0em;
|
||||
background: #00007f;
|
||||
border: 0px;
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
ul { list-style-type: disc; }
|
||||
|
||||
table.index { border: 1px #00007f; }
|
||||
table.index td { text-align: left; vertical-align: top; }
|
||||
table.index ul { padding-top: 0em; margin-top: 0em; }
|
||||
|
||||
h1:first-letter,
|
||||
h2:first-letter,
|
||||
h2:first-letter,
|
||||
h3:first-letter { color: #00007f; }
|
||||
|
||||
div.header, div.footer { margin-left: 0em; }
|
||||
239
cosmic rage/docs/LuaSocket_documentation/reference.html
Normal file
239
cosmic rage/docs/LuaSocket_documentation/reference.html
Normal file
@@ -0,0 +1,239 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: Index to reference manual">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Index, Manual, Network, Library,
|
||||
Support, Manual">
|
||||
<title>LuaSocket: Index to reference manual</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- reference +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2>Reference</h2>
|
||||
|
||||
<blockquote>
|
||||
<a href="dns.html">DNS (in socket)</a>
|
||||
<blockquote>
|
||||
<a href="dns.html#toip">toip</a>,
|
||||
<a href="dns.html#tohostname">tohostname</a>,
|
||||
<a href="dns.html#gethostname">gethostname</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- ftp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="ftp.html">FTP</a>
|
||||
<blockquote>
|
||||
<a href="ftp.html#get">get</a>,
|
||||
<a href="ftp.html#put">put</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- http +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="http.html">HTTP</a>
|
||||
<blockquote>
|
||||
<a href="http.html#request">request</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- ltn12 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="ltn12.html">LTN12</a>
|
||||
<blockquote>
|
||||
<a href="ltn12.html#filter">filter</a>:
|
||||
<a href="ltn12.html#filter.chain">chain</a>,
|
||||
<a href="ltn12.html#filter.cycle">cycle</a>.
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<a href="ltn12.html#pump">pump</a>:
|
||||
<a href="ltn12.html#pump.all">all</a>,
|
||||
<a href="ltn12.html#pump.step">step</a>.
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<a href="ltn12.html#sink">sink</a>:
|
||||
<a href="ltn12.html#sink.chain">chain</a>,
|
||||
<a href="ltn12.html#sink.error">error</a>,
|
||||
<a href="ltn12.html#sink.file">file</a>,
|
||||
<a href="ltn12.html#sink.null">null</a>,
|
||||
<a href="ltn12.html#sink.simplify">simplify</a>,
|
||||
<a href="ltn12.html#sink.table">table</a>.
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<a href="ltn12.html#source">source</a>:
|
||||
<a href="ltn12.html#source.cat">cat</a>,
|
||||
<a href="ltn12.html#source.chain">chain</a>,
|
||||
<a href="ltn12.html#source.empty">empty</a>,
|
||||
<a href="ltn12.html#source.error">error</a>,
|
||||
<a href="ltn12.html#source.file">file</a>,
|
||||
<a href="ltn12.html#source.simplify">simplify</a>,
|
||||
<a href="ltn12.html#source.string">string</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- mime +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="mime.html">MIME</a>
|
||||
<blockquote>
|
||||
<a href="mime.html#high">high-level</a>:
|
||||
<a href="mime.html#normalize">normalize</a>,
|
||||
<a href="mime.html#decode">decode</a>,
|
||||
<a href="mime.html#encode">encode</a>,
|
||||
<a href="mime.html#stuff">stuff</a>,
|
||||
<a href="mime.html#wrap">wrap</a>.
|
||||
</blockquote>
|
||||
<blockquote>
|
||||
<a href="mime.html#low">low-level</a>:
|
||||
<a href="mime.html#b64">b64</a>,
|
||||
<a href="mime.html#dot">dot</a>,
|
||||
<a href="mime.html#eol">eol</a>,
|
||||
<a href="mime.html#qp">qp</a>,
|
||||
<a href="mime.html#wrp">wrp</a>,
|
||||
<a href="mime.html#qpwrp">qpwrp</a>.
|
||||
<a href="mime.html#unb64">unb64</a>,
|
||||
<a href="mime.html#unqp">unqp</a>,
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="smtp.html">SMTP</a>
|
||||
<blockquote>
|
||||
<a href="smtp.html#message">message</a>,
|
||||
<a href="smtp.html#send">send</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="socket.html">Socket</a>
|
||||
<blockquote>
|
||||
<a href="socket.html#debug">_DEBUG</a>,
|
||||
<a href="dns.html#dns">dns</a>,
|
||||
<a href="socket.html#gettime">gettime</a>,
|
||||
<a href="socket.html#newtry">newtry</a>,
|
||||
<a href="socket.html#protect">protect</a>,
|
||||
<a href="socket.html#select">select</a>,
|
||||
<a href="socket.html#sink">sink</a>,
|
||||
<a href="socket.html#skip">skip</a>,
|
||||
<a href="socket.html#sleep">sleep</a>,
|
||||
<a href="socket.html#source">source</a>,
|
||||
<a href="tcp.html#tcp">tcp</a>,
|
||||
<a href="socket.html#try">try</a>,
|
||||
<a href="udp.html#udp">udp</a>,
|
||||
<a href="socket.html#version">_VERSION</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="tcp.html">TCP (in socket)</a>
|
||||
<blockquote>
|
||||
<a href="tcp.html#accept">accept</a>,
|
||||
<a href="tcp.html#bind">bind</a>,
|
||||
<a href="tcp.html#close">close</a>,
|
||||
<a href="tcp.html#connect">connect</a>,
|
||||
<a href="tcp.html#getpeername">getpeername</a>,
|
||||
<a href="tcp.html#getsockname">getsockname</a>,
|
||||
<a href="tcp.html#getstats">getstats</a>,
|
||||
<a href="tcp.html#receive">receive</a>,
|
||||
<a href="tcp.html#send">send</a>,
|
||||
<a href="tcp.html#setoption">setoption</a>,
|
||||
<a href="tcp.html#setstats">setstats</a>,
|
||||
<a href="tcp.html#settimeout">settimeout</a>,
|
||||
<a href="tcp.html#shutdown">shutdown</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- udp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="udp.html">UDP (in socket)</a>
|
||||
<blockquote>
|
||||
<a href="udp.html#close">close</a>,
|
||||
<a href="udp.html#getpeername">getpeername</a>,
|
||||
<a href="udp.html#getsockname">getsockname</a>,
|
||||
<a href="udp.html#receive">receive</a>,
|
||||
<a href="udp.html#receivefrom">receivefrom</a>,
|
||||
<a href="udp.html#send">send</a>,
|
||||
<a href="udp.html#sendto">sendto</a>,
|
||||
<a href="udp.html#setpeername">setpeername</a>,
|
||||
<a href="udp.html#setsockname">setsockname</a>,
|
||||
<a href="udp.html#setoption">setoption</a>,
|
||||
<a href="udp.html#settimeout">settimeout</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<blockquote>
|
||||
<a href="url.html">URL</a>
|
||||
<blockquote>
|
||||
<a href="url.html#absolute">absolute</a>,
|
||||
<a href="url.html#build">build</a>,
|
||||
<a href="url.html#build_path">build_path</a>,
|
||||
<a href="url.html#escape">escape</a>,
|
||||
<a href="url.html#parse">parse</a>,
|
||||
<a href="url.html#parse_path">parse_path</a>,
|
||||
<a href="url.html#unescape">unescape</a>.
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
|
||||
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:47 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
417
cosmic rage/docs/LuaSocket_documentation/smtp.html
Normal file
417
cosmic rage/docs/LuaSocket_documentation/smtp.html
Normal file
@@ -0,0 +1,417 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: SMTP support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, SMTP, E-Mail, MIME, Multipart,
|
||||
Library, Support">
|
||||
<title>LuaSocket: SMTP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- smtp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=smtp>SMTP</h2>
|
||||
|
||||
<p> The <tt>smtp</tt> namespace provides functionality to send e-mail
|
||||
messages. The high-level API consists of two functions: one to
|
||||
define an e-mail message, and another to actually send the message.
|
||||
Although almost all users will find that these functions provide more than
|
||||
enough functionality, the underlying implementation allows for even more
|
||||
control (if you bother to read the code).
|
||||
</p>
|
||||
|
||||
<p>The implementation conforms to the Simple Mail Transfer Protocol,
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2821.txt">RFC 2821</a>.
|
||||
Another RFC of interest is <a
|
||||
href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a>,
|
||||
which governs the Internet Message Format.
|
||||
Multipart messages (those that contain attachments) are part
|
||||
of the MIME standard, but described mainly
|
||||
in <a href="http://www.cs.princeton.edu/~diego/rfc/rfc2046.txt">RFC
|
||||
2046</a>
|
||||
|
||||
<p> In the description below, good understanding of <a
|
||||
href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> LTN012, Filters
|
||||
sources and sinks</a> and the <a href=mime.html>MIME</a> module is
|
||||
assumed. In fact, the SMTP module was the main reason for their
|
||||
creation. </p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>smtp</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the SMTP module and everything it requires
|
||||
local smtp = require("socket.smtp")
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
MIME headers are represented as a Lua table in the form:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<table summary="MIME headers in Lua table">
|
||||
<tr><td><tt>
|
||||
headers = {<br>
|
||||
field-1-name = <i>field-1-value</i>,<br>
|
||||
field-2-name = <i>field-2-value</i>,<br>
|
||||
field-3-name = <i>field-3-value</i>,<br>
|
||||
...<br>
|
||||
field-n-name = <i>field-n-value</i><br>
|
||||
}
|
||||
</tt></td></tr>
|
||||
</table>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
Field names are case insensitive (as specified by the standard) and all
|
||||
functions work with lowercase field names.
|
||||
Field values are left unmodified.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: MIME headers are independent of order. Therefore, there is no problem
|
||||
in representing them in a Lua table.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The following constants can be set to control the default behavior of
|
||||
the SMTP module:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>DOMAIN</tt>: domain used to greet the server;
|
||||
<li> <tt>PORT</tt>: default port used for the connection;
|
||||
<li> <tt>SERVER</tt>: default server used for the connection;
|
||||
<li> <tt>TIMEOUT</tt>: default timeout for all I/O operations;
|
||||
<li> <tt>ZONE</tt>: default time zone.
|
||||
</ul>
|
||||
|
||||
<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=send>
|
||||
smtp.<b>send{</b><br>
|
||||
from = <i>string</i>,<br>
|
||||
rcpt = <i>string</i> or <i>string-table</i>,<br>
|
||||
source = <i>LTN12 source</i>,<br>
|
||||
[user = <i>string</i>,]<br>
|
||||
[password = <i>string</i>,]<br>
|
||||
[server = <i>string</i>,]<br>
|
||||
[port = <i>number</i>,]<br>
|
||||
[domain = <i>string</i>,]<br>
|
||||
[step = <i>LTN12 pump step</i>,]<br>
|
||||
[create = <i>function</i>]<br>
|
||||
<b>}</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Sends a message to a recipient list. Since sending messages is not as
|
||||
simple as downloading an URL from a FTP or HTTP server, this function
|
||||
doesn't have a simple interface. However, see the
|
||||
<a href=#message><tt>message</tt></a> source factory for
|
||||
a very powerful way to define the message contents.
|
||||
</p>
|
||||
|
||||
|
||||
<p class=parameters>
|
||||
The sender is given by the e-mail address in the <tt>from</tt> field.
|
||||
<tt>Rcpt</tt> is a Lua table with one entry for each recipient e-mail
|
||||
address, or a string
|
||||
in case there is just one recipient.
|
||||
The contents of the message are given by a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>source</tt>. Several arguments are optional:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>user</tt>, <tt>password</tt>: User and password for
|
||||
authentication. The function will attempt LOGIN and PLAIN authentication
|
||||
methods if supported by the server (both are unsafe);
|
||||
<li> <tt>server</tt>: Server to connect to. Defaults to "localhost";
|
||||
<li> <tt>port</tt>: Port to connect to. Defaults to 25;
|
||||
<li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the
|
||||
local machine host name;
|
||||
<li> <tt>step</tt>:
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
pump step function used to pass data from the
|
||||
source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;
|
||||
<li><tt>create</tt>: An optional function to be used instead of
|
||||
<a href=tcp.html#socket.tcp><tt>socket.tcp</tt></a> when the communications socket is created.
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
If successful, the function returns 1. Otherwise, the function returns
|
||||
<b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: SMTP servers can be very picky with the format of e-mail
|
||||
addresses. To be safe, use only addresses of the form
|
||||
"<tt><fulano@example.com></tt>" in the <tt>from</tt> and
|
||||
<tt>rcpt</tt> arguments to the <tt>send</tt> function. In headers, e-mail
|
||||
addresses can take whatever form you like. </p>
|
||||
|
||||
<p class=note>
|
||||
Big note: There is a good deal of misconception with the use of the
|
||||
destination address field headers, i.e., the '<tt>To</tt>', '<tt>Cc</tt>',
|
||||
and, more importantly, the '<tt>Bcc</tt>' headers. Do <em>not</em> add a
|
||||
'<tt>Bcc</tt>' header to your messages because it will probably do the
|
||||
exact opposite of what you expect.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Only recipients specified in the <tt>rcpt</tt> list will receive a copy of the
|
||||
message. Each recipient of an SMTP mail message receives a copy of the
|
||||
message body along with the headers, and nothing more. The headers
|
||||
<em>are</em> part of the message and should be produced by the
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
|
||||
part of the message and will not be sent to anyone.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a>
|
||||
has two <em>important and short</em> sections, "3.6.3. Destination address
|
||||
fields" and "5. Security considerations", explaining the proper
|
||||
use of these headers. Here is a summary of what it says:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> <tt>To</tt>: contains the address(es) of the primary recipient(s)
|
||||
of the message;
|
||||
<li> <tt>Cc</tt>: (where the "Cc" means "Carbon Copy" in the sense of
|
||||
making a copy on a typewriter using carbon paper) contains the
|
||||
addresses of others who are to receive the message, though the
|
||||
content of the message may not be directed at them;
|
||||
<li> <tt>Bcc</tt>: (where the "Bcc" means "Blind Carbon
|
||||
Copy") contains addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message.
|
||||
</ul>
|
||||
|
||||
<p class=note>
|
||||
The LuaSocket <tt>send</tt> function does not care or interpret the
|
||||
headers you send, but it gives you full control over what is sent and
|
||||
to whom it is sent:
|
||||
</p>
|
||||
<ul>
|
||||
<li> If someone is to receive the message, the e-mail address <em>has</em>
|
||||
to be in the recipient list. This is the only parameter that controls who
|
||||
gets a copy of the message;
|
||||
<li> If there are multiple recipients, none of them will automatically
|
||||
know that someone else got that message. That is, the default behavior is
|
||||
similar to the <tt>Bcc</tt> field of popular e-mail clients;
|
||||
<li> It is up to you to add the <tt>To</tt> header with the list of primary
|
||||
recipients so that other recipients can see it;
|
||||
<li> It is also up to you to add the <tt>Cc</tt> header with the
|
||||
list of additional recipients so that everyone else sees it;
|
||||
<li> Adding a header <tt>Bcc</tt> is nonsense, unless it is
|
||||
empty. Otherwise, everyone receiving the message will see it and that is
|
||||
exactly what you <em>don't</em> want to happen!
|
||||
</ul>
|
||||
|
||||
<p class=note>
|
||||
I hope this clarifies the issue. Otherwise, please refer to
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2821.txt">RFC 2821</a>
|
||||
and
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2822.txt">RFC 2822</a>.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the smtp support
|
||||
local smtp = require("socket.smtp")
|
||||
|
||||
-- Connects to server "localhost" and sends a message to users
|
||||
-- "fulano@example.com", "beltrano@example.com",
|
||||
-- and "sicrano@example.com".
|
||||
-- Note that "fulano" is the primary recipient, "beltrano" receives a
|
||||
-- carbon copy and neither of them knows that "sicrano" received a blind
|
||||
-- carbon copy of the message.
|
||||
from = "<luasocket@example.com>"
|
||||
|
||||
rcpt = {
|
||||
"<fulano@example.com>",
|
||||
"<beltrano@example.com>",
|
||||
"<sicrano@example.com>"
|
||||
}
|
||||
|
||||
mesgt = {
|
||||
headers = {
|
||||
to = "Fulano da Silva <fulano@example.com>",
|
||||
cc = '"Beltrano F. Nunes" <beltrano@example.com>',
|
||||
subject = "My first message"
|
||||
},
|
||||
body = "I hope this works. If it does, I can send you another 1000 copies."
|
||||
}
|
||||
|
||||
r, e = smtp.send{
|
||||
from = from,
|
||||
rcpt = rcpt,
|
||||
source = smtp.message(mesgt)
|
||||
}
|
||||
</pre>
|
||||
|
||||
<!-- message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=message>
|
||||
smtp.<b>message(</b>mesgt<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
The only parameter of the function is a table describing the message.
|
||||
<tt>Mesgt</tt> has the following form (notice the recursive structure):
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<table summary="Mesgt table structure">
|
||||
<tr><td><tt>
|
||||
mesgt = {<br>
|
||||
headers = <i>header-table</i>,<br>
|
||||
body = <i>LTN12 source</i> or <i>string</i> or
|
||||
<i>multipart-mesgt</i><br>
|
||||
}<br>
|
||||
<br>
|
||||
multipart-mesgt = {<br>
|
||||
[preamble = <i>string</i>,]<br>
|
||||
[1] = <i>mesgt</i>,<br>
|
||||
[2] = <i>mesgt</i>,<br>
|
||||
...<br>
|
||||
[<i>n</i>] = <i>mesgt</i>,<br>
|
||||
[epilogue = <i>string</i>,]<br>
|
||||
}<br>
|
||||
</tt></td></tr>
|
||||
</table>
|
||||
</blockquote>
|
||||
|
||||
<p class=parameters>
|
||||
For a simple message, all that is needed is a set of <tt>headers</tt>
|
||||
and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
|
||||
or as a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source. For multipart messages, the body is a table that
|
||||
recursively defines each part as an independent message, plus an optional
|
||||
<tt>preamble</tt> and <tt>epilogue</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a <em>simple</em>
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source that produces the
|
||||
message contents as defined by <tt>mesgt</tt>, chunk by chunk.
|
||||
Hopefully, the following
|
||||
example will make things clear. When in doubt, refer to the appropriate RFC
|
||||
as listed in the introduction. </p>
|
||||
|
||||
<pre class=example>
|
||||
-- load the smtp support and its friends
|
||||
local smtp = require("socket.smtp")
|
||||
local mime = require("mime")
|
||||
local ltn12 = require("ltn12")
|
||||
|
||||
-- creates a source to send a message with two parts. The first part is
|
||||
-- plain text, the second part is a PNG image, encoded as base64.
|
||||
source = smtp.message{
|
||||
headers = {
|
||||
-- Remember that headers are *ignored* by smtp.send.
|
||||
from = "Sicrano de Oliveira <sicrano@example.com>",
|
||||
to = "Fulano da Silva <fulano@example.com>",
|
||||
subject = "Here is a message with attachments"
|
||||
},
|
||||
body = {
|
||||
preamble = "If your client doesn't understand attachments, \r\n" ..
|
||||
"it will still display the preamble and the epilogue.\r\n" ..
|
||||
"Preamble will probably appear even in a MIME enabled client.",
|
||||
-- first part: no headers means plain text, us-ascii.
|
||||
-- The mime.eol low-level filter normalizes end-of-line markers.
|
||||
[1] = {
|
||||
body = mime.eol(0, [[
|
||||
Lines in a message body should always end with CRLF.
|
||||
The smtp module will *NOT* perform translation. However, the
|
||||
send function *DOES* perform SMTP stuffing, whereas the message
|
||||
function does *NOT*.
|
||||
]])
|
||||
},
|
||||
-- second part: headers describe content to be a png image,
|
||||
-- sent under the base64 transfer content encoding.
|
||||
-- notice that nothing happens until the message is actually sent.
|
||||
-- small chunks are loaded into memory right before transmission and
|
||||
-- translation happens on the fly.
|
||||
[2] = {
|
||||
headers = {
|
||||
["content-type"] = 'image/png; name="image.png"',
|
||||
["content-disposition"] = 'attachment; filename="image.png"',
|
||||
["content-description"] = 'a beautiful image',
|
||||
["content-transfer-encoding"] = "BASE64"
|
||||
},
|
||||
body = ltn12.source.chain(
|
||||
ltn12.source.file(io.open("image.png", "rb")),
|
||||
ltn12.filter.chain(
|
||||
mime.encode("base64"),
|
||||
mime.wrap()
|
||||
)
|
||||
)
|
||||
},
|
||||
epilogue = "This might also show up, but after the attachments"
|
||||
}
|
||||
}
|
||||
|
||||
-- finally send it
|
||||
r, e = smtp.send{
|
||||
from = "<sicrano@example.com>",
|
||||
rcpt = "<fulano@example.com>",
|
||||
source = source,
|
||||
}
|
||||
</pre>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:51 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
404
cosmic rage/docs/LuaSocket_documentation/socket.html
Normal file
404
cosmic rage/docs/LuaSocket_documentation/socket.html
Normal file
@@ -0,0 +1,404 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: The core namespace">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Socket, Network, Library, Support">
|
||||
<title>LuaSocket: The socket namespace</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- socket +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=socket>The socket namespace</h2>
|
||||
|
||||
<p>
|
||||
The <tt>socket</tt> namespace contains the core functionality of LuaSocket.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>socket</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the socket module
|
||||
local socket = require("socket")
|
||||
</pre>
|
||||
|
||||
<!-- bind ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=bind>
|
||||
socket.<b>bind(</b>address, port [, backlog]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
This function is a shortcut that creates and returns a TCP server object
|
||||
bound to a local <tt>address</tt> and <tt>port</tt>, ready to
|
||||
accept client connections. Optionally,
|
||||
user can also specify the <tt>backlog</tt> argument to the
|
||||
<a href=tcp.html#listen><tt>listen</tt></a> method (defaults to 32).
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The server object returned will have the option "<tt>reuseaddr</tt>"
|
||||
set to <tt><b>true</b></tt>.
|
||||
</p>
|
||||
|
||||
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=connect>
|
||||
socket.<b>connect(</b>address, port [, locaddr, locport]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
This function is a shortcut that creates and returns a TCP client object
|
||||
connected to a remote <tt>host</tt> at a given <tt>port</tt>. Optionally,
|
||||
the user can also specify the local address and port to bind
|
||||
(<tt>locaddr</tt> and <tt>locport</tt>).
|
||||
</p>
|
||||
|
||||
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=debug>
|
||||
socket.<b>_DEBUG</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
This constant is set to <tt><b>true</b></tt> if the library was compiled
|
||||
with debug support.
|
||||
</p>
|
||||
|
||||
<!-- newtry +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=newtry>
|
||||
socket.<b>newtry(</b>finalizer<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a <em>clean</em>
|
||||
<a href="#try"><tt>try</tt></a>
|
||||
function that allows for cleanup before the exception
|
||||
is raised.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Finalizer</tt> is a function that will be called before
|
||||
<tt>try</tt> throws the exception. It will be called
|
||||
in <em>protected</em> mode.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns your customized <tt>try</tt> function.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: This idea saved a <em>lot</em> of work with the
|
||||
implementation of protocols in LuaSocket:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
foo = socket.protect(function()
|
||||
-- connect somewhere
|
||||
local c = socket.try(socket.connect("somewhere", 42))
|
||||
-- create a try function that closes 'c' on error
|
||||
local try = socket.newtry(function() c:close() end)
|
||||
-- do everything reassured c will be closed
|
||||
try(c:send("hello there?\r\n"))
|
||||
local answer = try(c:receive())
|
||||
...
|
||||
try(c:send("good bye\r\n"))
|
||||
c:close()
|
||||
end)
|
||||
</pre>
|
||||
|
||||
|
||||
<!-- protect +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=protect>
|
||||
socket.<b>protect(</b>func<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Converts a function that throws exceptions into a safe function. This
|
||||
function only catches exceptions thrown by the <a href=#try><tt>try</tt></a>
|
||||
and <a href=#newtry><tt>newtry</tt></a> functions. It does not catch normal
|
||||
Lua errors.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Func</tt> is a function that calls
|
||||
<a href=#try><tt>try</tt></a> (or <tt>assert</tt>, or <tt>error</tt>)
|
||||
to throw exceptions.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Returns an equivalent function that instead of throwing exceptions,
|
||||
returns <tt><b>nil</b></tt> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: Beware that if your function performs some illegal operation that
|
||||
raises an error, the protected function will catch the error and return it
|
||||
as a string. This is because the <a href=#try><tt>try</tt></a> function
|
||||
uses errors as the mechanism to throw exceptions.
|
||||
</p>
|
||||
|
||||
<!-- select +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=select>
|
||||
socket.<b>select(</b>recvt, sendt [, timeout]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Waits for a number of sockets to change status.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Recvt</tt> is an array with the sockets to test for characters
|
||||
available for reading. Sockets in the <tt>sendt</tt> array are watched to
|
||||
see if it is OK to immediately write on them. <tt>Timeout</tt> is the
|
||||
maximum amount of time (in seconds) to wait for a change in status. A
|
||||
<tt><b>nil</b></tt>, negative or omitted <tt>timeout</tt> value allows the
|
||||
function to block indefinitely. <tt>Recvt</tt> and <tt>sendt</tt> can also
|
||||
be empty tables or <tt><b>nil</b></tt>. Non-socket values (or values with
|
||||
non-numeric indices) in the arrays will be silently ignored.
|
||||
</p>
|
||||
|
||||
<p class=return> The function returns a list with the sockets ready for
|
||||
reading, a list with the sockets ready for writing and an error message.
|
||||
The error message is "<tt>timeout</tt>" if a timeout condition was met and
|
||||
<tt><b>nil</b></tt> otherwise. The returned tables are
|
||||
doubly keyed both by integers and also by the sockets
|
||||
themselves, to simplify the test if a specific socket has
|
||||
changed status.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<b>Important note</b>: a known bug in WinSock causes <tt>select</tt> to fail
|
||||
on non-blocking TCP sockets. The function may return a socket as
|
||||
writable even though the socket is <em>not</em> ready for sending.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<b>Another important note</b>: calling select with a server socket in the receive parameter before a call to accept does <em>not</em> guarantee
|
||||
<a href=tcp.html#accept><tt>accept</tt></a> will return immediately.
|
||||
Use the <a href=tcp.html#settimeout><tt>settimeout</tt></a>
|
||||
method or <tt>accept</tt> might block forever.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<b>Yet another note</b>: If you close a socket and pass
|
||||
it to <tt>select</tt>, it will be ignored.
|
||||
</p>
|
||||
|
||||
<!-- sink ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=sink>
|
||||
socket.<b>sink(</b>mode, socket<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
sink from a stream socket object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Mode</tt> defines the behavior of the sink. The following
|
||||
options are available:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>"http-chunked"</tt>: sends data through socket after applying the
|
||||
<em>chunked transfer coding</em>, closing the socket when done;
|
||||
<li> <tt>"close-when-done"</tt>: sends all received data through the
|
||||
socket, closing the socket when done;
|
||||
<li> <tt>"keep-open"</tt>: sends all received data through the
|
||||
socket, leaving it open when done.
|
||||
</ul>
|
||||
<p>
|
||||
<tt>Socket</tt> is the stream socket object used to send the data.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a sink with the appropriate behavior.
|
||||
</p>
|
||||
|
||||
<!-- skip ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=skip>
|
||||
socket.<b>skip(</b>d [, ret<sub>1</sub>, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Drops a number of arguments and returns the remaining.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>D</tt> is the number of arguments to drop. <tt>Ret<sub>1</sub></tt> to
|
||||
<tt>ret<sub>N</sub></tt> are the arguments.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns <tt>ret<sub>d+1</sub></tt> to <tt>ret<sub>N</sub></tt>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: This function is useful to avoid creation of dummy variables:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- get the status code and separator from SMTP server reply
|
||||
local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
|
||||
</pre>
|
||||
|
||||
<!-- sleep ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=sleep>
|
||||
socket.<b>sleep(</b>time<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Freezes the program execution during a given amount of time.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Time</tt> is the number of seconds to sleep for.
|
||||
</p>
|
||||
|
||||
<!-- source +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=source>
|
||||
socket.<b>source(</b>mode, socket [, length]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates an
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
|
||||
source from a stream socket object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Mode</tt> defines the behavior of the source. The following
|
||||
options are available:
|
||||
</p>
|
||||
<ul>
|
||||
<li> <tt>"http-chunked"</tt>: receives data from socket and removes the
|
||||
<em>chunked transfer coding</em> before returning the data;
|
||||
<li> <tt>"by-length"</tt>: receives a fixed number of bytes from the
|
||||
socket. This mode requires the extra argument <tt>length</tt>;
|
||||
<li> <tt>"until-closed"</tt>: receives data from a socket until the other
|
||||
side closes the connection.
|
||||
</ul>
|
||||
<p>
|
||||
<tt>Socket</tt> is the stream socket object used to receive the data.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a source with the appropriate behavior.
|
||||
</p>
|
||||
|
||||
<!-- time ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=gettime>
|
||||
socket.<b>gettime()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns the time in seconds, relative to the origin of the
|
||||
universe. You should subtract the values returned by this function
|
||||
to get meaningful values.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
t = socket.gettime()
|
||||
-- do stuff
|
||||
print(socket.gettime() - t .. " seconds elapsed")
|
||||
</pre>
|
||||
|
||||
<!-- try ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=try>
|
||||
socket.<b>try(</b>ret<sub>1</sub> [, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Throws an exception in case of error. The exception can only be caught
|
||||
by the <a href=#protect><tt>protect</tt></a> function. It does not explode
|
||||
into an error message.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Ret<sub>1</sub></tt> to <tt>ret<sub>N</sub></tt> can be arbitrary
|
||||
arguments, but are usually the return values of a function call
|
||||
nested with <tt>try</tt>.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns <tt>ret</tt><sub>1</sub> to <tt>ret</tt><sub>N</sub> if
|
||||
<tt>ret</tt><sub>1</sub> is not <tt><b>nil</b></tt>. Otherwise, it calls <tt>error</tt> passing <tt>ret</tt><sub>2</sub>.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- connects or throws an exception with the appropriate error message
|
||||
c = socket.try(socket.connect("localhost", 80))
|
||||
</pre>
|
||||
|
||||
<!-- version ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=version>
|
||||
socket.<b>_VERSION</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
This constant has a string describing the current LuaSocket version.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:54 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
533
cosmic rage/docs/LuaSocket_documentation/tcp.html
Normal file
533
cosmic rage/docs/LuaSocket_documentation/tcp.html
Normal file
@@ -0,0 +1,533 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: The TCP/IP support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Socket, TCP, Library, Network, Support">
|
||||
<title>LuaSocket: TCP/IP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- tcp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=tcp>TCP</h2>
|
||||
|
||||
<!-- socket.tcp +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=socket.tcp>
|
||||
socket.<b>tcp()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Creates and returns a TCP master object. A master object can
|
||||
be transformed into a server object with the method
|
||||
<a href=#listen><tt>listen</tt></a> (after a call to <a
|
||||
href=#bind><tt>bind</tt></a>) or into a client object with
|
||||
the method <a href=#connect><tt>connect</tt></a>. The only other
|
||||
method supported by a master object is the
|
||||
<a href=#close><tt>close</tt></a> method.</p>
|
||||
|
||||
<p class=return>
|
||||
In case of success, a new master object is returned. In case of error,
|
||||
<b><tt>nil</tt></b> is returned, followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- accept +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=accept>
|
||||
server:<b>accept()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Waits for a remote connection on the server
|
||||
object and returns a client object representing that connection.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
If a connection is successfully initiated, a client object is returned.
|
||||
If a timeout condition is met, the method returns <b><tt>nil</tt></b>
|
||||
followed by the error string '<tt>timeout</tt>'. Other errors are
|
||||
reported by <b><tt>nil</tt></b> followed by a message describing the error.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: calling <a href=socket.html#select><tt>socket.select</tt></a>
|
||||
with a server object in
|
||||
the <tt>recvt</tt> parameter before a call to <tt>accept</tt> does
|
||||
<em>not</em> guarantee <tt>accept</tt> will return immediately. Use the <a
|
||||
href=#settimeout><tt>settimeout</tt></a> method or <tt>accept</tt>
|
||||
might block until <em>another</em> client shows up.
|
||||
</p>
|
||||
|
||||
<!-- bind +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=bind>
|
||||
master:<b>bind(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Binds a master object to <tt>address</tt> and <tt>port</tt> on the
|
||||
local host.
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or a host name.
|
||||
<tt>Port</tt> must be an integer number in the range [0..64K).
|
||||
If <tt>address</tt>
|
||||
is '<tt>*</tt>', the system binds to all local interfaces
|
||||
using the <tt>INADDR_ANY</tt> constant. If <tt>port</tt> is 0, the system automatically
|
||||
chooses an ephemeral port.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
In case of success, the method returns 1. In case of error, the
|
||||
method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The function <a href=socket.html#bind><tt>socket.bind</tt></a>
|
||||
is available and is a shortcut for the creation of server sockets.
|
||||
</p>
|
||||
|
||||
<!-- close ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=close>
|
||||
master:<b>close()</b><br>
|
||||
client:<b>close()</b><br>
|
||||
server:<b>close()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Closes a TCP object. The internal socket used by the object is closed
|
||||
and the local address to which the object was
|
||||
bound is made available to other applications. No further operations
|
||||
(except for further calls to the <tt>close</tt> method) are allowed on
|
||||
a closed socket.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: It is important to close all used sockets once they are not
|
||||
needed, since, in many systems, each socket uses a file descriptor,
|
||||
which are limited system resources. Garbage-collected objects are
|
||||
automatically closed before destruction, though.
|
||||
</p>
|
||||
|
||||
<!-- connect ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=connect>
|
||||
master:<b>connect(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Attempts to connect a master object to a remote host, transforming it into a
|
||||
client object.
|
||||
Client objects support methods
|
||||
<a href=#send><tt>send</tt></a>,
|
||||
<a href=#receive><tt>receive</tt></a>,
|
||||
<a href=#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=#getpeername><tt>getpeername</tt></a>,
|
||||
<a href=#settimeout><tt>settimeout</tt></a>,
|
||||
and <a href=#close><tt>close</tt></a>.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Address</tt> can be an IP address or a host name.
|
||||
<tt>Port</tt> must be an integer number in the range [1..64K).
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
In case of error, the method returns <b><tt>nil</tt></b> followed by a string
|
||||
describing the error. In case of success, the method returns 1.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The function <a href=socket.html#connect><tt>socket.connect</tt></a>
|
||||
is available and is a shortcut for the creation of client sockets.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: Starting with LuaSocket 2.0,
|
||||
the <a href=#settimeout><tt>settimeout</tt></a>
|
||||
method affects the behavior of <tt>connect</tt>, causing it to return
|
||||
with an error in case of a timeout. If that happens, you can still call <a
|
||||
href=socket.html#select><tt>socket.select</tt></a> with the socket in the
|
||||
<tt>sendt</tt> table. The socket will be writable when the connection is
|
||||
established.
|
||||
</p>
|
||||
|
||||
<!-- getpeername ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=getpeername>
|
||||
client:<b>getpeername()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns information about the remote side of a connected client object.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Returns a string with the IP address of the peer, followed by the
|
||||
port number that peer is using for the connection.
|
||||
In case of error, the method returns <b><tt>nil</tt></b>.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: It makes no sense to call this method on server objects.
|
||||
</p>
|
||||
|
||||
<!-- getsockname ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=getsockname>
|
||||
master:<b>getsockname()</b><br>
|
||||
client:<b>getsockname()</b><br>
|
||||
server:<b>getsockname()</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns the local address information associated to the object.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The method returns a string with local IP address and a number with
|
||||
the port. In case of error, the method returns <b><tt>nil</tt></b>.
|
||||
</p>
|
||||
|
||||
<!-- getstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=getstats>
|
||||
master:<b>getstats()</b><br>
|
||||
client:<b>getstats()</b><br>
|
||||
server:<b>getstats()</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Returns accounting information on the socket, useful for throttling
|
||||
of bandwidth.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The method returns the number of bytes received, the number of bytes sent,
|
||||
and the age of the socket object in seconds.
|
||||
</p>
|
||||
|
||||
<!-- listen ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=listen>
|
||||
master:<b>listen(</b>backlog<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Specifies the socket is willing to receive connections, transforming the
|
||||
object into a server object. Server objects support the
|
||||
<a href=#accept><tt>accept</tt></a>,
|
||||
<a href=#getsockname><tt>getsockname</tt></a>,
|
||||
<a href=#setoption><tt>setoption</tt></a>,
|
||||
<a href=#settimeout><tt>settimeout</tt></a>,
|
||||
and <a href=#close><tt>close</tt></a> methods.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
The parameter <tt>backlog</tt> specifies the number of client
|
||||
connections that can
|
||||
be queued waiting for service. If the queue is full and another client
|
||||
attempts connection, the connection is refused.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
In case of success, the method returns 1. In case of error, the
|
||||
method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<!-- receive ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=receive>
|
||||
client:<b>receive(</b>[pattern [, prefix]]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Reads data from a client object, according to the specified <em>read
|
||||
pattern</em>. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Pattern</tt> can be any of the following:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> '<tt>*a</tt>': reads from the socket until the connection is
|
||||
closed. No end-of-line translation is performed;
|
||||
<li> '<tt>*l</tt>': reads a line of text from the socket. The line is
|
||||
terminated by a LF character (ASCII 10), optionally preceded by a
|
||||
CR character (ASCII 13). The CR and LF characters are not included in
|
||||
the returned line. In fact, <em>all</em> CR characters are
|
||||
ignored by the pattern. This is the default pattern;
|
||||
<li> <tt>number</tt>: causes the method to read a specified <tt>number</tt>
|
||||
of bytes from the socket.
|
||||
</ul>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Prefix</tt> is an optional string to be concatenated to the beginning
|
||||
of any received data before return.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
If successful, the method returns the received pattern. In case of error,
|
||||
the method returns <tt><b>nil</b></tt> followed by an error message which
|
||||
can be the string '<tt>closed</tt>' in case the connection was
|
||||
closed before the transmission was completed or the string
|
||||
'<tt>timeout</tt>' in case there was a timeout during the operation.
|
||||
Also, after the error message, the function returns the partial result of
|
||||
the transmission.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
<b>Important note</b>: This function was changed <em>severely</em>. It used
|
||||
to support multiple patterns (but I have never seen this feature used) and
|
||||
now it doesn't anymore. Partial results used to be returned in the same
|
||||
way as successful results. This last feature violated the idea that all
|
||||
functions should return <tt><b>nil</b></tt> on error. Thus it was changed
|
||||
too.
|
||||
</p>
|
||||
|
||||
<!-- send +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=send>
|
||||
client:<b>send(</b>data [, i [, j]]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Sends <tt>data</tt> through client object.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Data</tt> is the string to be sent. The optional arguments
|
||||
<tt>i</tt> and <tt>j</tt> work exactly like the standard
|
||||
<tt>string.sub</tt> Lua function to allow the selection of a
|
||||
substring to be sent.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
If successful, the method returns the index of the last byte
|
||||
within <tt>[i, j]</tt> that has been sent. Notice that, if
|
||||
<tt>i</tt> is 1 or absent, this is effectively the total
|
||||
number of bytes sent. In case of error, the method returns
|
||||
<b><tt>nil</tt></b>, followed by an error message, followed
|
||||
by the index of the last byte within <tt>[i, j]</tt> that
|
||||
has been sent. You might want to try again from the byte
|
||||
following that. The error message can be '<tt>closed</tt>'
|
||||
in case the connection was closed before the transmission
|
||||
was completed or the string '<tt>timeout</tt>' in case
|
||||
there was a timeout during the operation.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: Output is <em>not</em> buffered. For small strings,
|
||||
it is always better to concatenate them in Lua
|
||||
(with the '<tt>..</tt>' operator) and send the result in one call
|
||||
instead of calling the method several times.
|
||||
</p>
|
||||
|
||||
<!-- setoption ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=setoption>
|
||||
client:<b>setoption(</b>option [, value]<b>)</b><br>
|
||||
server:<b>setoption(</b>option [, value]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Sets options for the TCP object. Options are only needed by low-level or
|
||||
time-critical applications. You should only modify an option if you
|
||||
are sure you need it.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Option</tt> is a string with the option name, and <tt>value</tt>
|
||||
depends on the option being set:
|
||||
|
||||
<ul>
|
||||
|
||||
<li> '<tt>keepalive</tt>': Setting this option to <tt>true</tt> enables
|
||||
the periodic transmission of messages on a connected socket. Should the
|
||||
connected party fail to respond to these messages, the connection is
|
||||
considered broken and processes using the socket are notified;
|
||||
|
||||
<li> '<tt>linger</tt>': Controls the action taken when unsent data are
|
||||
queued on a socket and a close is performed. The value is a table with a
|
||||
boolean entry '<tt>on</tt>' and a numeric entry for the time interval
|
||||
'<tt>timeout</tt>' in seconds. If the '<tt>on</tt>' field is set to
|
||||
<tt>true</tt>, the system will block the process on the close attempt until
|
||||
it is able to transmit the data or until '<tt>timeout</tt>' has passed. If
|
||||
'<tt>on</tt>' is <tt>false</tt> and a close is issued, the system will
|
||||
process the close in a manner that allows the process to continue as
|
||||
quickly as possible. I do not advise you to set this to anything other than
|
||||
zero;
|
||||
|
||||
<li> '<tt>reuseaddr</tt>': Setting this option indicates that the rules
|
||||
used in validating addresses supplied in a call to
|
||||
<a href=#bind><tt>bind</tt></a> should allow reuse of local addresses;
|
||||
|
||||
<li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt>
|
||||
disables the Nagle's algorithm for the connection.
|
||||
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
The method returns 1 in case of success, or <b><tt>nil</tt></b> otherwise.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The descriptions above come from the man pages.
|
||||
</p>
|
||||
|
||||
<!-- setstats +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=setstats>
|
||||
master:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
client:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
server:<b>setstats(</b>received, sent, age<b>)</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Resets accounting information on the socket, useful for throttling
|
||||
of bandwidth.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Received</tt> is a number with the new number of bytes received.
|
||||
<tt>Sent</tt> is a number with the new number of bytes sent.
|
||||
<tt>Age</tt> is the new age in seconds.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The method returns 1 in case of success and <tt><b>nil</b></tt> otherwise.
|
||||
</p>
|
||||
|
||||
<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=settimeout>
|
||||
master:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
||||
client:<b>settimeout(</b>value [, mode]<b>)</b><br>
|
||||
server:<b>settimeout(</b>value [, mode]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Changes the timeout values for the object. By default,
|
||||
all I/O operations are blocking. That is, any call to the methods
|
||||
<a href=#send><tt>send</tt></a>,
|
||||
<a href=#receive><tt>receive</tt></a>, and
|
||||
<a href=#accept><tt>accept</tt></a>
|
||||
will block indefinitely, until the operation completes. The
|
||||
<tt>settimeout</tt> method defines a limit on the amount of time the
|
||||
I/O methods can block. When a timeout is set and the specified amount of
|
||||
time has elapsed, the affected methods give up and fail with an error code.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
The amount of time to wait is specified as the
|
||||
<tt>value</tt> parameter, in seconds. There are two timeout modes and
|
||||
both can be used together for fine tuning:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li> '<tt>b</tt>': <em>block</em> timeout. Specifies the upper limit on
|
||||
the amount of time LuaSocket can be blocked by the operating system
|
||||
while waiting for completion of any single I/O operation. This is the
|
||||
default mode;</li>
|
||||
|
||||
<li> '<tt>t</tt>': <em>total</em> timeout. Specifies the upper limit on
|
||||
the amount of time LuaSocket can block a Lua script before returning from
|
||||
a call.</li>
|
||||
</ul>
|
||||
|
||||
<p class=parameters>
|
||||
The <b><tt>nil</tt></b> timeout <tt>value</tt> allows operations to block
|
||||
indefinitely. Negative timeout values have the same effect.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: although timeout values have millisecond precision in LuaSocket,
|
||||
large blocks can cause I/O functions not to respect timeout values due
|
||||
to the time the library takes to transfer blocks to and from the OS
|
||||
and to and from the Lua interpreter. Also, function that accept host names
|
||||
and perform automatic name resolution might be blocked by the resolver for
|
||||
longer than the specified timeout value.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The old <tt>timeout</tt> method is deprecated. The name has been
|
||||
changed for sake of uniformity, since all other method names already
|
||||
contained verbs making their imperative nature obvious.
|
||||
</p>
|
||||
|
||||
<!-- shutdown +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=shutdown>
|
||||
client:<b>shutdown(</b>mode<b>)</b><br>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Shuts down part of a full-duplex connection.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
Mode tells which way of the connection should be shut down and can
|
||||
take the value:
|
||||
<ul>
|
||||
<li>"<tt>both</tt>": disallow further sends and receives on the object.
|
||||
This is the default mode;
|
||||
<li>"<tt>send</tt>": disallow further sends on the object;
|
||||
<li>"<tt>receive</tt>": disallow further receives on the object.
|
||||
</ul>
|
||||
|
||||
<p class=return>
|
||||
This function returns 1.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:25:57 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
416
cosmic rage/docs/LuaSocket_documentation/udp.html
Normal file
416
cosmic rage/docs/LuaSocket_documentation/udp.html
Normal file
@@ -0,0 +1,416 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: The UDP support">
|
||||
<meta name="keywords" content="Lua, LuaSocket, Socket, UDP, Library, Network, Support">
|
||||
<title>LuaSocket: UDP support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=udp>UDP</h2>
|
||||
|
||||
<!-- socket.udp ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="socket.udp">
|
||||
socket.<b>udp()</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Creates and returns an unconnected UDP object. Unconnected objects support the
|
||||
<a href="#sendto"><tt>sendto</tt></a>,
|
||||
<a href="#receive"><tt>receive</tt></a>,
|
||||
<a href="#receivefrom"><tt>receivefrom</tt></a>,
|
||||
<a href="#getsockname"><tt>getsockname</tt></a>,
|
||||
<a href="#setoption"><tt>setoption</tt></a>,
|
||||
<a href="#settimeout"><tt>settimeout</tt></a>,
|
||||
<a href="#setpeername"><tt>setpeername</tt></a>,
|
||||
<a href="#setsockname"><tt>setsockname</tt></a>, and
|
||||
<a href="#close"><tt>close</tt></a>.
|
||||
The <a href="#setpeername"><tt>setpeername</tt></a>
|
||||
is used to connect the object.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
In case of success, a new unconnected UDP object
|
||||
returned. In case of error, <b><tt>nil</tt></b> is returned, followed by
|
||||
an error message.
|
||||
</p>
|
||||
|
||||
<!-- close +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="close">
|
||||
connected:<b>close()</b><br>
|
||||
unconnected:<b>close()</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Closes a UDP object. The internal socket
|
||||
used by the object is closed and the local address to which the
|
||||
object was bound is made available to other applications. No
|
||||
further operations (except for further calls to the <tt>close</tt>
|
||||
method) are allowed on a closed socket.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: It is important to close all used sockets
|
||||
once they are not needed, since, in many systems, each socket uses
|
||||
a file descriptor, which are limited system resources.
|
||||
Garbage-collected objects are automatically closed before
|
||||
destruction, though.
|
||||
</p>
|
||||
|
||||
<!-- getpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="getpeername">
|
||||
connected:<b>getpeername()</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Retrieves information about the peer
|
||||
associated with a connected UDP object.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
Returns the IP address and port number of the peer.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: It makes no sense to call this method on unconnected objects.
|
||||
</p>
|
||||
|
||||
<!-- getsockname +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="getsockname">
|
||||
connected:<b>getsockname()</b><br>
|
||||
unconnected:<b>getsockname()</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Returns the local address information associated to the object.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
The method returns a string with local IP
|
||||
address and a number with the port. In case of error, the method
|
||||
returns <b><tt>nil</tt></b>.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: UDP sockets are not bound to any address
|
||||
until the <a href="#setsockname"><tt>setsockname</tt></a> or the
|
||||
<a href="#sendto"><tt>sendto</tt></a> method is called for the
|
||||
first time (in which case it is bound to an ephemeral port and the
|
||||
wild-card address).
|
||||
</p>
|
||||
|
||||
<!-- receive +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="receive">
|
||||
connected:<b>receive(</b>[size]<b>)</b><br>
|
||||
unconnected:<b>receive(</b>[size]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Receives a datagram from the UDP object. If
|
||||
the UDP object is connected, only datagrams coming from the peer
|
||||
are accepted. Otherwise, the returned datagram can come from any
|
||||
host.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
The optional <tt>size</tt> parameter
|
||||
specifies the maximum size of the datagram to be retrieved. If
|
||||
there are more than <tt>size</tt> bytes available in the datagram,
|
||||
the excess bytes are discarded. If there are less then
|
||||
<tt>size</tt> bytes available in the current datagram, the
|
||||
available bytes are returned. If <tt>size</tt> is omitted, the
|
||||
maximum datagram size is used (which is currently limited by the
|
||||
implementation to 8192 bytes).
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
In case of success, the method returns the
|
||||
received datagram. In case of timeout, the method returns
|
||||
<b><tt>nil</tt></b> followed by the string '<tt>timeout</tt>'.
|
||||
</p>
|
||||
|
||||
<!-- receivefrom +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="receivefrom">
|
||||
unconnected:<b>receivefrom(</b>[size]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Works exactly as the <a href="#receive"><tt>receive</tt></a>
|
||||
method, except it returns the IP
|
||||
address and port as extra return values (and is therefore slightly less
|
||||
efficient).
|
||||
</p>
|
||||
|
||||
<!-- send ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="send">
|
||||
connected:<b>send(</b>datagram<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Sends a datagram to the UDP peer of a connected object.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
<tt>Datagram</tt> is a string with the datagram contents.
|
||||
The maximum datagram size for UDP is 64K minus IP layer overhead.
|
||||
However datagrams larger than the link layer packet size will be
|
||||
fragmented, which may deteriorate performance and/or reliability.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
If successful, the method returns 1. In case of
|
||||
error, the method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: In UDP, the <tt>send</tt> method never blocks
|
||||
and the only way it can fail is if the underlying transport layer
|
||||
refuses to send a message to the specified address (i.e. no
|
||||
interface accepts the address).
|
||||
</p>
|
||||
|
||||
<!-- sendto ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="sendto">
|
||||
unconnected:<b>sendto(</b>datagram, ip, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Sends a datagram to the specified IP address and port number.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
<tt>Datagram</tt> is a string with the
|
||||
datagram contents.
|
||||
The maximum datagram size for UDP is 64K minus IP layer overhead.
|
||||
However datagrams larger than the link layer packet size will be
|
||||
fragmented, which may deteriorate performance and/or reliability.
|
||||
<tt>Ip</tt> is the IP address of the recipient.
|
||||
Host names are <em>not</em> allowed for performance reasons.
|
||||
|
||||
<tt>Port</tt> is the port number at the recipient.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
If successful, the method returns 1. In case of
|
||||
error, the method returns <b><tt>nil</tt></b> followed by an error message.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: In UDP, the <tt>send</tt> method never blocks
|
||||
and the only way it can fail is if the underlying transport layer
|
||||
refuses to send a message to the specified address (i.e. no
|
||||
interface accepts the address).
|
||||
</p>
|
||||
|
||||
<!-- setpeername +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="setpeername">
|
||||
connected:<b>setpeername(</b>'*'<b>)</b><br>
|
||||
unconnected:<b>setpeername(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Changes the peer of a UDP object. This
|
||||
method turns an unconnected UDP object into a connected UDP
|
||||
object or vice versa.
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
For connected objects, outgoing datagrams
|
||||
will be sent to the specified peer, and datagrams received from
|
||||
other peers will be discarded by the OS. Connected UDP objects must
|
||||
use the <a href="#send"><tt>send</tt></a> and
|
||||
<a href="#receive"><tt>receive</tt></a> methods instead of
|
||||
<a href="#sendto"><tt>sendto</tt></a> and
|
||||
<a href="#receivefrom"><tt>receivefrom</tt></a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or a
|
||||
host name. <tt>Port</tt> is the port number. If <tt>address</tt> is
|
||||
'<tt>*</tt>' and the object is connected, the peer association is
|
||||
removed and the object becomes an unconnected object again. In that
|
||||
case, the <tt>port</tt> argument is ignored.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
In case of error the method returns
|
||||
<b><tt>nil</tt></b> followed by an error message. In case of success, the
|
||||
method returns 1.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: Since the address of the peer does not have
|
||||
to be passed to and from the OS, the use of connected UDP objects
|
||||
is recommended when the same peer is used for several transmissions
|
||||
and can result in up to 30% performance gains.
|
||||
</p>
|
||||
|
||||
<!-- setsockname +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="setsockname">
|
||||
unconnected:<b>setsockname(</b>address, port<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Binds the UDP object to a local address.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
<tt>Address</tt> can be an IP address or a
|
||||
host name. If <tt>address</tt> is '<tt>*</tt>' the system binds to
|
||||
all local interfaces using the constant <tt>INADDR_ANY</tt>. If
|
||||
<tt>port</tt> is 0, the system chooses an ephemeral port.
|
||||
</p>
|
||||
|
||||
<p class="return">
|
||||
If successful, the method returns 1. In case of
|
||||
error, the method returns <b><tt>nil</tt></b> followed by an error
|
||||
message.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: This method can only be called before any
|
||||
datagram is sent through the UDP object, and only once. Otherwise,
|
||||
the system automatically binds the object to all local interfaces
|
||||
and chooses an ephemeral port as soon as the first datagram is
|
||||
sent. After the local address is set, either automatically by the
|
||||
system or explicitly by <tt>setsockname</tt>, it cannot be
|
||||
changed.
|
||||
</p>
|
||||
|
||||
<!-- setoption +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="setoption">
|
||||
connected:<b>setoption(</b>option [, value]<b>)</b><br>
|
||||
unconnected:<b>setoption(</b>option [, value]<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Sets options for the UDP object. Options are
|
||||
only needed by low-level or time-critical applications. You should
|
||||
only modify an option if you are sure you need it.</p>
|
||||
<p class="parameters"><tt>Option</tt> is a string with the option
|
||||
name, and <tt>value</tt> depends on the option being set:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li>'<tt>dontroute</tt>': Setting this option to <tt>true</tt>
|
||||
indicates that outgoing messages should bypass the standard routing
|
||||
facilities;</li>
|
||||
<li>'<tt>broadcast</tt>': Setting this option to <tt>true</tt>
|
||||
requests permission to send broadcast datagrams on the
|
||||
socket.</li>
|
||||
</ul>
|
||||
|
||||
<p class="return">
|
||||
The method returns 1 in case of success, or
|
||||
<b><tt>nil</tt></b> followed by an error message otherwise.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: The descriptions above come from the man
|
||||
pages.
|
||||
</p>
|
||||
|
||||
<!-- settimeout +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class="name" id="settimeout">
|
||||
connected:<b>settimeout(</b>value<b>)</b><br>
|
||||
unconnected:<b>settimeout(</b>value<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class="description">
|
||||
Changes the timeout values for the object. By default, the
|
||||
<a href="#receive"><tt>receive</tt></a> and
|
||||
<a href="#receivefrom"><tt>receivefrom</tt></a>
|
||||
operations are blocking. That is, any call to the methods will block
|
||||
indefinitely, until data arrives. The <tt>settimeout</tt> function defines
|
||||
a limit on the amount of time the functions can block. When a timeout is
|
||||
set and the specified amount of time has elapsed, the affected methods
|
||||
give up and fail with an error code.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
The amount of time to wait is specified as
|
||||
the <tt>value</tt> parameter, in seconds. The <b><tt>nil</tt></b> timeout
|
||||
<tt>value</tt> allows operations to block indefinitely. Negative
|
||||
timeout values have the same effect.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: In UDP, the <a href="#send"><tt>send</tt></a>
|
||||
and <a href="#sentdo"><tt>sendto</tt></a> methods never block (the
|
||||
datagram is just passed to the OS and the call returns
|
||||
immediately). Therefore, the <tt>settimeout</tt> method has no
|
||||
effect on them.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Note: The old <tt>timeout</tt> method is
|
||||
deprecated. The name has been changed for sake of uniformity, since
|
||||
all other method names already contained verbs making their
|
||||
imperative nature obvious.
|
||||
</p>
|
||||
|
||||
<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:26:01 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
329
cosmic rage/docs/LuaSocket_documentation/url.html
Normal file
329
cosmic rage/docs/LuaSocket_documentation/url.html
Normal file
@@ -0,0 +1,329 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="description" content="LuaSocket: URL manipulation">
|
||||
<meta name="keywords" content="Lua, LuaSocket, URL, Library, Link, Network, Support">
|
||||
<title>LuaSocket: URL support</title>
|
||||
<link rel="stylesheet" href="reference.css" type="text/css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=header>
|
||||
<hr>
|
||||
<center>
|
||||
<table summary="LuaSocket logo">
|
||||
<tr><td align=center><a href="http://www.lua.org">
|
||||
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
|
||||
</a></td></tr>
|
||||
<tr><td align=center valign=top>Network support for the Lua language
|
||||
</td></tr>
|
||||
</table>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#download">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
</center>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<!-- url ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<h2 id=url>URL</h2>
|
||||
|
||||
<p>
|
||||
The <tt>url</tt> namespace provides functions to parse, protect,
|
||||
and build URLs, as well as functions to compose absolute URLs
|
||||
from base and relative URLs, according to
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC
|
||||
2396</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
To obtain the <tt>url</tt> namespace, run:
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- loads the URL module
|
||||
local url = require("socket.url")
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
An URL is defined by the following grammar:
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<tt>
|
||||
<url> ::= [<scheme>:][//<authority>][/<path>][;<params>][?<query>][#<fragment>]<br>
|
||||
<authority> ::= [<userinfo>@]<host>[:<port>]<br>
|
||||
<userinfo> ::= <user>[:<password>]<br>
|
||||
<path> ::= {<segment>/}<segment><br>
|
||||
</tt>
|
||||
</blockquote>
|
||||
|
||||
<!-- absolute +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=absolute>
|
||||
url.<b>absolute(</b>base, relative<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Builds an absolute URL from a base URL and a relative URL.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Base</tt> is a string with the base URL or
|
||||
a parsed URL table. <tt>Relative</tt> is a
|
||||
string with the relative URL.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a string with the absolute URL.
|
||||
</p>
|
||||
|
||||
<p class=note>
|
||||
Note: The rules that
|
||||
govern the composition are fairly complex, and are described in detail in
|
||||
<a href="http://www.cs.princeton.edu/~diego/rfc/rfc2396.txt">RFC 2396</a>.
|
||||
The example bellow should give an idea of what the rules are.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
http://a/b/c/d;p?q
|
||||
|
||||
+
|
||||
|
||||
g:h = g:h
|
||||
g = http://a/b/c/g
|
||||
./g = http://a/b/c/g
|
||||
g/ = http://a/b/c/g/
|
||||
/g = http://a/g
|
||||
//g = http://g
|
||||
?y = http://a/b/c/?y
|
||||
g?y = http://a/b/c/g?y
|
||||
#s = http://a/b/c/d;p?q#s
|
||||
g#s = http://a/b/c/g#s
|
||||
g?y#s = http://a/b/c/g?y#s
|
||||
;x = http://a/b/c/;x
|
||||
g;x = http://a/b/c/g;x
|
||||
g;x?y#s = http://a/b/c/g;x?y#s
|
||||
. = http://a/b/c/
|
||||
./ = http://a/b/c/
|
||||
.. = http://a/b/
|
||||
../ = http://a/b/
|
||||
../g = http://a/b/g
|
||||
../.. = http://a/
|
||||
../../ = http://a/
|
||||
../../g = http://a/g
|
||||
</pre>
|
||||
|
||||
<!-- build ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=build>
|
||||
url.<b>build(</b>parsed_url<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Rebuilds an URL from its parts.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Parsed_url</tt> is a table with same components returned by
|
||||
<a href="#parse"><tt>parse</tt></a>.
|
||||
Lower level components, if specified,
|
||||
take precedence over high level components of the URL grammar.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a string with the built URL.
|
||||
</p>
|
||||
|
||||
<!-- build_path +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=build_path>
|
||||
url.<b>build_path(</b>segments, unsafe<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Builds a <tt><path></tt> component from a list of
|
||||
<tt><segment></tt> parts.
|
||||
Before composition, any reserved characters found in a segment are escaped into
|
||||
their protected form, so that the resulting path is a valid URL path
|
||||
component.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Segments</tt> is a list of strings with the <tt><segment></tt>
|
||||
parts. If <tt>unsafe</tt> is anything but <b><tt>nil</tt></b>, reserved
|
||||
characters are left untouched.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a string with the
|
||||
built <tt><path></tt> component.
|
||||
</p>
|
||||
|
||||
<!-- escape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="escape">
|
||||
url.<b>escape(</b>content<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Applies the URL escaping content coding to a string
|
||||
Each byte is encoded as a percent character followed
|
||||
by the two byte hexadecimal representation of its integer
|
||||
value.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Content</tt> is the string to be encoded.
|
||||
</p>
|
||||
|
||||
<p class=result>
|
||||
The function returns the encoded string.
|
||||
</p>
|
||||
|
||||
<pre class=example>
|
||||
-- load url module
|
||||
url = require("socket.url")
|
||||
|
||||
code = url.escape("/#?;")
|
||||
-- code = "%2f%23%3f%3b"
|
||||
</pre>
|
||||
|
||||
<!-- parse ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=parse>
|
||||
url.<b>parse(</b>url, default<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Parses an URL given as a string into a Lua table with its components.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Url</tt> is the URL to be parsed. If the <tt>default</tt> table is
|
||||
present, it is used to store the parsed fields. Only fields present in the
|
||||
URL are overwritten. Therefore, this table can be used to pass default
|
||||
values for each field.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns a table with all the URL components:
|
||||
</p>
|
||||
|
||||
<blockquote><tt>
|
||||
parsed_url = {<br>
|
||||
url = <i>string</i>,<br>
|
||||
scheme = <i>string</i>,<br>
|
||||
authority = <i>string</i>,<br>
|
||||
path = <i>string</i>,<br>
|
||||
params = <i>string</i>,<br>
|
||||
query = <i>string</i>,<br>
|
||||
fragment = <i>string</i>,<br>
|
||||
userinfo = <i>string</i>,<br>
|
||||
host = <i>string</i>,<br>
|
||||
port = <i>string</i>,<br>
|
||||
user = <i>string</i>,<br>
|
||||
password = <i>string</i><br>
|
||||
}
|
||||
</tt></blockquote>
|
||||
|
||||
<pre class=example>
|
||||
-- load url module
|
||||
url = require("socket.url")
|
||||
|
||||
parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
|
||||
-- parsed_url = {
|
||||
-- scheme = "http",
|
||||
-- authority = "www.example.com",
|
||||
-- path = "/cgilua/index.lua"
|
||||
-- query = "a=2",
|
||||
-- fragment = "there",
|
||||
-- host = "www.puc-rio.br",
|
||||
-- }
|
||||
|
||||
parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i")
|
||||
-- parsed_url = {
|
||||
-- scheme = "ftp",
|
||||
-- authority = "root:passwd@unsafe.org",
|
||||
-- path = "/pub/virus.exe",
|
||||
-- params = "type=i",
|
||||
-- userinfo = "root:passwd",
|
||||
-- host = "unsafe.org",
|
||||
-- user = "root",
|
||||
-- password = "passwd",
|
||||
-- }
|
||||
</pre>
|
||||
|
||||
<!-- parse_path +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id=parse_path>
|
||||
url.<b>parse_path(</b>path<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Breaks a <tt><path></tt> URL component into all its
|
||||
<tt><segment></tt> parts.
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
<tt>Path</tt> is a string with the path to be parsed.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
Since some characters are reserved in URLs, they must be escaped
|
||||
whenever present in a <tt><path></tt> component. Therefore, before
|
||||
returning a list with all the parsed segments, the function removes
|
||||
escaping from all of them.
|
||||
</p>
|
||||
|
||||
<!-- unescape +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<p class=name id="unescape">
|
||||
url.<b>unescape(</b>content<b>)</b>
|
||||
</p>
|
||||
|
||||
<p class=description>
|
||||
Removes the URL escaping content coding from a string.
|
||||
</p>
|
||||
|
||||
<p class=parameters>
|
||||
<tt>Content</tt> is the string to be decoded.
|
||||
</p>
|
||||
|
||||
<p class=return>
|
||||
The function returns the decoded string.
|
||||
</p>
|
||||
|
||||
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
|
||||
<div class=footer>
|
||||
<hr>
|
||||
<center>
|
||||
<p class=bar>
|
||||
<a href="home.html">home</a> ·
|
||||
<a href="home.html#down">download</a> ·
|
||||
<a href="installation.html">installation</a> ·
|
||||
<a href="introduction.html">introduction</a> ·
|
||||
<a href="reference.html">reference</a>
|
||||
</p>
|
||||
<p>
|
||||
<small>
|
||||
Last modified by Diego Nehab on <br>
|
||||
Thu Apr 20 00:26:05 EDT 2006
|
||||
</small>
|
||||
</p>
|
||||
</center>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
21
cosmic rage/docs/LuaSocket_license.txt
Normal file
21
cosmic rage/docs/LuaSocket_license.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
LuaSocket 2.0.2 license
|
||||
Copyright <20> 2004-2007 Diego Nehab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
2552
cosmic rage/docs/PCRE_ChangeLog.txt
Normal file
2552
cosmic rage/docs/PCRE_ChangeLog.txt
Normal file
File diff suppressed because it is too large
Load Diff
1996
cosmic rage/docs/RegularExpressions.txt
Normal file
1996
cosmic rage/docs/RegularExpressions.txt
Normal file
File diff suppressed because it is too large
Load Diff
339
cosmic rage/docs/gpl.txt
Normal file
339
cosmic rage/docs/gpl.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
BIN
cosmic rage/docs/lpeg-128.gif
Normal file
BIN
cosmic rage/docs/lpeg-128.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 KiB |
1423
cosmic rage/docs/lpeg.html
Normal file
1423
cosmic rage/docs/lpeg.html
Normal file
File diff suppressed because it is too large
Load Diff
860
cosmic rage/docs/lsqlite3.html
Normal file
860
cosmic rage/docs/lsqlite3.html
Normal file
@@ -0,0 +1,860 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>LuaSQLite 3</TITLE>
|
||||
<LINK REV="made" HREF="mailto:unknown@du216771.users">
|
||||
</HEAD>
|
||||
|
||||
<BODY>
|
||||
|
||||
<A NAME="__index__"></A>
|
||||
<!-- INDEX BEGIN -->
|
||||
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#name">NAME</A></LI>
|
||||
<LI><A HREF="#overview">OVERVIEW</A></LI>
|
||||
<LI><A HREF="#reference">REFERENCE</A></LI>
|
||||
<LI><A HREF="#sqlite3 functions">SQLite3 functions</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#sqlite3.complete">sqlite3.complete</A></LI>
|
||||
<LI><A HREF="#sqlite3.open">sqlite3.open</A></LI>
|
||||
<LI><A HREF="#sqlite3.open_memory">sqlite3.open_memory</A></LI>
|
||||
<LI><A HREF="#sqlite3.temp_directory">sqlite3.temp_directory</A></LI>
|
||||
<LI><A HREF="#sqlite3.version">sqlite3.version</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#database methods">Database methods</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#db:busy_handler">db:busy_handler</A></LI>
|
||||
<LI><A HREF="#db:busy_timeout">db:busy_timeout</A></LI>
|
||||
<LI><A HREF="#db:changes">db:changes</A></LI>
|
||||
<LI><A HREF="#db:close">db:close</A></LI>
|
||||
<LI><A HREF="#db:close_vm">db:close_vm</A></LI>
|
||||
<LI><A HREF="#db:create_aggregate">db:create_aggregate</A></LI>
|
||||
<LI><A HREF="#db:create_collation">db:create_collation</A></LI>
|
||||
<LI><A HREF="#db:create_function">db:create_function</A></LI>
|
||||
<LI><A HREF="#db:errcode">db:errcode</A></LI>
|
||||
<LI><A HREF="#db:errmsg">db:errmsg</A></LI>
|
||||
<LI><A HREF="#db:exec">db:exec</A></LI>
|
||||
<LI><A HREF="#db:interrupt">db:interrupt</A></LI>
|
||||
<LI><A HREF="#db:isopen">db:isopen</A></LI>
|
||||
<LI><A HREF="#db:last_insert_rowid">db:last_insert_rowid</A></LI>
|
||||
<LI><A HREF="#db:nrows">db:nrows</A></LI>
|
||||
<LI><A HREF="#db:prepare">db:prepare</A></LI>
|
||||
<LI><A HREF="#db:progress_handler">db:progress_handler</A></LI>
|
||||
<LI><A HREF="#db:rows">db:rows</A></LI>
|
||||
<LI><A HREF="#db:total_changes">db:total_changes</A></LI>
|
||||
<LI><A HREF="#db:trace">db:trace</A></LI>
|
||||
<LI><A HREF="#db:urows">db:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for prepared statements">Methods for prepared statements</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#stmt:bind">stmt:bind</A></LI>
|
||||
<LI><A HREF="#stmt:bind_blob">stmt:bind_blob</A></LI>
|
||||
<LI><A HREF="#stmt:bind_names">stmt:bind_names</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_count">stmt:bind_parameter_count</A></LI>
|
||||
<LI><A HREF="#stmt:bind_parameter_name">stmt:bind_parameter_name</A></LI>
|
||||
<LI><A HREF="#stmt:bind_values">stmt:bind_values</A></LI>
|
||||
<LI><A HREF="#stmt:columns">stmt:columns</A></LI>
|
||||
<LI><A HREF="#stmt:finalize">stmt:finalize</A></LI>
|
||||
<LI><A HREF="#stmt:get_name">stmt:get_name</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_types">stmt:get_named_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_named_values">stmt:get_named_values</A></LI>
|
||||
<LI><A HREF="#stmt:get_names">stmt:get_names</A></LI>
|
||||
<LI><A HREF="#stmt:get_type">stmt:get_type</A></LI>
|
||||
<LI><A HREF="#stmt:get_types">stmt:get_types</A></LI>
|
||||
<LI><A HREF="#stmt:get_unames">stmt:get_unames</A></LI>
|
||||
<LI><A HREF="#stmt:get_utypes">stmt:get_utypes</A></LI>
|
||||
<LI><A HREF="#stmt:get_uvalues">stmt:get_uvalues</A></LI>
|
||||
<LI><A HREF="#stmt:get_value">stmt:get_value</A></LI>
|
||||
<LI><A HREF="#stmt:get_values">stmt:get_values</A></LI>
|
||||
<LI><A HREF="#stmt:isopen">stmt:isopen</A></LI>
|
||||
<LI><A HREF="#stmt:nrows">stmt:nrows</A></LI>
|
||||
<LI><A HREF="#stmt:reset">stmt:reset</A></LI>
|
||||
<LI><A HREF="#stmt:rows">stmt:rows</A></LI>
|
||||
<LI><A HREF="#stmt:step">stmt:step</A></LI>
|
||||
<LI><A HREF="#stmt:urows">stmt:urows</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#methods for callback contexts">Methods for callback contexts</A></LI>
|
||||
<UL>
|
||||
|
||||
<LI><A HREF="#context:aggregate_count">context:aggregate_count</A></LI>
|
||||
<LI><A HREF="#context:get_aggregate_data">context:get_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:set_aggregate_data">context:set_aggregate_data</A></LI>
|
||||
<LI><A HREF="#context:result">context:result</A></LI>
|
||||
<LI><A HREF="#context:result_null">context:result_null</A></LI>
|
||||
<LI><A HREF="#context:result_number">context:result_number</A></LI>
|
||||
<LI><A HREF="#context:result_int">context:result_int</A></LI>
|
||||
<LI><A HREF="#context:result_text">context:result_text</A></LI>
|
||||
<LI><A HREF="#context:result_blob">context:result_blob</A></LI>
|
||||
<LI><A HREF="#context:result_error">context:result_error</A></LI>
|
||||
<LI><A HREF="#context:user_data">context:user_data</A></LI>
|
||||
</UL>
|
||||
|
||||
<LI><A HREF="#numerical error and result codes">Numerical error and result codes</A></LI>
|
||||
<LI><A HREF="#version">VERSION</A></LI>
|
||||
<LI><A HREF="#credits">CREDITS</A></LI>
|
||||
<LI><A HREF="#license">LICENSE</A></LI>
|
||||
</UL>
|
||||
<!-- INDEX END -->
|
||||
|
||||
<HR>
|
||||
<H1><A NAME="name">NAME</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> - a Lua 5.1 wrapper for the SQLite3 library</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="overview">OVERVIEW</A></H1>
|
||||
<P><STRONG>LuaSQLite 3</STRONG> is a thin wrapper around the public domain SQLite3
|
||||
database engine.</P>
|
||||
<P>The <CODE>lsqlite3</CODE> module supports the creation and manipulation of
|
||||
SQLite3 databases. After a <CODE>require('lsqlite3')</CODE> the exported
|
||||
functions are called with prefix <CODE>sqlite3</CODE>. However, most sqlite3
|
||||
functions are called via an object-oriented interface to either
|
||||
database or SQL statement objects; see below for details.</P>
|
||||
<P>This documentation does not attempt to describe how SQLite3 itself
|
||||
works, it just describes the Lua binding and the available functions.
|
||||
For more information about the SQL features supported by SQLite3 and
|
||||
details about the syntax of SQL statements and queries, please see the
|
||||
<STRONG>SQLite3 documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>. Using some of the
|
||||
advanced features (how to use callbacks, for instance) will require
|
||||
some familiarity with the SQLite3 API.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="reference">REFERENCE</A></H1>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="sqlite3 functions">SQLite3 functions</A></H1>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.complete">sqlite3.complete</A></H2>
|
||||
<PRE>
|
||||
sqlite3.complete(sql)</PRE>
|
||||
<P>Returns true if the string <CODE>sql</CODE> comprises one or more complete SQL
|
||||
statements and false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open">sqlite3.open</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open(filename)</PRE>
|
||||
<P>Opens (or creates if it does not exist) an SQLite database with name
|
||||
<CODE>filename</CODE> and returns its handle as userdata (the returned object
|
||||
should be used for all further method calls in connection with this
|
||||
specific database, see <A HREF="#database methods">Database methods</A>). Example:</P>
|
||||
<PRE>
|
||||
myDB=sqlite3.open('MyDatabase.sqlite3') -- open
|
||||
-- do some database calls...
|
||||
myDB:close() -- close</PRE>
|
||||
<P>In case of an error, the function returns nil, an error code and an
|
||||
error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.open_memory">sqlite3.open_memory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.open_memory()</PRE>
|
||||
<P>Opens an SQLite database <STRONG>in memory</STRONG> and returns its handle as
|
||||
userdata. In case of an error, the function returns nil, an error code
|
||||
and an error message. (In-memory databases are volatile as they are
|
||||
never stored on disk.)</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.temp_directory">sqlite3.temp_directory</A></H2>
|
||||
<PRE>
|
||||
sqlite3.temp_directory([temp])</PRE>
|
||||
<P>Sets or queries the directory used by SQLite for temporary files. If
|
||||
string <CODE>temp</CODE> is a directory name or nil, the temporary directory is
|
||||
set accordingly and the old value is returned. If <CODE>temp</CODE> is missing,
|
||||
the function simply returns the current temporary directory.</P>
|
||||
<P>
|
||||
<H2><A NAME="sqlite3.version">sqlite3.version</A></H2>
|
||||
<PRE>
|
||||
sqlite3.version()</PRE>
|
||||
<P>Returns a string with SQLite version information, in the form 'x.y[.z]'.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="database methods">Database methods</A></H1>
|
||||
<P>After opening a database with <A HREF="#sqlite3.open"><CODE>sqlite3.open()</CODE></A> or
|
||||
<A HREF="#sqlite3.open_memory"><CODE>sqlite3.open_memory()</CODE></A>
|
||||
the returned database object should be used for all further method calls
|
||||
in connection with that database. An open database object supports the
|
||||
following methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_handler">db:busy_handler</A></H2>
|
||||
<PRE>
|
||||
db:busy_handler([func[,udata]])</PRE>
|
||||
<P>Sets or removes a busy handler for a database. <CODE>func</CODE> is either a Lua
|
||||
function that implements the busy handler or nil to remove a previously
|
||||
set handler. This function returns nothing.</P>
|
||||
<P>The handler function is called with two parameters: <CODE>udata</CODE> and the
|
||||
number of (re-)tries for a pending transaction. It should return nil,
|
||||
false or 0 if the transaction is to be aborted. All other values will
|
||||
result in another attempt to perform the transaction. (See the SQLite
|
||||
documentation for important hints about writing busy handlers.)</P>
|
||||
<P>
|
||||
<H2><A NAME="db:busy_timeout">db:busy_timeout</A></H2>
|
||||
<PRE>
|
||||
db:busy_timeout(t)</PRE>
|
||||
<P>Sets a busy handler that waits for <CODE>t</CODE> milliseconds if a transaction
|
||||
cannot proceed. Calling this function will remove any busy handler set
|
||||
by <A HREF="#db:busy_handler"><CODE>db:busy_handler()</CODE></A>; calling it with an argument
|
||||
less than or equal to 0 will turn off all busy handlers.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:changes">db:changes</A></H2>
|
||||
<PRE>
|
||||
db:changes()</PRE>
|
||||
<P>This function returns the number of database rows that were changed (or
|
||||
inserted or deleted) by the most recent SQL statement. Only changes that
|
||||
are directly specified by INSERT, UPDATE, or DELETE statements are
|
||||
counted. Auxiliary changes caused by triggers are not counted. Use
|
||||
<A HREF="#db:total_changes"><CODE>db:total_changes()</CODE></A> to find the total number of
|
||||
changes.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close">db:close</A></H2>
|
||||
<PRE>
|
||||
db:close()</PRE>
|
||||
<P>Closes a database. All SQL statements prepared using
|
||||
<A HREF="#db:prepare"><CODE>db:prepare()</CODE></A> should
|
||||
have been finalized before this function is called. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see the list of
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:close_vm">db:close_vm</A></H2>
|
||||
<PRE>
|
||||
db:close_vm(temponly)</PRE>
|
||||
<P>Finalizes all statements that have not been explicitly finalized. If
|
||||
<CODE>temponly</CODE> is true, only internal, temporary statements are finalized.
|
||||
This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:create_aggregate">db:create_aggregate</A></H2>
|
||||
<PRE>
|
||||
db:create_aggregate(name,nargs,step,final)</PRE>
|
||||
<P>This function creates an aggregate callback function. Aggregates perform
|
||||
an operation over all rows in a query. <CODE>name</CODE> is a string with the name
|
||||
of the aggregate function as given in an SQL statement; <CODE>nargs</CODE> is the
|
||||
number of arguments this call will provide. <CODE>step</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a function
|
||||
context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same number of
|
||||
parameters as given in <CODE>nargs</CODE>. <CODE>final</CODE> is a function that is called
|
||||
once after all rows have been processed; it receives one argument, the
|
||||
function context.</P>
|
||||
<P>The function context can be used inside the two callback functions to
|
||||
communicate with SQLite3. Here is a simple example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
local num_sum=0
|
||||
local function oneRow(context,num) -- add one column in all rows
|
||||
num_sum=num_sum+num
|
||||
end
|
||||
local function afterLast(context) -- return sum after last row has been processed
|
||||
context:result_number(num_sum)
|
||||
num_sum=0
|
||||
end
|
||||
db:create_aggregate("do_the_sums",1,oneRow,afterLast)
|
||||
for sum in db:urows('SELECT do_the_sums(num1) FROM numbers') do print("Sum of col 1:",sum) end
|
||||
for sum in db:urows('SELECT do_the_sums(num2) FROM numbers') do print("Sum of col 2:",sum) end</PRE>
|
||||
<P>This prints:</P>
|
||||
<PRE>
|
||||
Sum of col 1: 6
|
||||
Sum of col 2: 66</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_collation">db:create_collation</A></H2>
|
||||
<PRE>
|
||||
db:create_collation(name,func)</PRE>
|
||||
<P>This creates a collation callback. A collation callback is used to
|
||||
establish a collation order, mostly for string comparisons and sorting
|
||||
purposes. <CODE>name</CODE> is a string with the name of the collation to be created;
|
||||
<CODE>func</CODE> is a function that accepts two string arguments, compares them
|
||||
and returns 0 if both strings are identical, -1 if the first argument is
|
||||
lower in the collation order than the second and 1 if the first argument
|
||||
is higher in the collation order than the second. A simple example:</P>
|
||||
<PRE>
|
||||
local function collate(s1,s2)
|
||||
s1=s1:lower()
|
||||
s2=s2:lower()
|
||||
if s1==s2 then return 0
|
||||
elseif s1<s2 then return -1
|
||||
else return 1 end
|
||||
end
|
||||
db:exec[=[
|
||||
CREATE TABLE test(id INTEGER PRIMARY KEY,content COLLATE CINSENS);
|
||||
INSERT INTO test VALUES(NULL,'hello world');
|
||||
INSERT INTO test VALUES(NULL,'Buenos dias');
|
||||
INSERT INTO test VALUES(NULL,'HELLO WORLD');
|
||||
]=]
|
||||
db:create_collation('CINSENS',collate)
|
||||
for row in db:nrows('SELECT * FROM test') do print(row.id,row.content) end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:create_function">db:create_function</A></H2>
|
||||
<PRE>
|
||||
db:create_function(name,nargs,func)</PRE>
|
||||
<P>This function creates a callback function. Callback function are called
|
||||
by SQLite3 once for every row in a query. <CODE>name</CODE> is a string with the
|
||||
name of the callback function as given in an SQL statement; <CODE>nargs</CODE> is
|
||||
the number of arguments this call will provide. <CODE>func</CODE> is the actual Lua
|
||||
function that gets called once for every row; it should accept a
|
||||
function context (see <A HREF="#methods for callback contexts">Methods for callback contexts</A>) plus the same
|
||||
number of parameters as given in nargs. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec'CREATE TABLE test(col1,col2,col3)'
|
||||
db:exec'INSERT INTO test VALUES(1,2,4)'
|
||||
db:exec'INSERT INTO test VALUES(2,4,9)'
|
||||
db:exec'INSERT INTO test VALUES(3,6,16)'
|
||||
db:create_function('sum_cols',3,function(ctx,a,b,c)
|
||||
ctx:result_number(a+b+c)
|
||||
end))
|
||||
for col1,col2,col3,sum in db:urows('SELECT *,sum_cols(col1,col2,col3) FROM test') do
|
||||
util.printf('%2i+%2i+%2i=%2i\n',col1,col2,col3,sum)
|
||||
end</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:errcode">db:errcode</A></H2>
|
||||
<PRE>
|
||||
db:errcode()
|
||||
db:error_code()</PRE>
|
||||
<P>Returns the numerical result code (or extended result code) for the most
|
||||
recent failed call associated with database db. See
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A> for details.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:errmsg">db:errmsg</A></H2>
|
||||
<PRE>
|
||||
db:errmsg()
|
||||
db:error_message()</PRE>
|
||||
<P>Returns a string that contains an error message for the most recent
|
||||
failed call associated with database db.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:exec">db:exec</A></H2>
|
||||
<PRE>
|
||||
db:exec(sql[,func[,udata]])
|
||||
db:execute(sql[,func[,udata]])</PRE>
|
||||
<P>Compiles and executes the SQL <CODE>statement(s)</CODE> given in string <CODE>sql</CODE>. The
|
||||
statements are simply executed one after the other and not stored. The
|
||||
function returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code
|
||||
(see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>If one or more of the SQL statements are queries, then the callback
|
||||
function specified in <CODE>func</CODE> is invoked once for each row of the query
|
||||
result (if <CODE>func</CODE> is nil, no callback is invoked). The callback receives
|
||||
four arguments: <CODE>udata</CODE> (the third parameter of the <CODE>db:exec()</CODE> call),
|
||||
the number of columns in the row, a table with the column values and
|
||||
another table with the column names. The callback function should return
|
||||
0. If the callback returns a non-zero value then the query is aborted,
|
||||
all subsequent SQL statements are skipped and <CODE>db:exec()</CODE> returns
|
||||
<CODE>sqlite3.ABORT</CODE>. Here is a simple example:</P>
|
||||
<PRE>
|
||||
sql=[=[
|
||||
CREATE TABLE numbers(num1,num2,str);
|
||||
INSERT INTO numbers VALUES(1,11,"ABC");
|
||||
INSERT INTO numbers VALUES(2,22,"DEF");
|
||||
INSERT INTO numbers VALUES(3,33,"UVW");
|
||||
INSERT INTO numbers VALUES(4,44,"XYZ");
|
||||
SELECT * FROM numbers;
|
||||
]=]
|
||||
function showrow(udata,cols,values,names)
|
||||
assert(udata=='test_udata')
|
||||
print('exec:')
|
||||
for i=1,cols do print('',names[i],values[i]) end
|
||||
return 0
|
||||
end
|
||||
db:exec(sql,showrow,'test_udata')</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:interrupt">db:interrupt</A></H2>
|
||||
<PRE>
|
||||
db:interrupt()</PRE>
|
||||
<P>This function causes any pending database operation to abort and return
|
||||
at the next opportunity. This function returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:isopen">db:isopen</A></H2>
|
||||
<PRE>
|
||||
db:isopen()</PRE>
|
||||
<P>Returns true if database db is open, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:last_insert_rowid">db:last_insert_rowid</A></H2>
|
||||
<PRE>
|
||||
db:last_insert_rowid()</PRE>
|
||||
<P>This function returns the rowid of the most recent INSERT into the
|
||||
database. If no inserts have ever occurred, 0 is returned. (Each row in
|
||||
an SQLite table has a unique 64-bit signed integer key called the
|
||||
'rowid'. This id is always available as an undeclared column named
|
||||
ROWID, OID, or _ROWID_. If the table has a column of type INTEGER
|
||||
PRIMARY KEY then that column is another alias for the rowid.)</P>
|
||||
<P>If an INSERT occurs within a trigger, then the rowid of the inserted row
|
||||
is returned as long as the trigger is running. Once the trigger
|
||||
terminates, the value returned reverts to the last value inserted before
|
||||
the trigger fired.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:nrows">db:nrows</A></H2>
|
||||
<PRE>
|
||||
db:nrows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a
|
||||
table in which the named fields correspond to the columns in the database.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:nrows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
num2: 11
|
||||
num1: 1
|
||||
num2: 22
|
||||
num1: 2
|
||||
num2: 33
|
||||
num1: 3</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:prepare">db:prepare</A></H2>
|
||||
<PRE>
|
||||
db:prepare(sql)</PRE>
|
||||
<P>This function compiles the SQL statement in string <CODE>sql</CODE> into an internal
|
||||
representation and returns this as userdata. The returned object should
|
||||
be used for all further method calls in connection with this specific
|
||||
SQL statement (see <A HREF="#methods for prepared statements">Methods for prepared statements</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="db:progress_handler">db:progress_handler</A></H2>
|
||||
<PRE>
|
||||
db:progress_handler(n,func,udata)</PRE>
|
||||
<P>This function installs a callback function <CODE>func</CODE> that is invoked
|
||||
periodically during long-running calls to <A HREF="#db:exec"><CODE>db:exec()</CODE></A>
|
||||
or <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A>. The
|
||||
progress callback is invoked once for every <CODE>n</CODE> internal operations,
|
||||
where <CODE>n</CODE> is the first argument to this function. <CODE>udata</CODE> is passed to
|
||||
the progress callback function each time it is invoked. If a call to
|
||||
<CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> results in fewer than <CODE>n</CODE> operations
|
||||
being executed, then the progress callback is never invoked. Only a
|
||||
single progress callback function may be registered for each opened
|
||||
database and a call to this function will overwrite any previously set
|
||||
callback function. To remove the progress callback altogether, pass nil
|
||||
as the second argument.</P>
|
||||
<P>If the progress callback returns a result other than 0, then the current
|
||||
query is immediately terminated, any database changes are rolled back
|
||||
and the containing <CODE>db:exec()</CODE> or <CODE>stmt:step()</CODE> call returns
|
||||
<CODE>sqlite3.INTERRUPT</CODE>. This feature can be used to cancel long-running
|
||||
queries.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:rows">db:rows</A></H2>
|
||||
<PRE>
|
||||
db:rows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns a table
|
||||
in which the numerical indices 1 to n correspond to the selected columns
|
||||
1 to n in the database. Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for a in db:rows('SELECT * FROM numbers') do table.print(a) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1: 1
|
||||
2: 11
|
||||
1: 2
|
||||
2: 22
|
||||
1: 3
|
||||
2: 33</PRE>
|
||||
<P>
|
||||
<H2><A NAME="db:total_changes">db:total_changes</A></H2>
|
||||
<PRE>
|
||||
db:total_changes()</PRE>
|
||||
<P>This function returns the number of database rows that have been
|
||||
modified by INSERT, UPDATE or DELETE statements since the database was
|
||||
opened. This includes UPDATE, INSERT and DELETE statements executed as
|
||||
part of trigger programs. All changes are counted as soon as the
|
||||
statement that produces them is completed by calling either
|
||||
<A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> or <A HREF="#stmt:finalize"><CODE>stmt:finalize()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:trace">db:trace</A></H2>
|
||||
<PRE>
|
||||
db:trace(func,udata)</PRE>
|
||||
<P>This function installs a trace callback handler. <CODE>func</CODE> is a Lua
|
||||
function that is called by SQLite3 just before the evaluation of an SQL
|
||||
statement. This callback receives two arguments: the first is the
|
||||
<CODE>udata</CODE> argument used when the callback was installed; the second is a
|
||||
string with the SQL statement about to be executed.</P>
|
||||
<P>
|
||||
<H2><A NAME="db:urows">db:urows</A></H2>
|
||||
<PRE>
|
||||
db:urows(sql)</PRE>
|
||||
<P>Creates an iterator that returns the successive rows selected by the SQL
|
||||
statement given in string <CODE>sql</CODE>. Each call to the iterator returns the
|
||||
values that correspond to the columns in the currently selected row.
|
||||
Here is an example:</P>
|
||||
<PRE>
|
||||
db:exec[=[
|
||||
CREATE TABLE numbers(num1,num2);
|
||||
INSERT INTO numbers VALUES(1,11);
|
||||
INSERT INTO numbers VALUES(2,22);
|
||||
INSERT INTO numbers VALUES(3,33);
|
||||
]=]
|
||||
for num1,num2 in db:urows('SELECT * FROM numbers') do print(num1,num2) end</PRE>
|
||||
<P>This script prints:</P>
|
||||
<PRE>
|
||||
1 11
|
||||
2 22
|
||||
3 33</PRE>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for prepared statements">Methods for prepared statements</A></H1>
|
||||
<P>After creating a prepared statement with <A HREF="#db:prepare"><CODE>db:prepare()</CODE></A>
|
||||
the returned statement object should be used for all further calls in
|
||||
connection with that statement. Statement objects support the following
|
||||
methods.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind">stmt:bind</A></H2>
|
||||
<PRE>
|
||||
stmt:bind(n[,value])</PRE>
|
||||
<P>Binds value to statement parameter <CODE>n</CODE>. If the type of value is string
|
||||
or number, it is bound as text or double, respectively. If <CODE>value</CODE> is a
|
||||
boolean or nil or missing, any previous binding is removed. The function
|
||||
returns <CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_blob">stmt:bind_blob</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_blob(n,blob)</PRE>
|
||||
<P>Binds string <CODE>blob</CODE> (which can be a binary string) as a blob to
|
||||
statement parameter <CODE>n</CODE>. The function returns <CODE>sqlite3.OK</CODE> on success
|
||||
or else a numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_names">stmt:bind_names</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_names(nametable)</PRE>
|
||||
<P>Binds the values in <CODE>nametable</CODE> to statement parameters. If the
|
||||
statement parameters are named (i.e., of the form ``:AAA'' or ``$AAA'')
|
||||
then this function looks for appropriately named fields in <CODE>nametable</CODE>;
|
||||
if the statement parameters are
|
||||
not named, it looks for numerical fields 1 to the number of statement
|
||||
parameters. The function returns <CODE>sqlite3.OK</CODE> on success or else a
|
||||
numerical error code (see <A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_count">stmt:bind_parameter_count</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_count()</PRE>
|
||||
<P>Returns the largest statement parameter index in prepared statement
|
||||
<CODE>stmt</CODE>. When the statement parameters are of the forms ``:AAA'' or ``?'',
|
||||
then they are assigned sequentially increasing numbers beginning with
|
||||
one, so the value returned is the number of parameters. However if the
|
||||
same statement parameter name is used multiple times, each occurrence
|
||||
is given the same number, so the value returned is the number of unique
|
||||
statement parameter names.</P>
|
||||
<P>If statement parameters of the form ``?NNN'' are used (where NNN is an
|
||||
integer) then there might be gaps in the numbering and the value
|
||||
returned by this interface is the index of the statement parameter with
|
||||
the largest index value.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_parameter_name">stmt:bind_parameter_name</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_parameter_name(n)</PRE>
|
||||
<P>Returns the name of the <CODE>n</CODE>-th parameter in prepared statement <CODE>stmt</CODE>.
|
||||
Statement parameters of the form ``:AAA'' or ``@AAA'' or ``$VVV'' have a name
|
||||
which is the string ``:AAA'' or ``@AAA'' or ``$VVV''. In other words, the
|
||||
initial ``:'' or ``$'' or ``@'' is included as part of the name. Parameters
|
||||
of the form ``?'' or ``?NNN'' have no name. The first bound parameter has
|
||||
an index of 1.
|
||||
If the value <CODE>n</CODE> is out of range or if the <CODE>n</CODE>-th parameter is
|
||||
nameless, then nil is returned. The function returns <CODE>sqlite3.OK</CODE> on
|
||||
success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:bind_values">stmt:bind_values</A></H2>
|
||||
<PRE>
|
||||
stmt:bind_values(value1,value2,...,valueN)</PRE>
|
||||
<P>Binds the given values to statement parameters. The function returns
|
||||
<CODE>sqlite3.OK</CODE> on success or else a numerical error code (see
|
||||
<A HREF="#numerical error and result codes">Numerical error and result codes</A>).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:columns">stmt:columns</A></H2>
|
||||
<PRE>
|
||||
stmt:columns()</PRE>
|
||||
<P>Returns the number of columns in the result set returned by statement
|
||||
stmt or 0 if the statement does not return data (for example an UPDATE).</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:finalize">stmt:finalize</A></H2>
|
||||
<PRE>
|
||||
stmt:finalize()</PRE>
|
||||
<P>This function frees prepared statement stmt. If the statement was
|
||||
executed successfully, or not executed at all, then <CODE>sqlite3.OK</CODE> is
|
||||
returned. If execution of the statement failed then an error code is
|
||||
returned.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_name">stmt:get_name</A></H2>
|
||||
<PRE>
|
||||
stmt:get_name(n)</PRE>
|
||||
<P>Returns the name of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_types">stmt:get_named_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_types()</PRE>
|
||||
<P>Returns a table with the names and types of all columns in the result
|
||||
set of statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_named_values">stmt:get_named_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_named_values()</PRE>
|
||||
<P>This function returns a table with names and values of all columns in
|
||||
the current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_names">stmt:get_names</A></H2>
|
||||
<PRE>
|
||||
stmt:get_names()</PRE>
|
||||
<P>This function returns an array with the names of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_type">stmt:get_type</A></H2>
|
||||
<PRE>
|
||||
stmt:get_type(n)</PRE>
|
||||
<P>Returns the type of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_types">stmt:get_types</A></H2>
|
||||
<PRE>
|
||||
stmt:get_types()</PRE>
|
||||
<P>This function returns an array with the types of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_unames">stmt:get_unames</A></H2>
|
||||
<PRE>
|
||||
stmt:get_unames()</PRE>
|
||||
<P>This function returns a list with the names of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_utypes">stmt:get_utypes</A></H2>
|
||||
<PRE>
|
||||
stmt:get_utypes()</PRE>
|
||||
<P>This function returns a list with the types of all columns in the result
|
||||
set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_uvalues">stmt:get_uvalues</A></H2>
|
||||
<PRE>
|
||||
stmt:get_uvalues()</PRE>
|
||||
<P>This function returns a list with the values of all columns in the
|
||||
current result row of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_value">stmt:get_value</A></H2>
|
||||
<PRE>
|
||||
stmt:get_value(n)</PRE>
|
||||
<P>Returns the value of column <CODE>n</CODE> in the result set of statement stmt. (The
|
||||
left-most column is number 0.)</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:get_values">stmt:get_values</A></H2>
|
||||
<PRE>
|
||||
stmt:get_values()</PRE>
|
||||
<P>This function returns an array with the values of all columns in the
|
||||
result set returned by statement stmt.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:isopen">stmt:isopen</A></H2>
|
||||
<PRE>
|
||||
stmt:isopen()</PRE>
|
||||
<P>Returns true if stmt has not yet been finalized, false otherwise.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:nrows">stmt:nrows</A></H2>
|
||||
<PRE>
|
||||
stmt:nrows()</PRE>
|
||||
<P>Returns an function that iterates over the names and values of the
|
||||
result set of statement <CODE>stmt</CODE>. Each iteration returns a table with the
|
||||
names and values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:nrows"><CODE>db:nrows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:reset">stmt:reset</A></H2>
|
||||
<PRE>
|
||||
stmt:reset()</PRE>
|
||||
<P>This function resets SQL statement <CODE>stmt</CODE>, so that it is ready to be
|
||||
re-executed. Any statement variables that had values bound to them using
|
||||
the <CODE>stmt:bind*()</CODE> functions retain their values.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:rows">stmt:rows</A></H2>
|
||||
<PRE>
|
||||
stmt:rows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns an array with the values for the
|
||||
current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:rows"><CODE>db:rows()</CODE></A>.</P>
|
||||
<P>
|
||||
<H2><A NAME="stmt:step">stmt:step</A></H2>
|
||||
<PRE>
|
||||
stmt:step()</PRE>
|
||||
<P>This function must be called to evaluate the (next iteration of the)
|
||||
prepared statement stmt. It will return one of the following values:</P>
|
||||
<UL>
|
||||
<LI>
|
||||
<CODE>sqlite3.BUSY</CODE>: the engine was unable to acquire the locks needed. If the
|
||||
statement is a COMMIT or occurs outside of an explicit transaction, then
|
||||
you can retry the statement. If the statement is not a COMMIT and occurs
|
||||
within a explicit transaction then you should rollback the transaction
|
||||
before continuing.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.DONE</CODE>: the statement has finished executing successfully.
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again on this statement
|
||||
without first calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A> to reset the virtual
|
||||
machine back to the initial state.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ROW</CODE>: this is returned each time a new row of data is ready for
|
||||
processing by the caller. The values may be accessed using the column
|
||||
access functions. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> can be called again to
|
||||
retrieve the next row of data.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.ERROR</CODE>: a run-time error (such as a constraint violation) has
|
||||
occurred. <A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> should not be called again. More
|
||||
information may be found by calling <A HREF="#db:errmsg"><CODE>db:errmsg()</CODE></A>. A more
|
||||
specific error
|
||||
code (can be obtained by calling <A HREF="#stmt:reset"><CODE>stmt:reset()</CODE></A>.
|
||||
<P></P>
|
||||
<LI>
|
||||
<CODE>sqlite3.MISUSE</CODE>: the function was called inappropriately, perhaps
|
||||
because the statement has already been finalized or a previous call to
|
||||
<A HREF="#stmt:step"><CODE>stmt:step()</CODE></A> has returned <CODE>sqlite3.ERROR</CODE> or
|
||||
<CODE>sqlite3.DONE</CODE>.
|
||||
<P></P></UL>
|
||||
<P>
|
||||
<H2><A NAME="stmt:urows">stmt:urows</A></H2>
|
||||
<PRE>
|
||||
stmt:urows()</PRE>
|
||||
<P>Returns an function that iterates over the values of the result set of
|
||||
statement stmt. Each iteration returns the values for the current row.
|
||||
This is the prepared statement equivalent of <A HREF="#db:urows"><CODE>db:urows()</CODE></A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="methods for callback contexts">Methods for callback contexts</A></H1>
|
||||
<P>A callback context is available as a parameter inside the callback
|
||||
functions <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A>. It can be used
|
||||
to get further information about the state of a query.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:aggregate_count">context:aggregate_count</A></H2>
|
||||
<PRE>
|
||||
context:aggregate_count()</PRE>
|
||||
<P>Returns the number of calls to the aggregate step function.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:get_aggregate_data">context:get_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:get_aggregate_data()</PRE>
|
||||
<P>Returns the user-definable data field for callback funtions.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:set_aggregate_data">context:set_aggregate_data</A></H2>
|
||||
<PRE>
|
||||
context:set_aggregate_data(udata)</PRE>
|
||||
<P>Set the user-definable data field for callback funtions to <CODE>udata</CODE>.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result">context:result</A></H2>
|
||||
<PRE>
|
||||
context:result(res)</PRE>
|
||||
<P>This function sets the result of a callback function to res. The type of
|
||||
the result depends on the type of res and is either a number or a string
|
||||
or nil. All other values will raise an error message.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_null">context:result_null</A></H2>
|
||||
<PRE>
|
||||
context:result_null()</PRE>
|
||||
<P>This function sets the result of a callback function to nil. It returns
|
||||
nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_number">context:result_number</A></H2>
|
||||
<PRE>
|
||||
context:result_number(number)
|
||||
context:result_double(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the value
|
||||
<CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_int">context:result_int</A></H2>
|
||||
<PRE>
|
||||
context:result_int(number)</PRE>
|
||||
<P>This function sets the result of a callback function to the integer
|
||||
value in <CODE>number</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_text">context:result_text</A></H2>
|
||||
<PRE>
|
||||
context:result_text(str)</PRE>
|
||||
<P>This function sets the result of a callback function to the string in
|
||||
<CODE>str</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_blob">context:result_blob</A></H2>
|
||||
<PRE>
|
||||
context:result_blob(blob)</PRE>
|
||||
<P>This function sets the result of a callback function to the binary
|
||||
string in <CODE>blob</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:result_error">context:result_error</A></H2>
|
||||
<PRE>
|
||||
context:result_error(err)</PRE>
|
||||
<P>This function sets the result of a callback function to the error value
|
||||
in <CODE>err</CODE>. It returns nothing.</P>
|
||||
<P>
|
||||
<H2><A NAME="context:user_data">context:user_data</A></H2>
|
||||
<PRE>
|
||||
context:user_data()</PRE>
|
||||
<P>Returns the userdata parameter given in the call to install the callback
|
||||
function (see <A HREF="#db:create_aggregate"><CODE>db:create_aggregate()</CODE></A> and
|
||||
<A HREF="#db:create_function"><CODE>db:create_function()</CODE></A> for details).</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="numerical error and result codes">Numerical error and result codes</A></H1>
|
||||
<P>The following constants are defined by module sqlite3:</P>
|
||||
<PRE>
|
||||
OK: 0 ERROR: 1 INTERNAL: 2 PERM: 3 ABORT: 4
|
||||
BUSY: 5 LOCKED: 6 NOMEM: 7 READONLY: 8 INTERRUPT: 9
|
||||
IOERR: 10 CORRUPT: 11 NOTFOUND: 12 FULL: 13 CANTOPEN: 14
|
||||
PROTOCOL: 15 EMPTY: 16 SCHEMA: 17 TOOBIG: 18 CONSTRAINT: 19
|
||||
MISMATCH: 20 MISUSE: 21 NOLFS: 22 FORMAT: 24 RANGE: 25
|
||||
NOTADB: 26 ROW: 100 DONE: 101</PRE>
|
||||
<P>For details about their exact meaning please see the <STRONG>SQLite3
|
||||
documentation</STRONG> <A HREF="http://www.sqlite.org/">http://www.sqlite.org/</A>.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="version">VERSION</A></H1>
|
||||
<P>This is <CODE>lsqlite3</CODE> subversion 6, also known as ``devel-0.6''.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="credits">CREDITS</A></H1>
|
||||
<P><CODE>lsqlite3</CODE> was developed by Tiago Dionizio and Doug Currie with
|
||||
contributions from Thomas Lauer and Michael Roth.</P>
|
||||
<P>This documentation is based on the ``(very) preliminary'' documents
|
||||
for the Idle-SQLite3 database module. Thanks to Thomas Lauer for
|
||||
making it available.</P>
|
||||
<P>
|
||||
<HR>
|
||||
<H1><A NAME="license">LICENSE</A></H1>
|
||||
<PRE>
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2007 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining *
|
||||
* a copy of this software and associated documentation files (the *
|
||||
* "Software"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to *
|
||||
* the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be *
|
||||
* included in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
************************************************************************/</PRE>
|
||||
|
||||
</BODY>
|
||||
|
||||
</HTML>
|
||||
13
cosmic rage/docs/lua_license.txt
Normal file
13
cosmic rage/docs/lua_license.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
Lua 5.0 license
|
||||
|
||||
Copyright <20> 2003-2004 Tecgraf, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
http://www.lua.org
|
||||
|
||||
BIN
cosmic rage/docs/luacom.pdf
Normal file
BIN
cosmic rage/docs/luacom.pdf
Normal file
Binary file not shown.
156
cosmic rage/docs/mersenne_twister.txt
Normal file
156
cosmic rage/docs/mersenne_twister.txt
Normal file
@@ -0,0 +1,156 @@
|
||||
What is Mersenne Twister (MT)?
|
||||
|
||||
Mersenne Twister(MT) is a pseudorandom number generating algorithm developped by Makoto Matsumoto and Takuji Nishimura (alphabetical order) in 1996/1997. An improvement on initialization was given on 2002 Jan.
|
||||
|
||||
MT has the following merits:
|
||||
|
||||
* It is designed with consideration on the flaws of various existing generators.
|
||||
|
||||
* The algorithm is coded into a C-source downloadable below.
|
||||
|
||||
* Far longer period and far higher order of equidistribution than any other implemented generators. (It is proved that the period is 2^19937-1, and 623-dimensional equidistribution property is assured.)
|
||||
|
||||
* Fast generation. (Although it depends on the system, it is reported that MT is sometimes faster than the standard ANSI-C library in a system with pipeline and cache memory.) (Note added in 2004/3: on 1998, usually MT was much faster than rand(), but the algorithm for rand() has been substituted, and now there are no much difference in speed.)
|
||||
|
||||
* Efficient use of the memory. (The implemented C-code mt19937.c consumes only 624 words of working area.)
|
||||
|
||||
-------
|
||||
Copyright notice from source code.
|
||||
-------
|
||||
|
||||
A C-program for MT19937, with initialization improved 2002/1/26.
|
||||
Coded by Takuji Nishimura and Makoto Matsumoto.
|
||||
|
||||
Before using, initialize the state by using init_genrand(seed)
|
||||
or init_by_array(init_key, key_length).
|
||||
|
||||
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The names of its contributors may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Any feedback is very welcome.
|
||||
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
||||
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
||||
|
||||
-----------
|
||||
Note re the period. Using the "bc" program under Linux, we can see that the MT algorithm repeats itself every
|
||||
|
||||
2^19937-1 =>
|
||||
|
||||
43154247973881626480552355163379198390539350432267115051652505414033\
|
||||
30680137658091130451362931858466554526993825764883531790221733458441\
|
||||
39095282691546091680190078753437413962968019201144864809026614143184\
|
||||
43276980300066728104984095451588176077132969843762134621790396391341\
|
||||
28520562761960051310664637664861599423667548653748024196435029593516\
|
||||
86623639090479483476923139783013778207857124190544743328445291831729\
|
||||
73242310888265081321626469451077707812282829444775022680488057820028\
|
||||
76465939916476626520090056149580034405435369038986289406179287201112\
|
||||
08336148084474829135473283672778795656483078469091169458662301697024\
|
||||
01260240187028746650033445774570315431292996025187780790119375902863\
|
||||
17108414964247337898626750330896137490576634090528957229001603800057\
|
||||
16308751913739795550474681543332534749910462481325045163417965514705\
|
||||
75481459200859472614836213875557116864445789750886277996487304308450\
|
||||
48422342062926651855602433933919084436892101842484467704272766460185\
|
||||
29149252772809226975384267702573339289544012054658956103476588553866\
|
||||
33902546289962132643282425748035786233580608154696546932563833327670\
|
||||
76989943977488852668727852745100296305914696387571542573553447597973\
|
||||
44631006783673933274021499309687782967413915145996023742136298987206\
|
||||
11431410402147238998090962818915890645693934483330994169632295877995\
|
||||
84899336674701487176349480554999616305154122540346529700772114623135\
|
||||
57040814930986630657336771911728539870957481678162560842128233801686\
|
||||
25334586431254034670806135273543270714478876861861983320777280644806\
|
||||
69112571319726258176315131359642954776357636783701934983517846214429\
|
||||
49607571909180546251141436663841894338525764522893476524546315357404\
|
||||
68786228945885654608562058042468987372436921445092315377698407168198\
|
||||
37653823774861419620704154810637936512319281799900662176646716711347\
|
||||
16327154817958770053826943934004030617004576911353491878748889234293\
|
||||
49340145170571716181125795888889277495426977149914549623916394014822\
|
||||
98502533165151143127880200905680845650681887726660983163688388490562\
|
||||
18222629339865486456690806721917047404088913498356856624280632311985\
|
||||
20436826329415290752972798343429446509992206368781367154091702655772\
|
||||
72739132942427752934908260058588476652315095741707783191001616847568\
|
||||
56586731928608820701797603072698499873548360423717346602576943472355\
|
||||
06301744118874141292438958141549100609752216882230887611431996472330\
|
||||
84238013711092744948355781503758684964458574991777286992674421836962\
|
||||
11376751010832785437940817490940910430840967741447084363242794768920\
|
||||
56200427227961638669149805489831121244676399931955371484012886360748\
|
||||
70647956866904857478285521705474011394592962217750257556581106745220\
|
||||
14489819919686359653615516812739827407601388996388203187763036687627\
|
||||
30157584640042798880691862640268612686180883874939573818125022279689\
|
||||
93026744625577395954246983163786300017127922715140603412990218157065\
|
||||
96505326007758236773981821290873944498591827499990072235924233345678\
|
||||
50671186568839186747704960016277540625331440619019129983789914712515\
|
||||
36520033605799350860167880768756856237785709525554130490292719222018\
|
||||
41725023571244499118702106426945650613849193734743245039662677990384\
|
||||
02386781686809962015879090586549423504699190743519551043722544515740\
|
||||
96782908433602593822578073088027385526155197204407562032678062444880\
|
||||
34909982321612316877947156134057932495455095280525180101230872587789\
|
||||
74115817048245588971438596754408081313438375502988726739523375296641\
|
||||
61550140609160798322923982724061478325289247971651993698951918780868\
|
||||
12211916417477109024806334910917048274412282811866324459071457871383\
|
||||
51234842261380074621914004818152386666043133344875067903582838283562\
|
||||
68808323657548206847963954638381953217452250268237244136327576587560\
|
||||
91197836532983120667082171493167735643403792897243939867441398918554\
|
||||
16612295739356668612658271234696438377122838998040199739078061443675\
|
||||
41567107846340467370240377765347817336708484473470205686663615813800\
|
||||
36922533822099094664695919301616260979205087421756703065051395428607\
|
||||
50806159835357541032147095084278461056701367739794932024202998707731\
|
||||
01769258204621070221251412042932253043178961626704777611512359793540\
|
||||
41470848709854654265027720573009003338479053342506041195030300017040\
|
||||
02887892941404603345869926367501355094942750552591581639980523190679\
|
||||
61078499358089668329929768126244231400865703342186809455174050644882\
|
||||
90392073167113076951318922965935090186230948105575195603052407871638\
|
||||
09219164433754514863301000915916985856242176563624771328981678548246\
|
||||
29737624953025136036341276836645617507703197745753491280643317653999\
|
||||
59943433081184701471587128161493944212766142282629099500557469810532\
|
||||
06610001560295784656616193252269412026831159508949671513845195883217\
|
||||
14798274887926185141781997903441728559860772722086667768042609030875\
|
||||
48238033454465663056192413083744527546681430154877108777280110860043\
|
||||
25892262259413968285283497045571062757701421761565262725153407407625\
|
||||
40514993198949445910641466053430537857670986252004986488096114486925\
|
||||
86034737143636591940139627063668513892996928694918051725568185082988\
|
||||
24954954815796063169517658741420159798754273428026723452481263569157\
|
||||
30721315373978104162765371507859850415479728766312294671134815852941\
|
||||
88164328250444666927811374744948983850643757875073764963451486253063\
|
||||
83391555145690087891955315994462944493235248817599907119135755933382\
|
||||
12170619147718505493663221115722292033114850248756330311801880568507\
|
||||
35698415805181187107786539535712960143729408652704070219243831672903\
|
||||
23231567912289419486240594039074452321678019381871219092155460768444\
|
||||
57357855951361330424220615135645751393727093900970723782710124585383\
|
||||
76783381610233975868548942306960915402499879074534613119239638529507\
|
||||
54758058205625956600817743007191746812655955021747670922460866747744\
|
||||
52087560785906233475062709832859348006778945616960249439281376349565\
|
||||
75998474857735539909575573132008090408300364464922194099340969487305\
|
||||
47494301216165686750735749555882340303989874672975455060957736921559\
|
||||
19548081551403591570712993005702711728625284319741331230761788679750\
|
||||
67842601954367603059903407084814646072789554954877421407535706212171\
|
||||
98252192978869786916734625618430175454903864111585429504569920905636\
|
||||
741539030968041471
|
||||
|
||||
bytes.
|
||||
418
cosmic rage/docs/re.html
Normal file
418
cosmic rage/docs/re.html
Normal file
@@ -0,0 +1,418 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>LPeg.re - Regex syntax for LPEG</title>
|
||||
<link rel="stylesheet"
|
||||
href="http://www.inf.puc-rio.br/~roberto/lpeg/doc.css"
|
||||
type="text/css"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- $Id: re.html,v 1.15 2010/11/05 12:53:43 roberto Exp $ -->
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div id="product">
|
||||
<div id="product_logo">
|
||||
<a href="http://www.inf.puc-rio.br/~roberto/lpeg/">
|
||||
<img alt="LPeg logo" src="lpeg-128.gif"/>
|
||||
</a>
|
||||
</div>
|
||||
<div id="product_name"><big><strong>LPeg.re</strong></big></div>
|
||||
<div id="product_description">
|
||||
Regex syntax for LPEG
|
||||
</div>
|
||||
</div> <!-- id="product" -->
|
||||
|
||||
<div id="main">
|
||||
|
||||
<div id="navigation">
|
||||
<h1>re</h1>
|
||||
|
||||
<ul>
|
||||
<li><a href="#basic">Basic Constructions</a></li>
|
||||
<li><a href="#func">Functions</a></li>
|
||||
<li><a href="#ex">Some Examples</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div> <!-- id="navigation" -->
|
||||
|
||||
<div id="content">
|
||||
|
||||
<h2><a name="basic"></a>The <code>re</code> Module</h2>
|
||||
|
||||
<p>
|
||||
The <code>re</code> module
|
||||
(provided by file <code>re.lua</code> in the distribution)
|
||||
supports a somewhat conventional regex syntax
|
||||
for pattern usage within <a href="lpeg.html">LPeg</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The next table summarizes <code>re</code>'s syntax.
|
||||
A <code>p</code> represents an arbitrary pattern;
|
||||
<code>num</code> represents a number (<code>[0-9]+</code>);
|
||||
<code>name</code> represents an identifier
|
||||
(<code>[a-zA-Z][a-zA-Z0-9_]*</code>).
|
||||
Constructions are listed in order of decreasing precedence.
|
||||
<table border="1">
|
||||
<tbody><tr><td><b>Syntax</b></td><td><b>Description</b></td></tr>
|
||||
<tr><td><code>( p )</code></td> <td>grouping</td></tr>
|
||||
<tr><td><code>'string'</code></td> <td>literal string</td></tr>
|
||||
<tr><td><code>"string"</code></td> <td>literal string</td></tr>
|
||||
<tr><td><code>[class]</code></td> <td>character class</td></tr>
|
||||
<tr><td><code>.</code></td> <td>any character</td></tr>
|
||||
<tr><td><code>%name</code></td>
|
||||
<td>pattern <code>defs[name]</code> or a pre-defined pattern</td></tr>
|
||||
<tr><td><code>name</code></td><td>non terminal</td></tr>
|
||||
<tr><td><code><name></code></td><td>non terminal</td></tr>
|
||||
<tr><td><code>{}</code></td> <td>position capture</td></tr>
|
||||
<tr><td><code>{ p }</code></td> <td>simple capture</td></tr>
|
||||
<tr><td><code>{: p :}</code></td> <td>anonymous group capture</td></tr>
|
||||
<tr><td><code>{:name: p :}</code></td> <td>named group capture</td></tr>
|
||||
<tr><td><code>{~ p ~}</code></td> <td>substitution capture</td></tr>
|
||||
<tr><td><code>=name</code></td> <td>back reference
|
||||
</td></tr>
|
||||
<tr><td><code>p ?</code></td> <td>optional match</td></tr>
|
||||
<tr><td><code>p *</code></td> <td>zero or more repetitions</td></tr>
|
||||
<tr><td><code>p +</code></td> <td>one or more repetitions</td></tr>
|
||||
<tr><td><code>p^num</code></td> <td>exactly <code>n</code> repetitions</td></tr>
|
||||
<tr><td><code>p^+num</code></td>
|
||||
<td>at least <code>n</code> repetitions</td></tr>
|
||||
<tr><td><code>p^-num</code></td>
|
||||
<td>at most <code>n</code> repetitions</td></tr>
|
||||
<tr><td><code>p -> 'string'</code></td> <td>string capture</td></tr>
|
||||
<tr><td><code>p -> "string"</code></td> <td>string capture</td></tr>
|
||||
<tr><td><code>p -> {}</code></td> <td>table capture</td></tr>
|
||||
<tr><td><code>p -> name</code></td> <td>function/query/string capture
|
||||
equivalent to <code>p / defs[name]</code></td></tr>
|
||||
<tr><td><code>p => name</code></td> <td>match-time capture
|
||||
equivalent to <code>lpeg.Cmt(p, defs[name])</code></td></tr>
|
||||
<tr><td><code>& p</code></td> <td>and predicate</td></tr>
|
||||
<tr><td><code>! p</code></td> <td>not predicate</td></tr>
|
||||
<tr><td><code>p1 p2</code></td> <td>concatenation</td></tr>
|
||||
<tr><td><code>p1 / p2</code></td> <td>ordered choice</td></tr>
|
||||
<tr><td>(<code>name <- p</code>)<sup>+</sup></td> <td>grammar</td></tr>
|
||||
</tbody></table>
|
||||
<p>
|
||||
Any space appearing in a syntax description can be
|
||||
replaced by zero or more space characters and Lua-style comments
|
||||
(<code>--</code> until end of line).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Character classes define sets of characters.
|
||||
An initial <code>^</code> complements the resulting set.
|
||||
A range <em>x</em><code>-</code><em>y</em> includes in the set
|
||||
all characters with codes between the codes of <em>x</em> and <em>y</em>.
|
||||
A pre-defined class <code>%</code><em>name</em> includes all
|
||||
characters of that class.
|
||||
A simple character includes itself in the set.
|
||||
The only special characters inside a class are <code>^</code>
|
||||
(special only if it is the first character);
|
||||
<code>]</code>
|
||||
(can be included in the set as the first character,
|
||||
after the optional <code>^</code>);
|
||||
<code>%</code> (special only if followed by a letter);
|
||||
and <code>-</code>
|
||||
(can be included in the set as the first or the last character).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Currently the pre-defined classes are similar to those from the
|
||||
Lua's string library
|
||||
(<code>%a</code> for letters,
|
||||
<code>%A</code> for non letters, etc.).
|
||||
There is also a class <code>%nl</code>
|
||||
containing only the newline character,
|
||||
which is particularly handy for grammars written inside long strings,
|
||||
as long strings do not interpret escape sequences like <code>\n</code>.
|
||||
</p>
|
||||
|
||||
|
||||
<h2><a name="func">Functions</a></h2>
|
||||
|
||||
<h3><code>re.compile (string, [, defs])</code></h3>
|
||||
<p>
|
||||
Compiles the given string and
|
||||
returns an equivalent LPeg pattern.
|
||||
The given string may define either an expression or a grammar.
|
||||
The optional <code>defs</code> table provides extra Lua values
|
||||
to be used by the pattern.
|
||||
</p>
|
||||
|
||||
<h3><code>re.find (subject, pattern [, init])</code></h3>
|
||||
<p>
|
||||
Searches the given pattern in the given subject.
|
||||
If it finds a match,
|
||||
returns the index where this occurrence starts,
|
||||
plus the captures made by the pattern (if any).
|
||||
Otherwise, returns nil.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
An optional numeric argument <code>init</code> makes the search
|
||||
starts at that position in the subject string.
|
||||
As usual in Lua libraries,
|
||||
a negative value counts from the end.
|
||||
</p>
|
||||
|
||||
<h3><code>re.match (subject, pattern)</code></h3>
|
||||
<p>
|
||||
Matches the given pattern against the given subject.
|
||||
</p>
|
||||
|
||||
<h3><code>re.updatelocale ()</code></h3>
|
||||
<p>
|
||||
Updates the pre-defined character classes to the current locale.
|
||||
</p>
|
||||
|
||||
|
||||
<h2><a name="ex">Some Examples</a></h2>
|
||||
|
||||
<h3>A complete simple program</h3>
|
||||
<p>
|
||||
The next code shows a simple complete Lua program using
|
||||
the <code>re</code> module:
|
||||
</p>
|
||||
<pre class="example">
|
||||
local re = require"re"
|
||||
|
||||
-- find the position of the first number in a string
|
||||
print(re.find("the number 423 is odd", "[0-9]+")) --> 12
|
||||
|
||||
-- similar, but also captures (and returns) the number
|
||||
print(re.find("the number 423 is odd", "{[0-9]+}")) --> 12 423
|
||||
|
||||
-- returns all words in a string
|
||||
print(re.match("the number 423 is odd", "({%a+} / .)*"))
|
||||
--> the number is odd
|
||||
</pre>
|
||||
|
||||
|
||||
<h3>Balanced parentheses</h3>
|
||||
<p>
|
||||
The following call will produce the same pattern produced by the
|
||||
Lua expression in the
|
||||
<a href="lpeg.html#balanced">balanced parentheses</a> example:
|
||||
</p>
|
||||
<pre class="example">
|
||||
b = re.compile[[ balanced <- "(" ([^()] / balanced)* ")" ]]
|
||||
</pre>
|
||||
|
||||
<h3>String reversal</h3>
|
||||
<p>
|
||||
The next example reverses a string:
|
||||
</p>
|
||||
<pre class="example">
|
||||
rev = re.compile[[ R <- (!.) -> '' / ({.} R) -> '%2%1']]
|
||||
print(rev:match"0123456789") --> 9876543210
|
||||
</pre>
|
||||
|
||||
<h3>CSV decoder</h3>
|
||||
<p>
|
||||
The next example replicates the <a href="lpeg.html#CSV">CSV decoder</a>:
|
||||
</p>
|
||||
<pre class="example">
|
||||
record = re.compile[[
|
||||
record <- ( field (',' field)* ) -> {} (%nl / !.)
|
||||
field <- escaped / nonescaped
|
||||
nonescaped <- { [^,"%nl]* }
|
||||
escaped <- '"' {~ ([^"] / '""' -> '"')* ~} '"'
|
||||
]]
|
||||
</pre>
|
||||
|
||||
<h3>Lua's long strings</h3>
|
||||
<p>
|
||||
The next example matches Lua long strings:
|
||||
</p>
|
||||
<pre class="example">
|
||||
c = re.compile([[
|
||||
longstring <- ('[' {:eq: '='* :} '[' close) -> void
|
||||
close <- ']' =eq ']' / . close
|
||||
]], {void = function () end})
|
||||
|
||||
print(c:match'[==[]]===]]]]==]===[]') --> 17
|
||||
</pre>
|
||||
|
||||
<h3>Indented blocks</h3>
|
||||
<p>
|
||||
This example breaks indented blocks into tables,
|
||||
respecting the indentation:
|
||||
</p>
|
||||
<pre class="example">
|
||||
p = re.compile[[
|
||||
block <- ({:ident:' '*:} line
|
||||
((=ident !' ' line) / &(=ident ' ') block)*) -> {}
|
||||
line <- {[^%nl]*} %nl
|
||||
]]
|
||||
</pre>
|
||||
<p>
|
||||
As an example,
|
||||
consider the following text:
|
||||
</p>
|
||||
<pre class="example">
|
||||
t = p:match[[
|
||||
first line
|
||||
subline 1
|
||||
subline 2
|
||||
second line
|
||||
third line
|
||||
subline 3.1
|
||||
subline 3.1.1
|
||||
subline 3.2
|
||||
]]
|
||||
</pre>
|
||||
<p>
|
||||
The resulting table <code>t</code> will be like this:
|
||||
</p>
|
||||
<pre class="example">
|
||||
{'first line'; {'subline 1'; 'subline 2'; ident = ' '};
|
||||
'second line';
|
||||
'third line'; { 'subline 3.1'; {'subline 3.1.1'; ident = ' '};
|
||||
'subline 3.2'; ident = ' '};
|
||||
ident = ''}
|
||||
</pre>
|
||||
|
||||
<h3>Macro expander</h3>
|
||||
<p>
|
||||
This example implements a simple macro expander.
|
||||
Macros must be defined as part of the pattern,
|
||||
following some simple rules:
|
||||
</p>
|
||||
<pre class="example">
|
||||
p = re.compile[[
|
||||
text <- {~ item* ~}
|
||||
item <- macro / [^()] / '(' item* ')'
|
||||
arg <- ' '* {~ (!',' item)* ~}
|
||||
args <- '(' arg (',' arg)* ')'
|
||||
-- now we define some macros
|
||||
macro <- ('apply' args) -> '%1(%2)'
|
||||
/ ('add' args) -> '%1 + %2'
|
||||
/ ('mul' args) -> '%1 * %2'
|
||||
]]
|
||||
|
||||
print(p:match"add(mul(a,b), apply(f,x))") --> a * b + f(x)
|
||||
</pre>
|
||||
<p>
|
||||
A <code>text</code> is a sequence of items,
|
||||
wherein we apply a substitution capture to expand any macros.
|
||||
An <code>item</code> is either a macro,
|
||||
any character different from parentheses,
|
||||
or a parenthesized expression.
|
||||
A macro argument (<code>arg</code>) is a sequence
|
||||
of items different from a comma.
|
||||
(Note that a comma may appear inside an item,
|
||||
e.g., inside a parenthesized expression.)
|
||||
Again we do a substitution capture to expand any macro
|
||||
in the argument before expanding the outer macro.
|
||||
<code>args</code> is a list of arguments separated by commas.
|
||||
Finally we define the macros.
|
||||
Each macro is a string substitution;
|
||||
it replaces the macro name and its arguments by its corresponding string,
|
||||
with each <code>%</code><em>n</em> replaced by the <em>n</em>-th argument.
|
||||
</p>
|
||||
|
||||
<h3>Patterns</h3>
|
||||
<p>
|
||||
This example shows the complete syntax
|
||||
of patterns accepted by <code>re</code>.
|
||||
</p>
|
||||
<pre class="example">
|
||||
p = [=[
|
||||
|
||||
pattern <- exp !.
|
||||
exp <- S (alternative / grammar)
|
||||
|
||||
alternative <- seq ('/' S seq)*
|
||||
seq <- prefix*
|
||||
prefix <- '&' S prefix / '!' S prefix / suffix
|
||||
suffix <- primary S (([+*?]
|
||||
/ '^' [+-]? num
|
||||
/ '->' S (string / '{}' / name)
|
||||
/ '=>' S name) S)*
|
||||
|
||||
primary <- '(' exp ')' / string / class / defined
|
||||
/ '{:' (name ':')? exp ':}'
|
||||
/ '=' name
|
||||
/ '{}'
|
||||
/ '{~' exp '~}'
|
||||
/ '{' exp '}'
|
||||
/ '.'
|
||||
/ name S !arrow
|
||||
/ '<' name '>' -- old-style non terminals
|
||||
|
||||
grammar <- definition+
|
||||
definition <- name S arrow exp
|
||||
|
||||
class <- '[' '^'? item (!']' item)* ']'
|
||||
item <- defined / range / .
|
||||
range <- . '-' [^]]
|
||||
|
||||
S <- (%s / '--' [^%nl]*)* -- spaces and comments
|
||||
name <- [A-Za-z][A-Za-z0-9_]*
|
||||
arrow <- '<-'
|
||||
num <- [0-9]+
|
||||
string <- '"' [^"]* '"' / "'" [^']* "'"
|
||||
defined <- '%' name
|
||||
|
||||
]=]
|
||||
|
||||
print(re.match(p, p)) -- a self description must match itself
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
<h2><a name="license">License</a></h2>
|
||||
|
||||
<p>
|
||||
Copyright © 2008-2010 Lua.org, PUC-Rio.
|
||||
</p>
|
||||
<p>
|
||||
Permission is hereby granted, free of charge,
|
||||
to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction,
|
||||
including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is
|
||||
furnished to do so,
|
||||
subject to the following conditions:
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions of the Software.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
</p>
|
||||
|
||||
</div> <!-- id="content" -->
|
||||
|
||||
</div> <!-- id="main" -->
|
||||
|
||||
<div id="about">
|
||||
<p><small>
|
||||
$Id: re.html,v 1.15 2010/11/05 12:53:43 roberto Exp $
|
||||
</small></p>
|
||||
</div> <!-- id="about" -->
|
||||
|
||||
</div> <!-- id="container" -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
BIN
cosmic rage/dolapi.dll
Normal file
BIN
cosmic rage/dolapi.dll
Normal file
Binary file not shown.
2494
cosmic rage/fonts/banner.flf
Normal file
2494
cosmic rage/fonts/banner.flf
Normal file
File diff suppressed because it is too large
Load Diff
2204
cosmic rage/fonts/big.flf
Normal file
2204
cosmic rage/fonts/big.flf
Normal file
File diff suppressed because it is too large
Load Diff
1691
cosmic rage/fonts/block.flf
Normal file
1691
cosmic rage/fonts/block.flf
Normal file
File diff suppressed because it is too large
Load Diff
1630
cosmic rage/fonts/bubble.flf
Normal file
1630
cosmic rage/fonts/bubble.flf
Normal file
File diff suppressed because it is too large
Load Diff
1286
cosmic rage/fonts/digital.flf
Normal file
1286
cosmic rage/fonts/digital.flf
Normal file
File diff suppressed because it is too large
Load Diff
1691
cosmic rage/fonts/lean.flf
Normal file
1691
cosmic rage/fonts/lean.flf
Normal file
File diff suppressed because it is too large
Load Diff
899
cosmic rage/fonts/mini.flf
Normal file
899
cosmic rage/fonts/mini.flf
Normal file
@@ -0,0 +1,899 @@
|
||||
flf2a$ 4 3 10 0 10 0 1920 96
|
||||
Mini by Glenn Chappell 4/93
|
||||
Includes ISO Latin-1
|
||||
figlet release 2.1 -- 12 Aug 1994
|
||||
Permission is hereby given to modify this font, as long as the
|
||||
modifier's name is placed on a comment line.
|
||||
|
||||
Modified by Paul Burton <solution@earthlink.net> 12/96 to include new parameter
|
||||
supported by FIGlet and FIGWin. May also be slightly modified for better use
|
||||
of new full-width/kern/smush alternatives, but default output is NOT changed.
|
||||
|
||||
$$@
|
||||
$$@
|
||||
$$@
|
||||
$$@@
|
||||
@
|
||||
|$@
|
||||
o$@
|
||||
@@
|
||||
@
|
||||
||$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
-|-|-$@
|
||||
-|-|-$@
|
||||
@@
|
||||
_$@
|
||||
(|$ @
|
||||
_|)$@
|
||||
@@
|
||||
@
|
||||
O/$@
|
||||
/O$@
|
||||
@@
|
||||
@
|
||||
()$ @
|
||||
(_X$@
|
||||
@@
|
||||
@
|
||||
/$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
/$@
|
||||
|$ @
|
||||
\$@@
|
||||
@
|
||||
\$ @
|
||||
|$@
|
||||
/$ @@
|
||||
@
|
||||
\|/$@
|
||||
/|\$@
|
||||
@@
|
||||
@
|
||||
_|_$@
|
||||
|$ @
|
||||
@@
|
||||
@
|
||||
@
|
||||
o$@
|
||||
/$@@
|
||||
@
|
||||
__$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
@
|
||||
o$@
|
||||
@@
|
||||
@
|
||||
/$@
|
||||
/$ @
|
||||
@@
|
||||
_$ @
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
@
|
||||
/|$@
|
||||
|$@
|
||||
@@
|
||||
_$ @
|
||||
)$@
|
||||
/_$@
|
||||
@@
|
||||
_$ @
|
||||
_)$@
|
||||
_)$@
|
||||
@@
|
||||
@
|
||||
|_|_$@
|
||||
|$ @
|
||||
@@
|
||||
_$ @
|
||||
|_$ @
|
||||
_)$@
|
||||
@@
|
||||
_$ @
|
||||
|_$ @
|
||||
|_)$@
|
||||
@@
|
||||
__$@
|
||||
/$@
|
||||
/$ @
|
||||
@@
|
||||
_$ @
|
||||
(_)$@
|
||||
(_)$@
|
||||
@@
|
||||
_$ @
|
||||
(_|$@
|
||||
|$@
|
||||
@@
|
||||
@
|
||||
o$@
|
||||
o$@
|
||||
@@
|
||||
@
|
||||
o$@
|
||||
o$@
|
||||
/$@@
|
||||
@
|
||||
/$@
|
||||
\$@
|
||||
@@
|
||||
@
|
||||
--$@
|
||||
--$@
|
||||
@@
|
||||
@
|
||||
\$@
|
||||
/$@
|
||||
@@
|
||||
_$ @
|
||||
)$@
|
||||
o$ @
|
||||
@@
|
||||
__$ @
|
||||
/ \$@
|
||||
| (|/$@
|
||||
\__$ @@
|
||||
@
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
_$ @
|
||||
|_)$@
|
||||
|_)$@
|
||||
@@
|
||||
_$@
|
||||
/$ @
|
||||
\_$@
|
||||
@@
|
||||
_$ @
|
||||
| \$@
|
||||
|_/$@
|
||||
@@
|
||||
_$@
|
||||
|_$@
|
||||
|_$@
|
||||
@@
|
||||
_$@
|
||||
|_$@
|
||||
|$ @
|
||||
@@
|
||||
__$@
|
||||
/__$@
|
||||
\_|$@
|
||||
@@
|
||||
@
|
||||
|_|$@
|
||||
| |$@
|
||||
@@
|
||||
___$@
|
||||
|$ @
|
||||
_|_$@
|
||||
@@
|
||||
@
|
||||
|$@
|
||||
\_|$@
|
||||
@@
|
||||
@
|
||||
|/$@
|
||||
|\$@
|
||||
@@
|
||||
@
|
||||
|$ @
|
||||
|_$@
|
||||
@@
|
||||
@
|
||||
|\/|$@
|
||||
| |$@
|
||||
@@
|
||||
@
|
||||
|\ |$@
|
||||
| \|$@
|
||||
@@
|
||||
_$ @
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
_$ @
|
||||
|_)$@
|
||||
|$ @
|
||||
@@
|
||||
_$ @
|
||||
/ \$@
|
||||
\_X$@
|
||||
@@
|
||||
_$ @
|
||||
|_)$@
|
||||
| \$@
|
||||
@@
|
||||
__$@
|
||||
(_$ @
|
||||
__)$@
|
||||
@@
|
||||
___$@
|
||||
|$ @
|
||||
|$ @
|
||||
@@
|
||||
@
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
@
|
||||
\ /$@
|
||||
\/$ @
|
||||
@@
|
||||
@
|
||||
\ /$@
|
||||
\/\/$ @
|
||||
@@
|
||||
@
|
||||
\/$@
|
||||
/\$@
|
||||
@@
|
||||
@
|
||||
\_/$@
|
||||
|$ @
|
||||
@@
|
||||
__$@
|
||||
/$@
|
||||
/_$@
|
||||
@@
|
||||
_$@
|
||||
|$ @
|
||||
|_$@
|
||||
@@
|
||||
@
|
||||
\$ @
|
||||
\$@
|
||||
@@
|
||||
_$ @
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
/\$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
@
|
||||
@
|
||||
@
|
||||
__$@@
|
||||
@
|
||||
\$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
@
|
||||
|_$ @
|
||||
|_)$@
|
||||
@@
|
||||
@
|
||||
_$@
|
||||
(_$@
|
||||
@@
|
||||
@
|
||||
_|$@
|
||||
(_|$@
|
||||
@@
|
||||
@
|
||||
_$ @
|
||||
(/_$@
|
||||
@@
|
||||
_$@
|
||||
_|_$@
|
||||
|$ @
|
||||
@@
|
||||
@
|
||||
_$ @
|
||||
(_|$@
|
||||
_|$@@
|
||||
@
|
||||
|_$ @
|
||||
| |$@
|
||||
@@
|
||||
@
|
||||
o$@
|
||||
|$@
|
||||
@@
|
||||
@
|
||||
o$@
|
||||
|$@
|
||||
_|$@@
|
||||
@
|
||||
|$ @
|
||||
|<$@
|
||||
@@
|
||||
@
|
||||
|$@
|
||||
|$@
|
||||
@@
|
||||
@
|
||||
._ _$ @
|
||||
| | |$@
|
||||
@@
|
||||
@
|
||||
._$ @
|
||||
| |$@
|
||||
@@
|
||||
@
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
@
|
||||
._$ @
|
||||
|_)$@
|
||||
|$ @@
|
||||
@
|
||||
_.$@
|
||||
(_|$@
|
||||
|$@@
|
||||
@
|
||||
._$@
|
||||
|$ @
|
||||
@@
|
||||
@
|
||||
_$@
|
||||
_>$@
|
||||
@@
|
||||
@
|
||||
_|_$@
|
||||
|_$@
|
||||
@@
|
||||
@
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
@
|
||||
@
|
||||
\/$@
|
||||
@@
|
||||
@
|
||||
@
|
||||
\/\/$@
|
||||
@@
|
||||
@
|
||||
@
|
||||
><$@
|
||||
@@
|
||||
@
|
||||
@
|
||||
\/$@
|
||||
/$ @@
|
||||
@
|
||||
_$ @
|
||||
/_$@
|
||||
@@
|
||||
,-$@
|
||||
_|$ @
|
||||
|$ @
|
||||
`-$@@
|
||||
|$@
|
||||
|$@
|
||||
|$@
|
||||
|$@@
|
||||
-.$ @
|
||||
|_$@
|
||||
|$ @
|
||||
-'$ @@
|
||||
/\/$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
o o$@
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
o_o$@
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
o o$@
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
o o$@
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
o o$@
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
o o$@
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
_$ @
|
||||
| )$@
|
||||
| )$@
|
||||
|$ @@
|
||||
160 NO-BREAK SPACE
|
||||
$$@
|
||||
$$@
|
||||
$$@
|
||||
$$@@
|
||||
161 INVERTED EXCLAMATION MARK
|
||||
@
|
||||
o$@
|
||||
|$@
|
||||
@@
|
||||
162 CENT SIGN
|
||||
@
|
||||
|_$@
|
||||
(__$@
|
||||
|$ @@
|
||||
163 POUND SIGN
|
||||
_$ @
|
||||
_/_`$ @
|
||||
|___$@
|
||||
@@
|
||||
164 CURRENCY SIGN
|
||||
@
|
||||
`o'$@
|
||||
' `$@
|
||||
@@
|
||||
165 YEN SIGN
|
||||
@
|
||||
_\_/_$@
|
||||
--|--$@
|
||||
@@
|
||||
166 BROKEN BAR
|
||||
|$@
|
||||
|$@
|
||||
|$@
|
||||
|$@@
|
||||
167 SECTION SIGN
|
||||
_$@
|
||||
($ @
|
||||
()$@
|
||||
_)$@@
|
||||
168 DIAERESIS
|
||||
o o$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
169 COPYRIGHT SIGN
|
||||
_$ @
|
||||
|C|$@
|
||||
`-'$@
|
||||
@@
|
||||
170 FEMININE ORDINAL INDICATOR
|
||||
_.$@
|
||||
(_|$@
|
||||
---$@
|
||||
@@
|
||||
171 LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
@
|
||||
//$@
|
||||
\\$@
|
||||
@@
|
||||
172 NOT SIGN
|
||||
@
|
||||
__$ @
|
||||
|$@
|
||||
@@
|
||||
173 SOFT HYPHEN
|
||||
@
|
||||
_$@
|
||||
@
|
||||
@@
|
||||
174 REGISTERED SIGN
|
||||
_$ @
|
||||
|R|$@
|
||||
`-'$@
|
||||
@@
|
||||
175 MACRON
|
||||
__$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
176 DEGREE SIGN
|
||||
O$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
177 PLUS-MINUS SIGN
|
||||
@
|
||||
_|_$@
|
||||
_|_$@
|
||||
@@
|
||||
178 SUPERSCRIPT TWO
|
||||
2$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
179 SUPERSCRIPT THREE
|
||||
3$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
180 ACUTE ACCENT
|
||||
/$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
181 MICRO SIGN
|
||||
@
|
||||
@
|
||||
|_|$@
|
||||
|$ @@
|
||||
182 PILCROW SIGN
|
||||
__$ @
|
||||
(| |$@
|
||||
| |$@
|
||||
@@
|
||||
183 MIDDLE DOT
|
||||
@
|
||||
o$@
|
||||
@
|
||||
@@
|
||||
184 CEDILLA
|
||||
@
|
||||
@
|
||||
@
|
||||
S$@@
|
||||
185 SUPERSCRIPT ONE
|
||||
1$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
186 MASCULINE ORDINAL INDICATOR
|
||||
_$ @
|
||||
(_)$@
|
||||
---$@
|
||||
@@
|
||||
187 RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
@
|
||||
\\$@
|
||||
//$@
|
||||
@@
|
||||
188 VULGAR FRACTION ONE QUARTER
|
||||
@
|
||||
1/$@
|
||||
/4$@
|
||||
@@
|
||||
189 VULGAR FRACTION ONE HALF
|
||||
@
|
||||
1/$@
|
||||
/2$@
|
||||
@@
|
||||
190 VULGAR FRACTION THREE QUARTERS
|
||||
@
|
||||
3/$@
|
||||
/4$@
|
||||
@@
|
||||
191 INVERTED QUESTION MARK
|
||||
@
|
||||
o$@
|
||||
(_$@
|
||||
@@
|
||||
192 LATIN CAPITAL LETTER A WITH GRAVE
|
||||
\$ @
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
193 LATIN CAPITAL LETTER A WITH ACUTE
|
||||
/$ @
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
194 LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
/\$ @
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
195 LATIN CAPITAL LETTER A WITH TILDE
|
||||
/\/$@
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
196 LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
o o$@
|
||||
/\$ @
|
||||
/--\$@
|
||||
@@
|
||||
197 LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
O$ @
|
||||
/ \$ @
|
||||
/---\$@
|
||||
@@
|
||||
198 LATIN CAPITAL LETTER AE
|
||||
_$@
|
||||
/|_$@
|
||||
/-|_$@
|
||||
@@
|
||||
199 LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
_$@
|
||||
/$ @
|
||||
\_$@
|
||||
S$@@
|
||||
200 LATIN CAPITAL LETTER E WITH GRAVE
|
||||
\_$@
|
||||
|_$@
|
||||
|_$@
|
||||
@@
|
||||
201 LATIN CAPITAL LETTER E WITH ACUTE
|
||||
_/$@
|
||||
|_$ @
|
||||
|_$ @
|
||||
@@
|
||||
202 LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
/\$@
|
||||
|_$ @
|
||||
|_$ @
|
||||
@@
|
||||
203 LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
o_o$@
|
||||
|_$ @
|
||||
|_$ @
|
||||
@@
|
||||
204 LATIN CAPITAL LETTER I WITH GRAVE
|
||||
\__$@
|
||||
|$ @
|
||||
_|_$@
|
||||
@@
|
||||
205 LATIN CAPITAL LETTER I WITH ACUTE
|
||||
__/$@
|
||||
|$ @
|
||||
_|_$@
|
||||
@@
|
||||
206 LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
/\$@
|
||||
___$@
|
||||
_|_$@
|
||||
@@
|
||||
207 LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
o_o$@
|
||||
|$ @
|
||||
_|_$@
|
||||
@@
|
||||
208 LATIN CAPITAL LETTER ETH
|
||||
_$ @
|
||||
_|_\$@
|
||||
|_/$@
|
||||
@@
|
||||
209 LATIN CAPITAL LETTER N WITH TILDE
|
||||
/\/$@
|
||||
|\ |$@
|
||||
| \|$@
|
||||
@@
|
||||
210 LATIN CAPITAL LETTER O WITH GRAVE
|
||||
\$ @
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
211 LATIN CAPITAL LETTER O WITH ACUTE
|
||||
/$ @
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
212 LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
/\$@
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
213 LATIN CAPITAL LETTER O WITH TILDE
|
||||
/\/$@
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
214 LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
o_o$@
|
||||
/ \$@
|
||||
\_/$@
|
||||
@@
|
||||
215 MULTIPLICATION SIGN
|
||||
@
|
||||
@
|
||||
X$@
|
||||
@@
|
||||
216 LATIN CAPITAL LETTER O WITH STROKE
|
||||
__$ @
|
||||
/ /\$@
|
||||
\/_/$@
|
||||
@@
|
||||
217 LATIN CAPITAL LETTER U WITH GRAVE
|
||||
\$ @
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
218 LATIN CAPITAL LETTER U WITH ACUTE
|
||||
/$ @
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
219 LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
/\$@
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
220 LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
o o$@
|
||||
| |$@
|
||||
|_|$@
|
||||
@@
|
||||
221 LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
/$ @
|
||||
\_/$@
|
||||
|$ @
|
||||
@@
|
||||
222 LATIN CAPITAL LETTER THORN
|
||||
|_$ @
|
||||
|_)$@
|
||||
|$ @
|
||||
@@
|
||||
223 LATIN SMALL LETTER SHARP S
|
||||
_$ @
|
||||
| )$@
|
||||
| )$@
|
||||
|$ @@
|
||||
224 LATIN SMALL LETTER A WITH GRAVE
|
||||
\$ @
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
225 LATIN SMALL LETTER A WITH ACUTE
|
||||
/$ @
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
226 LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
/\$@
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
227 LATIN SMALL LETTER A WITH TILDE
|
||||
/\/$@
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
228 LATIN SMALL LETTER A WITH DIAERESIS
|
||||
o o$@
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
229 LATIN SMALL LETTER A WITH RING ABOVE
|
||||
O$ @
|
||||
_.$@
|
||||
(_|$@
|
||||
@@
|
||||
230 LATIN SMALL LETTER AE
|
||||
@
|
||||
___$ @
|
||||
(_|/_$@
|
||||
@@
|
||||
231 LATIN SMALL LETTER C WITH CEDILLA
|
||||
@
|
||||
_$@
|
||||
(_$@
|
||||
S$@@
|
||||
232 LATIN SMALL LETTER E WITH GRAVE
|
||||
\$ @
|
||||
_$ @
|
||||
(/_$@
|
||||
@@
|
||||
233 LATIN SMALL LETTER E WITH ACUTE
|
||||
/$ @
|
||||
_$ @
|
||||
(/_$@
|
||||
@@
|
||||
234 LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
/\$@
|
||||
_$ @
|
||||
(/_$@
|
||||
@@
|
||||
235 LATIN SMALL LETTER E WITH DIAERESIS
|
||||
o o$@
|
||||
_$ @
|
||||
(/_$@
|
||||
@@
|
||||
236 LATIN SMALL LETTER I WITH GRAVE
|
||||
\$@
|
||||
@
|
||||
|$@
|
||||
@@
|
||||
237 LATIN SMALL LETTER I WITH ACUTE
|
||||
/$@
|
||||
@
|
||||
|$@
|
||||
@@
|
||||
238 LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
/\$@
|
||||
@
|
||||
|$ @
|
||||
@@
|
||||
239 LATIN SMALL LETTER I WITH DIAERESIS
|
||||
o o$@
|
||||
@
|
||||
|$ @
|
||||
@@
|
||||
240 LATIN SMALL LETTER ETH
|
||||
X$ @
|
||||
\$ @
|
||||
(_|$@
|
||||
@@
|
||||
241 LATIN SMALL LETTER N WITH TILDE
|
||||
/\/$@
|
||||
._$ @
|
||||
| |$@
|
||||
@@
|
||||
242 LATIN SMALL LETTER O WITH GRAVE
|
||||
\$ @
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
243 LATIN SMALL LETTER O WITH ACUTE
|
||||
/$ @
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
244 LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
/\$@
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
245 LATIN SMALL LETTER O WITH TILDE
|
||||
/\/$@
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
246 LATIN SMALL LETTER O WITH DIAERESIS
|
||||
o o$@
|
||||
_$ @
|
||||
(_)$@
|
||||
@@
|
||||
247 DIVISION SIGN
|
||||
o$ @
|
||||
---$@
|
||||
o$ @
|
||||
@@
|
||||
248 LATIN SMALL LETTER O WITH STROKE
|
||||
@
|
||||
_$ @
|
||||
(/)$@
|
||||
@@
|
||||
249 LATIN SMALL LETTER U WITH GRAVE
|
||||
\$ @
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
250 LATIN SMALL LETTER U WITH ACUTE
|
||||
/$ @
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
251 LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
/\$@
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
252 LATIN SMALL LETTER U WITH DIAERESIS
|
||||
o o$@
|
||||
@
|
||||
|_|$@
|
||||
@@
|
||||
253 LATIN SMALL LETTER Y WITH ACUTE
|
||||
/$@
|
||||
@
|
||||
\/$@
|
||||
/$ @@
|
||||
254 LATIN SMALL LETTER THORN
|
||||
@
|
||||
|_$ @
|
||||
|_)$@
|
||||
|$ @@
|
||||
255 LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
oo$@
|
||||
@
|
||||
\/$@
|
||||
/$ @@
|
||||
1493
cosmic rage/fonts/script.flf
Normal file
1493
cosmic rage/fonts/script.flf
Normal file
File diff suppressed because it is too large
Load Diff
1097
cosmic rage/fonts/shadow.flf
Normal file
1097
cosmic rage/fonts/shadow.flf
Normal file
File diff suppressed because it is too large
Load Diff
1295
cosmic rage/fonts/slant.flf
Normal file
1295
cosmic rage/fonts/slant.flf
Normal file
File diff suppressed because it is too large
Load Diff
1097
cosmic rage/fonts/small.flf
Normal file
1097
cosmic rage/fonts/small.flf
Normal file
File diff suppressed because it is too large
Load Diff
1097
cosmic rage/fonts/smscript.flf
Normal file
1097
cosmic rage/fonts/smscript.flf
Normal file
File diff suppressed because it is too large
Load Diff
899
cosmic rage/fonts/smshadow.flf
Normal file
899
cosmic rage/fonts/smshadow.flf
Normal file
@@ -0,0 +1,899 @@
|
||||
flf2a$ 4 3 14 0 10 0 1920 96
|
||||
SmShadow by Glenn Chappell 4/93 -- based on Small
|
||||
Includes ISO Latin-1
|
||||
figlet release 2.1 -- 12 Aug 1994
|
||||
Permission is hereby given to modify this font, as long as the
|
||||
modifier's name is placed on a comment line.
|
||||
|
||||
Modified by Paul Burton <solution@earthlink.net> 12/96 to include new parameter
|
||||
supported by FIGlet and FIGWin. May also be slightly modified for better use
|
||||
of new full-width/kern/smush alternatives, but default output is NOT changed.
|
||||
|
||||
$$@
|
||||
$$@
|
||||
$$@
|
||||
$$@@
|
||||
|$@
|
||||
_|$@
|
||||
_)$@
|
||||
@@
|
||||
| )$@
|
||||
V V$ @
|
||||
@
|
||||
@@
|
||||
| |$ @
|
||||
_ |_ |_|$@
|
||||
_ |_ |_|$@
|
||||
_| _|$ @@
|
||||
|$ @
|
||||
(_-<$@
|
||||
_ _/$@
|
||||
_|$ @@
|
||||
_) /$ @
|
||||
/$ @
|
||||
_/ _)$@
|
||||
@@
|
||||
_|$ @
|
||||
_| _|$@
|
||||
\____|$ @
|
||||
@@
|
||||
)$@
|
||||
/$ @
|
||||
@
|
||||
@@
|
||||
/$@
|
||||
|$ @
|
||||
|$ @
|
||||
\_\$@@
|
||||
\ \$ @
|
||||
|$@
|
||||
|$@
|
||||
_/$ @@
|
||||
\ \ /$ @
|
||||
_ _|$@
|
||||
_/ _\$ @
|
||||
@@
|
||||
|$ @
|
||||
__ __|$@
|
||||
_|$ @
|
||||
@@
|
||||
@
|
||||
@
|
||||
)$@
|
||||
/$ @@
|
||||
@
|
||||
____|$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
@
|
||||
_)$@
|
||||
@@
|
||||
/$@
|
||||
/$ @
|
||||
_/$ @
|
||||
@@
|
||||
\$ @
|
||||
( |$@
|
||||
\__/$ @
|
||||
@@
|
||||
_ |$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
_ )$@
|
||||
/$ @
|
||||
___|$@
|
||||
@@
|
||||
__ /$@
|
||||
_ \$@
|
||||
___/$@
|
||||
@@
|
||||
| |$ @
|
||||
__ _|$@
|
||||
_|$ @
|
||||
@@
|
||||
__|$@
|
||||
__ \$@
|
||||
___/$@
|
||||
@@
|
||||
/$ @
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
__ /$@
|
||||
/$ @
|
||||
_/$ @
|
||||
@@
|
||||
_ )$@
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
_ \$@
|
||||
\_ /$@
|
||||
_/$ @
|
||||
@@
|
||||
_)$@
|
||||
@
|
||||
_)$@
|
||||
@@
|
||||
_)$@
|
||||
@
|
||||
)$@
|
||||
/$ @@
|
||||
/$@
|
||||
< <$ @
|
||||
\_\$@
|
||||
@@
|
||||
@
|
||||
____|$@
|
||||
____|$@
|
||||
@@
|
||||
\ \$ @
|
||||
> >$@
|
||||
_/$ @
|
||||
@@
|
||||
__ \$@
|
||||
_/$@
|
||||
_)$ @
|
||||
@@
|
||||
__ \$ @
|
||||
/ _` |$@
|
||||
\__,_|$@
|
||||
\____/$ @@
|
||||
\$ @
|
||||
_ \$ @
|
||||
_/ _\$@
|
||||
@@
|
||||
_ )$@
|
||||
_ \$@
|
||||
___/$@
|
||||
@@
|
||||
__|$@
|
||||
($ @
|
||||
\___|$@
|
||||
@@
|
||||
_ \$ @
|
||||
| |$@
|
||||
___/$ @
|
||||
@@
|
||||
__|$@
|
||||
_|$ @
|
||||
___|$@
|
||||
@@
|
||||
__|$@
|
||||
_|$ @
|
||||
_|$ @
|
||||
@@
|
||||
__|$@
|
||||
(_ |$@
|
||||
\___|$@
|
||||
@@
|
||||
| |$@
|
||||
__ |$@
|
||||
_| _|$@
|
||||
@@
|
||||
_ _|$@
|
||||
|$ @
|
||||
___|$@
|
||||
@@
|
||||
|$@
|
||||
\ |$@
|
||||
\__/$ @
|
||||
@@
|
||||
| /$@
|
||||
. <$ @
|
||||
_|\_\$@
|
||||
@@
|
||||
|$ @
|
||||
|$ @
|
||||
____|$@
|
||||
@@
|
||||
\ |$@
|
||||
|\/ |$@
|
||||
_| _|$@
|
||||
@@
|
||||
\ |$@
|
||||
. |$@
|
||||
_|\_|$@
|
||||
@@
|
||||
_ \$ @
|
||||
( |$@
|
||||
\___/$ @
|
||||
@@
|
||||
_ \$@
|
||||
__/$@
|
||||
_|$ @
|
||||
@@
|
||||
_ \$ @
|
||||
( |$@
|
||||
\__\_\$@
|
||||
@@
|
||||
_ \$@
|
||||
/$@
|
||||
_|_\$@
|
||||
@@
|
||||
__|$@
|
||||
\__ \$@
|
||||
____/$@
|
||||
@@
|
||||
__ __|$@
|
||||
|$ @
|
||||
_|$ @
|
||||
@@
|
||||
| |$@
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
\ \ /$@
|
||||
\ \ /$ @
|
||||
\_/$ @
|
||||
@@
|
||||
\ \ /$@
|
||||
\ \ \ /$ @
|
||||
\_/\_/$ @
|
||||
@@
|
||||
\ \ /$@
|
||||
> <$ @
|
||||
_/\_\$@
|
||||
@@
|
||||
\ \ /$@
|
||||
\ /$ @
|
||||
_|$ @
|
||||
@@
|
||||
__ /$@
|
||||
/$ @
|
||||
____|$@
|
||||
@@
|
||||
_|$@
|
||||
|$ @
|
||||
|$ @
|
||||
__|$@@
|
||||
\ \$ @
|
||||
\ \$ @
|
||||
\_\$@
|
||||
@@
|
||||
_ |$@
|
||||
|$@
|
||||
|$@
|
||||
__|$@@
|
||||
\$ @
|
||||
/\|$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
@
|
||||
@
|
||||
____|$@@
|
||||
)$@
|
||||
\|$@
|
||||
@
|
||||
@@
|
||||
@
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
|$ @
|
||||
_ \$@
|
||||
_.__/$@
|
||||
@@
|
||||
@
|
||||
_|$@
|
||||
\__|$@
|
||||
@@
|
||||
|$@
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
@
|
||||
-_)$@
|
||||
\___|$@
|
||||
@@
|
||||
_|$@
|
||||
_|$@
|
||||
_|$ @
|
||||
@@
|
||||
@
|
||||
_` |$@
|
||||
\__, |$@
|
||||
____/$ @@
|
||||
|$ @
|
||||
\$ @
|
||||
_| _|$@
|
||||
@@
|
||||
_)$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
_)$@
|
||||
|$@
|
||||
|$@
|
||||
__/$ @@
|
||||
|$ @
|
||||
| /$@
|
||||
_\_\$@
|
||||
@@
|
||||
|$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
@
|
||||
` \$ @
|
||||
_|_|_|$@
|
||||
@@
|
||||
@
|
||||
\$ @
|
||||
_| _|$@
|
||||
@@
|
||||
@
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
@
|
||||
_ \$@
|
||||
.__/$@
|
||||
_|$ @@
|
||||
@
|
||||
_` |$@
|
||||
\__, |$@
|
||||
_|$@@
|
||||
@
|
||||
_|$@
|
||||
_|$ @
|
||||
@@
|
||||
@
|
||||
(_-<$@
|
||||
___/$@
|
||||
@@
|
||||
|$ @
|
||||
_|$@
|
||||
\__|$@
|
||||
@@
|
||||
@
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
@
|
||||
\ \ /$@
|
||||
\_/$ @
|
||||
@@
|
||||
@
|
||||
\ \ \ /$@
|
||||
\_/\_/$ @
|
||||
@@
|
||||
@
|
||||
\ \ /$@
|
||||
_\_\$@
|
||||
@@
|
||||
@
|
||||
| |$@
|
||||
\_, |$@
|
||||
___/$ @@
|
||||
@
|
||||
_ /$@
|
||||
___|$@
|
||||
@@
|
||||
/$@
|
||||
_ |$ @
|
||||
|$ @
|
||||
\_\$@@
|
||||
|$@
|
||||
|$@
|
||||
|$@
|
||||
_|$@@
|
||||
\ \$ @
|
||||
|_$@
|
||||
|$ @
|
||||
_/$ @@
|
||||
\ |$@
|
||||
/\/$ @
|
||||
@
|
||||
@@
|
||||
_) \_)$@
|
||||
_ \$ @
|
||||
/ _\$@
|
||||
@@
|
||||
_) _)$@
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
_) _)$@
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
_) _)$@
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
_) _)$@
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
_) _)$@
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
_ \$@
|
||||
|< <$@
|
||||
|__/$@
|
||||
_|$ @@
|
||||
160 NO-BREAK SPACE
|
||||
$$@
|
||||
$$@
|
||||
$$@
|
||||
$$@@
|
||||
161 INVERTED EXCLAMATION MARK
|
||||
_)$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
162 CENT SIGN
|
||||
|$ @
|
||||
_)$@
|
||||
\ _)$@
|
||||
|$ @@
|
||||
163 POUND SIGN
|
||||
_\$ @
|
||||
_ _|$ @
|
||||
_,___|$@
|
||||
@@
|
||||
164 CURRENCY SIGN
|
||||
\ . /$@
|
||||
_ \$@
|
||||
\/ /$@
|
||||
@@
|
||||
165 YEN SIGN
|
||||
\ \ /$ @
|
||||
__ __|$@
|
||||
__ __|$@
|
||||
_|$ @@
|
||||
166 BROKEN BAR
|
||||
|$@
|
||||
_|$@
|
||||
|$@
|
||||
_|$@@
|
||||
167 SECTION SIGN
|
||||
_)$@
|
||||
\ \$ @
|
||||
\ \/$ @
|
||||
__/$ @@
|
||||
168 DIAERESIS
|
||||
_) _)$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
169 COPYRIGHT SIGN
|
||||
\$ @
|
||||
_| \$@
|
||||
\ \__| /$@
|
||||
\____/$ @@
|
||||
170 FEMININE ORDINAL INDICATOR
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
_____|$@
|
||||
@@
|
||||
171 LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
/ /$@
|
||||
< < <$ @
|
||||
\_\_\$@
|
||||
@@
|
||||
172 NOT SIGN
|
||||
____ |$@
|
||||
_|$@
|
||||
@
|
||||
@@
|
||||
173 SOFT HYPHEN
|
||||
@
|
||||
___|$@
|
||||
@
|
||||
@@
|
||||
174 REGISTERED SIGN
|
||||
\$ @
|
||||
-) \$@
|
||||
\ |\\ /$@
|
||||
\____/$ @@
|
||||
175 MACRON
|
||||
___|$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
176 DEGREE SIGN
|
||||
.\$@
|
||||
\_/$@
|
||||
@
|
||||
@@
|
||||
177 PLUS-MINUS SIGN
|
||||
|$ @
|
||||
_ _|$@
|
||||
_|$ @
|
||||
_____|$@@
|
||||
178 SUPERSCRIPT TWO
|
||||
_ )$@
|
||||
__|$@
|
||||
@
|
||||
@@
|
||||
179 SUPERSCRIPT THREE
|
||||
_ /$@
|
||||
__)$@
|
||||
@
|
||||
@@
|
||||
180 ACUTE ACCENT
|
||||
_/$@
|
||||
@
|
||||
@
|
||||
@@
|
||||
181 MICRO SIGN
|
||||
@
|
||||
| |$@
|
||||
.,_|$@
|
||||
_|$ @@
|
||||
182 PILCROW SIGN
|
||||
|$@
|
||||
\_ | |$@
|
||||
_|_|$@
|
||||
@@
|
||||
183 MIDDLE DOT
|
||||
@
|
||||
_)$@
|
||||
@
|
||||
@@
|
||||
184 CEDILLA
|
||||
@
|
||||
@
|
||||
@
|
||||
_)$@@
|
||||
185 SUPERSCRIPT ONE
|
||||
_ |$@
|
||||
_|$@
|
||||
@
|
||||
@@
|
||||
186 MASCULINE ORDINAL INDICATOR
|
||||
_ \$@
|
||||
\___/$@
|
||||
____|$@
|
||||
@@
|
||||
187 RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
\ \ \$ @
|
||||
> > >$@
|
||||
_/_/$ @
|
||||
@@
|
||||
188 VULGAR FRACTION ONE QUARTER
|
||||
_ | /$ @
|
||||
_| /_' |$@
|
||||
_/ _|$@
|
||||
@@
|
||||
189 VULGAR FRACTION ONE HALF
|
||||
_ | /$ @
|
||||
_| /_ )$@
|
||||
_/ __|$@
|
||||
@@
|
||||
190 VULGAR FRACTION THREE QUARTERS
|
||||
_ / /$ @
|
||||
__) /_' |$@
|
||||
_/ _|$@
|
||||
@@
|
||||
191 INVERTED QUESTION MARK
|
||||
_)$ @
|
||||
/$ @
|
||||
\___|$@
|
||||
@@
|
||||
192 LATIN CAPITAL LETTER A WITH GRAVE
|
||||
\_\$ @
|
||||
--\$ @
|
||||
_/\_\$@
|
||||
@@
|
||||
193 LATIN CAPITAL LETTER A WITH ACUTE
|
||||
_/$ @
|
||||
--\$ @
|
||||
_/\_\$@
|
||||
@@
|
||||
194 LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
--\$ @
|
||||
_/\_\$@
|
||||
@@
|
||||
195 LATIN CAPITAL LETTER A WITH TILDE
|
||||
/ _/$ @
|
||||
--\$ @
|
||||
_/\_\$@
|
||||
@@
|
||||
196 LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
_) \_)$@
|
||||
_ \$ @
|
||||
/ _\$@
|
||||
@@
|
||||
197 LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
( )$ @
|
||||
_ \$ @
|
||||
_/ _\$@
|
||||
@@
|
||||
198 LATIN CAPITAL LETTER AE
|
||||
, __|$@
|
||||
_ _|$ @
|
||||
_/ ___|$@
|
||||
@@
|
||||
199 LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
|$@
|
||||
($ @
|
||||
\___|$@
|
||||
_)$ @@
|
||||
200 LATIN CAPITAL LETTER E WITH GRAVE
|
||||
\_\$@
|
||||
-<$@
|
||||
__<$@
|
||||
@@
|
||||
201 LATIN CAPITAL LETTER E WITH ACUTE
|
||||
_/$@
|
||||
-<$@
|
||||
__<$@
|
||||
@@
|
||||
202 LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
/\\$@
|
||||
-<$@
|
||||
__<$@
|
||||
@@
|
||||
203 LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
_) _)$@
|
||||
-<$ @
|
||||
__<$ @
|
||||
@@
|
||||
204 LATIN CAPITAL LETTER I WITH GRAVE
|
||||
\_\$ @
|
||||
_ _|$@
|
||||
___|$@
|
||||
@@
|
||||
205 LATIN CAPITAL LETTER I WITH ACUTE
|
||||
_/$ @
|
||||
_ _|$@
|
||||
___|$@
|
||||
@@
|
||||
206 LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
_ _|$@
|
||||
___|$@
|
||||
@@
|
||||
207 LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
_) _)$@
|
||||
_ _|$ @
|
||||
___|$ @
|
||||
@@
|
||||
208 LATIN CAPITAL LETTER ETH
|
||||
_ \$ @
|
||||
_ _| |$@
|
||||
___/$ @
|
||||
@@
|
||||
209 LATIN CAPITAL LETTER N WITH TILDE
|
||||
/ _/$@
|
||||
\ |$@
|
||||
_|\_|$@
|
||||
@@
|
||||
210 LATIN CAPITAL LETTER O WITH GRAVE
|
||||
\_\$ @
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
211 LATIN CAPITAL LETTER O WITH ACUTE
|
||||
_/$ @
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
212 LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
213 LATIN CAPITAL LETTER O WITH TILDE
|
||||
/ _/$ @
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
214 LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
_) _)$@
|
||||
__ \$@
|
||||
\____/$@
|
||||
@@
|
||||
215 MULTIPLICATION SIGN
|
||||
\ \$@
|
||||
, '$@
|
||||
\/\/$@
|
||||
@@
|
||||
216 LATIN CAPITAL LETTER O WITH STROKE
|
||||
_ /\$ @
|
||||
( / |$@
|
||||
\_/__/$ @
|
||||
@@
|
||||
217 LATIN CAPITAL LETTER U WITH GRAVE
|
||||
\_\$ @
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
218 LATIN CAPITAL LETTER U WITH ACUTE
|
||||
_/$ @
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
219 LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
220 LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
_) _)$@
|
||||
| |$@
|
||||
\__/$ @
|
||||
@@
|
||||
221 LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
_/$ @
|
||||
\ \ /$@
|
||||
_|$ @
|
||||
@@
|
||||
222 LATIN CAPITAL LETTER THORN
|
||||
|$ @
|
||||
-_)$@
|
||||
_|$ @
|
||||
@@
|
||||
223 LATIN SMALL LETTER SHARP S
|
||||
_ \$@
|
||||
|< <$@
|
||||
|__/$@
|
||||
_|$ @@
|
||||
224 LATIN SMALL LETTER A WITH GRAVE
|
||||
\_\$ @
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
225 LATIN SMALL LETTER A WITH ACUTE
|
||||
_/$ @
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
226 LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
227 LATIN SMALL LETTER A WITH TILDE
|
||||
/ _/$ @
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
228 LATIN SMALL LETTER A WITH DIAERESIS
|
||||
_) _)$@
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
229 LATIN SMALL LETTER A WITH RING ABOVE
|
||||
( )$ @
|
||||
_` |$@
|
||||
\__,_|$@
|
||||
@@
|
||||
230 LATIN SMALL LETTER AE
|
||||
@
|
||||
_` -_)$@
|
||||
\__,___|$@
|
||||
@@
|
||||
231 LATIN SMALL LETTER C WITH CEDILLA
|
||||
@
|
||||
_|$@
|
||||
\__|$@
|
||||
_)$@@
|
||||
232 LATIN SMALL LETTER E WITH GRAVE
|
||||
\_\$ @
|
||||
-_)$@
|
||||
\___|$@
|
||||
@@
|
||||
233 LATIN SMALL LETTER E WITH ACUTE
|
||||
_/$ @
|
||||
-_)$@
|
||||
\___|$@
|
||||
@@
|
||||
234 LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
-_)$@
|
||||
\___|$@
|
||||
@@
|
||||
235 LATIN SMALL LETTER E WITH DIAERESIS
|
||||
_) _)$@
|
||||
-_)$ @
|
||||
\___|$ @
|
||||
@@
|
||||
236 LATIN SMALL LETTER I WITH GRAVE
|
||||
\_\$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
237 LATIN SMALL LETTER I WITH ACUTE
|
||||
_/$@
|
||||
|$@
|
||||
_|$@
|
||||
@@
|
||||
238 LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
/\\$@
|
||||
|$ @
|
||||
_|$ @
|
||||
@@
|
||||
239 LATIN SMALL LETTER I WITH DIAERESIS
|
||||
_) _)$@
|
||||
|$ @
|
||||
_|$ @
|
||||
@@
|
||||
240 LATIN SMALL LETTER ETH
|
||||
, \'$@
|
||||
_` |$@
|
||||
\___/$ @
|
||||
@@
|
||||
241 LATIN SMALL LETTER N WITH TILDE
|
||||
/ _/$ @
|
||||
' \$ @
|
||||
_| _|$@
|
||||
@@
|
||||
242 LATIN SMALL LETTER O WITH GRAVE
|
||||
\_\$ @
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
243 LATIN SMALL LETTER O WITH ACUTE
|
||||
_/$ @
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
244 LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
245 LATIN SMALL LETTER O WITH TILDE
|
||||
/ _/$@
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
246 LATIN SMALL LETTER O WITH DIAERESIS
|
||||
_) _)$@
|
||||
_ \$@
|
||||
\___/$@
|
||||
@@
|
||||
247 DIVISION SIGN
|
||||
_)$ @
|
||||
___|$@
|
||||
_)$ @
|
||||
@@
|
||||
248 LATIN SMALL LETTER O WITH STROKE
|
||||
@
|
||||
/\$@
|
||||
\_/_/$@
|
||||
@@
|
||||
249 LATIN SMALL LETTER U WITH GRAVE
|
||||
\_\$ @
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
250 LATIN SMALL LETTER U WITH ACUTE
|
||||
_/$ @
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
251 LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
/\\$ @
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
252 LATIN SMALL LETTER U WITH DIAERESIS
|
||||
_) _)$@
|
||||
| |$@
|
||||
\_,_|$@
|
||||
@@
|
||||
253 LATIN SMALL LETTER Y WITH ACUTE
|
||||
_/$ @
|
||||
| |$@
|
||||
\_, |$@
|
||||
___/$ @@
|
||||
254 LATIN SMALL LETTER THORN
|
||||
|$ @
|
||||
'_ \$@
|
||||
.__/$@
|
||||
_|$ @@
|
||||
255 LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
_) _)$@
|
||||
| |$@
|
||||
\_, |$@
|
||||
___/$ @@
|
||||
1097
cosmic rage/fonts/smslant.flf
Normal file
1097
cosmic rage/fonts/smslant.flf
Normal file
File diff suppressed because it is too large
Load Diff
2227
cosmic rage/fonts/standard.flf
Normal file
2227
cosmic rage/fonts/standard.flf
Normal file
File diff suppressed because it is too large
Load Diff
600
cosmic rage/fonts/term.flf
Normal file
600
cosmic rage/fonts/term.flf
Normal file
@@ -0,0 +1,600 @@
|
||||
flf2a 1 1 2 -1 13 0 0 242
|
||||
Terminal by Glenn Chappell 4/93
|
||||
Includes characters 128-255
|
||||
Enhanced for Latin-2,3,4 by John Cowan <cowan@ccil.org>
|
||||
Latin character sets supported only if your screen font does
|
||||
figlet release 2.2 -- November 1996
|
||||
Permission is hereby given to modify this font, as long as the
|
||||
modifier's name is placed on a comment line.
|
||||
|
||||
Double-checked by Paul Burton <solution@earthlink.net> 12/96. Added the new
|
||||
parameter supported by FIGlet and FIGWin. Unlike all other FIGfonts, this one
|
||||
is intended to produce output exactly the same as the input unless a control
|
||||
file is used. Therefore it produces the SAME output for smush, kern or fit.
|
||||
|
||||
@
|
||||
!@
|
||||
"@
|
||||
#@
|
||||
$@
|
||||
%@
|
||||
&@
|
||||
'@
|
||||
(@
|
||||
)@
|
||||
*@
|
||||
+@
|
||||
,@
|
||||
-@
|
||||
.@
|
||||
/@
|
||||
0@
|
||||
1@
|
||||
2@
|
||||
3@
|
||||
4@
|
||||
5@
|
||||
6@
|
||||
7@
|
||||
8@
|
||||
9@
|
||||
:@
|
||||
;@
|
||||
<@
|
||||
=@
|
||||
>@
|
||||
?@
|
||||
@#
|
||||
A@
|
||||
B@
|
||||
C@
|
||||
D@
|
||||
E@
|
||||
F@
|
||||
G@
|
||||
H@
|
||||
I@
|
||||
J@
|
||||
K@
|
||||
L@
|
||||
M@
|
||||
N@
|
||||
O@
|
||||
P@
|
||||
Q@
|
||||
R@
|
||||
S@
|
||||
T@
|
||||
U@
|
||||
V@
|
||||
W@
|
||||
X@
|
||||
Y@
|
||||
Z@
|
||||
[@
|
||||
\@
|
||||
]@
|
||||
^@
|
||||
_@
|
||||
`@
|
||||
a@
|
||||
b@
|
||||
c@
|
||||
d@
|
||||
e@
|
||||
f@
|
||||
g@
|
||||
h@
|
||||
i@
|
||||
j@
|
||||
k@
|
||||
l@
|
||||
m@
|
||||
n@
|
||||
o@
|
||||
p@
|
||||
q@
|
||||
r@
|
||||
s@
|
||||
t@
|
||||
u@
|
||||
v@
|
||||
w@
|
||||
x@
|
||||
y@
|
||||
z@
|
||||
{@
|
||||
|@
|
||||
}@
|
||||
~@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
<EFBFBD>@
|
||||
128
|
||||
<EFBFBD>@
|
||||
129
|
||||
<EFBFBD>@
|
||||
130
|
||||
<EFBFBD>@
|
||||
131
|
||||
<EFBFBD>@
|
||||
132
|
||||
<EFBFBD>@
|
||||
133
|
||||
<EFBFBD>@
|
||||
134
|
||||
<EFBFBD>@
|
||||
135
|
||||
<EFBFBD>@
|
||||
136
|
||||
<EFBFBD>@
|
||||
137
|
||||
<EFBFBD>@
|
||||
138
|
||||
<EFBFBD>@
|
||||
139
|
||||
<EFBFBD>@
|
||||
140
|
||||
<EFBFBD>@
|
||||
141
|
||||
<EFBFBD>@
|
||||
142
|
||||
<EFBFBD>@
|
||||
143
|
||||
<EFBFBD>@
|
||||
144
|
||||
<EFBFBD>@
|
||||
145
|
||||
<EFBFBD>@
|
||||
146
|
||||
<EFBFBD>@
|
||||
147
|
||||
<EFBFBD>@
|
||||
148
|
||||
<EFBFBD>@
|
||||
149
|
||||
<EFBFBD>@
|
||||
150
|
||||
<EFBFBD>@
|
||||
151
|
||||
<EFBFBD>@
|
||||
152
|
||||
<EFBFBD>@
|
||||
153
|
||||
<EFBFBD>@
|
||||
154
|
||||
<EFBFBD>@
|
||||
155
|
||||
<EFBFBD>@
|
||||
156
|
||||
<EFBFBD>@
|
||||
157
|
||||
<EFBFBD>@
|
||||
158
|
||||
<EFBFBD>@
|
||||
159
|
||||
<EFBFBD>@
|
||||
160 NO-BREAK SPACE
|
||||
<EFBFBD>@
|
||||
161 INVERTED EXCLAMATION MARK
|
||||
<EFBFBD>@
|
||||
162 CENT SIGN
|
||||
<EFBFBD>@
|
||||
163 POUND SIGN
|
||||
<EFBFBD>@
|
||||
164 CURRENCY SIGN
|
||||
<EFBFBD>@
|
||||
165 YEN SIGN
|
||||
<EFBFBD>@
|
||||
166 BROKEN BAR
|
||||
<EFBFBD>@
|
||||
167 SECTION SIGN
|
||||
<EFBFBD>@
|
||||
168 DIAERESIS
|
||||
<EFBFBD>@
|
||||
169 COPYRIGHT SIGN
|
||||
<EFBFBD>@
|
||||
170 FEMININE ORDINAL INDICATOR
|
||||
<EFBFBD>@
|
||||
171 LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
<EFBFBD>@
|
||||
172 NOT SIGN
|
||||
<EFBFBD>@
|
||||
173 SOFT HYPHEN
|
||||
<EFBFBD>@
|
||||
174 REGISTERED SIGN
|
||||
<EFBFBD>@
|
||||
175 MACRON
|
||||
<EFBFBD>@
|
||||
176 DEGREE SIGN
|
||||
<EFBFBD>@
|
||||
177 PLUS-MINUS SIGN
|
||||
<EFBFBD>@
|
||||
178 SUPERSCRIPT TWO
|
||||
<EFBFBD>@
|
||||
179 SUPERSCRIPT THREE
|
||||
<EFBFBD>@
|
||||
180 ACUTE ACCENT
|
||||
<EFBFBD>@
|
||||
181 MICRO SIGN
|
||||
<EFBFBD>@
|
||||
182 PILCROW SIGN
|
||||
<EFBFBD>@
|
||||
183 MIDDLE DOT
|
||||
<EFBFBD>@
|
||||
184 CEDILLA
|
||||
<EFBFBD>@
|
||||
185 SUPERSCRIPT ONE
|
||||
<EFBFBD>@
|
||||
186 MASCULINE ORDINAL INDICATOR
|
||||
<EFBFBD>@
|
||||
187 RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
<EFBFBD>@
|
||||
188 VULGAR FRACTION ONE QUARTER
|
||||
<EFBFBD>@
|
||||
189 VULGAR FRACTION ONE HALF
|
||||
<EFBFBD>@
|
||||
190 VULGAR FRACTION THREE QUARTERS
|
||||
<EFBFBD>@
|
||||
191 INVERTED QUESTION MARK
|
||||
<EFBFBD>@
|
||||
192 LATIN CAPITAL LETTER A WITH GRAVE
|
||||
<EFBFBD>@
|
||||
193 LATIN CAPITAL LETTER A WITH ACUTE
|
||||
<EFBFBD>@
|
||||
194 LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
195 LATIN CAPITAL LETTER A WITH TILDE
|
||||
<EFBFBD>@
|
||||
196 LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
197 LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
<EFBFBD>@
|
||||
198 LATIN CAPITAL LETTER AE
|
||||
<EFBFBD>@
|
||||
199 LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
200 LATIN CAPITAL LETTER E WITH GRAVE
|
||||
<EFBFBD>@
|
||||
201 LATIN CAPITAL LETTER E WITH ACUTE
|
||||
<EFBFBD>@
|
||||
202 LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
203 LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
204 LATIN CAPITAL LETTER I WITH GRAVE
|
||||
<EFBFBD>@
|
||||
205 LATIN CAPITAL LETTER I WITH ACUTE
|
||||
<EFBFBD>@
|
||||
206 LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
207 LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
208 LATIN CAPITAL LETTER ETH
|
||||
<EFBFBD>@
|
||||
209 LATIN CAPITAL LETTER N WITH TILDE
|
||||
<EFBFBD>@
|
||||
210 LATIN CAPITAL LETTER O WITH GRAVE
|
||||
<EFBFBD>@
|
||||
211 LATIN CAPITAL LETTER O WITH ACUTE
|
||||
<EFBFBD>@
|
||||
212 LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
213 LATIN CAPITAL LETTER O WITH TILDE
|
||||
<EFBFBD>@
|
||||
214 LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
215 MULTIPLICATION SIGN
|
||||
<EFBFBD>@
|
||||
216 LATIN CAPITAL LETTER O WITH STROKE
|
||||
<EFBFBD>@
|
||||
217 LATIN CAPITAL LETTER U WITH GRAVE
|
||||
<EFBFBD>@
|
||||
218 LATIN CAPITAL LETTER U WITH ACUTE
|
||||
<EFBFBD>@
|
||||
219 LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
220 LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
221 LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
<EFBFBD>@
|
||||
222 LATIN CAPITAL LETTER THORN
|
||||
<EFBFBD>@
|
||||
223 LATIN SMALL LETTER SHARP S
|
||||
<EFBFBD>@
|
||||
224 LATIN SMALL LETTER A WITH GRAVE
|
||||
<EFBFBD>@
|
||||
225 LATIN SMALL LETTER A WITH ACUTE
|
||||
<EFBFBD>@
|
||||
226 LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
227 LATIN SMALL LETTER A WITH TILDE
|
||||
<EFBFBD>@
|
||||
228 LATIN SMALL LETTER A WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
229 LATIN SMALL LETTER A WITH RING ABOVE
|
||||
<EFBFBD>@
|
||||
230 LATIN SMALL LETTER AE
|
||||
<EFBFBD>@
|
||||
231 LATIN SMALL LETTER C WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
232 LATIN SMALL LETTER E WITH GRAVE
|
||||
<EFBFBD>@
|
||||
233 LATIN SMALL LETTER E WITH ACUTE
|
||||
<EFBFBD>@
|
||||
234 LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
235 LATIN SMALL LETTER E WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
236 LATIN SMALL LETTER I WITH GRAVE
|
||||
<EFBFBD>@
|
||||
237 LATIN SMALL LETTER I WITH ACUTE
|
||||
<EFBFBD>@
|
||||
238 LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
239 LATIN SMALL LETTER I WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
240 LATIN SMALL LETTER ETH
|
||||
<EFBFBD>@
|
||||
241 LATIN SMALL LETTER N WITH TILDE
|
||||
<EFBFBD>@
|
||||
242 LATIN SMALL LETTER O WITH GRAVE
|
||||
<EFBFBD>@
|
||||
243 LATIN SMALL LETTER O WITH ACUTE
|
||||
<EFBFBD>@
|
||||
244 LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
245 LATIN SMALL LETTER O WITH TILDE
|
||||
<EFBFBD>@
|
||||
246 LATIN SMALL LETTER O WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
247 DIVISION SIGN
|
||||
<EFBFBD>@
|
||||
248 LATIN SMALL LETTER O WITH STROKE
|
||||
<EFBFBD>@
|
||||
249 LATIN SMALL LETTER U WITH GRAVE
|
||||
<EFBFBD>@
|
||||
250 LATIN SMALL LETTER U WITH ACUTE
|
||||
<EFBFBD>@
|
||||
251 LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
252 LATIN SMALL LETTER U WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
253 LATIN SMALL LETTER Y WITH ACUTE
|
||||
<EFBFBD>@
|
||||
254 LATIN SMALL LETTER THORN
|
||||
<EFBFBD>@
|
||||
255 LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
<EFBFBD>@
|
||||
0x0100 LATIN CAPITAL LETTER A WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x0101 LATIN SMALL LETTER A WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x0102 LATIN CAPITAL LETTER A WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x0103 LATIN SMALL LETTER A WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x0104 LATIN CAPITAL LETTER A WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0105 LATIN SMALL LETTER A WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0106 LATIN CAPITAL LETTER C WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0107 LATIN SMALL LETTER C WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0108 LATIN CAPITAL LETTER C WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x0109 LATIN SMALL LETTER C WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x010A LATIN CAPITAL LETTER C WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x010B LATIN SMALL LETTER C WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x010C LATIN CAPITAL LETTER C WITH CARON
|
||||
<EFBFBD>@
|
||||
0x010D LATIN SMALL LETTER C WITH CARON
|
||||
<EFBFBD>@
|
||||
0x010E LATIN CAPITAL LETTER D WITH CARON
|
||||
<EFBFBD>@
|
||||
0x010F LATIN SMALL LETTER D WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0110 LATIN CAPITAL LETTER D WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0111 LATIN SMALL LETTER D WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0112 LATIN CAPITAL LETTER E WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x0113 LATIN SMALL LETTER E WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x0116 LATIN CAPITAL LETTER E WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x0117 LATIN SMALL LETTER E WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x0118 LATIN CAPITAL LETTER E WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0119 LATIN SMALL LETTER E WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x011A LATIN CAPITAL LETTER E WITH CARON
|
||||
<EFBFBD>@
|
||||
0x011B LATIN SMALL LETTER E WITH CARON
|
||||
<EFBFBD>@
|
||||
0x011C LATIN CAPITAL LETTER G WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x011D LATIN SMALL LETTER G WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x011E LATIN CAPITAL LETTER G WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x011F LATIN SMALL LETTER G WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x0120 LATIN CAPITAL LETTER G WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x0121 LATIN SMALL LETTER G WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x0122 LATIN CAPITAL LETTER G WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0123 LATIN SMALL LETTER G WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0124 LATIN CAPITAL LETTER H WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x0125 LATIN SMALL LETTER H WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x0126 LATIN CAPITAL LETTER H WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0127 LATIN SMALL LETTER H WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0128 LATIN CAPITAL LETTER I WITH TILDE
|
||||
<EFBFBD>@
|
||||
0x0129 LATIN SMALL LETTER I WITH TILDE
|
||||
<EFBFBD>@
|
||||
0x012A LATIN CAPITAL LETTER I WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x012B LATIN SMALL LETTER I WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x012E LATIN CAPITAL LETTER I WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x012F LATIN SMALL LETTER I WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0130 LATIN CAPITAL LETTER I WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x0131 LATIN SMALL LETTER DOTLESS I
|
||||
<EFBFBD>@
|
||||
0x0134 LATIN CAPITAL LETTER J WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x0135 LATIN SMALL LETTER J WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x0136 LATIN CAPITAL LETTER K WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0137 LATIN SMALL LETTER K WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0138 LATIN SMALL LETTER KRA
|
||||
<EFBFBD>@
|
||||
0x0139 LATIN CAPITAL LETTER L WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x013A LATIN SMALL LETTER L WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x013B LATIN CAPITAL LETTER L WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x013C LATIN SMALL LETTER L WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x013D LATIN CAPITAL LETTER L WITH CARON
|
||||
<EFBFBD>@
|
||||
0x013E LATIN SMALL LETTER L WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0141 LATIN CAPITAL LETTER L WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0142 LATIN SMALL LETTER L WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0143 LATIN CAPITAL LETTER N WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0144 LATIN SMALL LETTER N WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0145 LATIN CAPITAL LETTER N WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0146 LATIN SMALL LETTER N WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0147 LATIN CAPITAL LETTER N WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0148 LATIN SMALL LETTER N WITH CARON
|
||||
<EFBFBD>@
|
||||
0x014A LATIN CAPITAL LETTER ENG
|
||||
<EFBFBD>@
|
||||
0x014B LATIN SMALL LETTER ENG
|
||||
<EFBFBD>@
|
||||
0x014C LATIN CAPITAL LETTER O WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x014D LATIN SMALL LETTER O WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x0150 LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
|
||||
<EFBFBD>@
|
||||
0x0151 LATIN SMALL LETTER O WITH DOUBLE ACUTE
|
||||
<EFBFBD>@
|
||||
0x0154 LATIN CAPITAL LETTER R WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0155 LATIN SMALL LETTER R WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x0156 LATIN CAPITAL LETTER R WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0157 LATIN SMALL LETTER R WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0158 LATIN CAPITAL LETTER R WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0159 LATIN SMALL LETTER R WITH CARON
|
||||
<EFBFBD>@
|
||||
0x015A LATIN CAPITAL LETTER S WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x015B LATIN SMALL LETTER S WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x015C LATIN CAPITAL LETTER S WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x015D LATIN SMALL LETTER S WITH CIRCUMFLEX
|
||||
<EFBFBD>@
|
||||
0x015E LATIN CAPITAL LETTER S WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x015F LATIN SMALL LETTER S WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0160 LATIN CAPITAL LETTER S WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0161 LATIN SMALL LETTER S WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0162 LATIN CAPITAL LETTER T WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0163 LATIN SMALL LETTER T WITH CEDILLA
|
||||
<EFBFBD>@
|
||||
0x0164 LATIN CAPITAL LETTER T WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0165 LATIN SMALL LETTER T WITH CARON
|
||||
<EFBFBD>@
|
||||
0x0166 LATIN CAPITAL LETTER T WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0167 LATIN SMALL LETTER T WITH STROKE
|
||||
<EFBFBD>@
|
||||
0x0168 LATIN CAPITAL LETTER U WITH TILDE
|
||||
<EFBFBD>@
|
||||
0x0169 LATIN SMALL LETTER U WITH TILDE
|
||||
<EFBFBD>@
|
||||
0x016A LATIN CAPITAL LETTER U WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x016B LATIN SMALL LETTER U WITH MACRON
|
||||
<EFBFBD>@
|
||||
0x016C LATIN CAPITAL LETTER U WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x016D LATIN SMALL LETTER U WITH BREVE
|
||||
<EFBFBD>@
|
||||
0x016E LATIN CAPITAL LETTER U WITH RING ABOVE
|
||||
<EFBFBD>@
|
||||
0x016F LATIN SMALL LETTER U WITH RING ABOVE
|
||||
<EFBFBD>@
|
||||
0x0170 LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
|
||||
<EFBFBD>@
|
||||
0x0171 LATIN SMALL LETTER U WITH DOUBLE ACUTE
|
||||
<EFBFBD>@
|
||||
0x0172 LATIN CAPITAL LETTER U WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0173 LATIN SMALL LETTER U WITH OGONEK
|
||||
<EFBFBD>@
|
||||
0x0179 LATIN CAPITAL LETTER Z WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x017A LATIN SMALL LETTER Z WITH ACUTE
|
||||
<EFBFBD>@
|
||||
0x017B LATIN CAPITAL LETTER Z WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x017C LATIN SMALL LETTER Z WITH DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x017D LATIN CAPITAL LETTER Z WITH CARON
|
||||
<EFBFBD>@
|
||||
0x017E LATIN SMALL LETTER Z WITH CARON
|
||||
<EFBFBD>@
|
||||
0x02C7 CARON
|
||||
<EFBFBD>@
|
||||
0x02D8 BREVE
|
||||
<EFBFBD>@
|
||||
0x02D9 DOT ABOVE
|
||||
<EFBFBD>@
|
||||
0x02DB OGONEK
|
||||
<EFBFBD>@
|
||||
0x02DD DOUBLE ACUTE ACCENT
|
||||
<EFBFBD>@
|
||||
BIN
cosmic rage/help.db
Normal file
BIN
cosmic rage/help.db
Normal file
Binary file not shown.
38
cosmic rage/license.txt
Normal file
38
cosmic rage/license.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
LICENSE AGREEMENT
|
||||
|
||||
By installing and/or using MUSHclient you agree to the following conditions of use. If you do not agree to them please do not proceed with the installation.
|
||||
|
||||
This agreement is between you, "the User", and the program's author (Nick Gammon), "the Author".
|
||||
|
||||
|
||||
AUTHOR
|
||||
|
||||
MUSHclient has been written by Nick Gammon of Gammon Software Solutions.
|
||||
|
||||
Web page: http://www.gammon.com.au/
|
||||
|
||||
Contact/support: http://www.gammon.com.au/forum/
|
||||
|
||||
|
||||
COPYRIGHT
|
||||
|
||||
MUSHclient is copyright 1995 - 2007 by Nick Gammon. All rights reserved worldwide.
|
||||
|
||||
MUSHclient is not in the public domain and Nick Gammon keeps its copyright.
|
||||
|
||||
|
||||
PERMISSION TO DISTRIBUTE
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
LIMITATION OF LIABILITY
|
||||
|
||||
The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
|
||||
|
||||
|
||||
This document was written on 2nd April 2007.
|
||||
|
||||
(End of agreement)
|
||||
5473
cosmic rage/locale/Localize_template.lua
Normal file
5473
cosmic rage/locale/Localize_template.lua
Normal file
File diff suppressed because it is too large
Load Diff
88
cosmic rage/locale/count_locale_usage.lua
Normal file
88
cosmic rage/locale/count_locale_usage.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
-- make copy of original tables
|
||||
orig_messages = messages
|
||||
orig_formatted = formatted
|
||||
orig_times = times
|
||||
orig_headings = headings
|
||||
|
||||
-- empty them out so __index is triggered
|
||||
-- save original tables so we can look them up eventually
|
||||
|
||||
messages = { _orig = orig_messages }
|
||||
formatted = { _orig = orig_formatted }
|
||||
times = { _orig = orig_times }
|
||||
headings = { _orig = orig_headings }
|
||||
|
||||
counts = {} -- keep counts here
|
||||
|
||||
-- metatable for messages, titles, headings
|
||||
mt_static = {
|
||||
-- called to access an entry
|
||||
__index=
|
||||
function (t, name)
|
||||
local s = rawget (t._orig, name)
|
||||
if s == nil or #s == 0 then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
end -- not translated yet
|
||||
return s
|
||||
end;
|
||||
}
|
||||
|
||||
-- metatable for formatted messages
|
||||
mt_formatted = {
|
||||
-- called to access an entry
|
||||
__index=
|
||||
function (t, name)
|
||||
local f = rawget (t._orig, name)
|
||||
-- no function? not translated then
|
||||
if f == nil then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
return nil
|
||||
end
|
||||
assert (type (f) == "function")
|
||||
|
||||
-- return a function, that will count if the original function
|
||||
-- returns an empty string
|
||||
return function (...)
|
||||
local s = f (...) -- call original function
|
||||
if type (s) ~= "string" or #s == 0 then
|
||||
counts [name] = (counts [name] or 0) + 1
|
||||
end -- not translated
|
||||
return s -- return translated value
|
||||
end -- function
|
||||
end;
|
||||
}
|
||||
|
||||
-- apply the metatables
|
||||
setmetatable (messages, mt_static)
|
||||
setmetatable (times, mt_static)
|
||||
setmetatable (headings, mt_static)
|
||||
setmetatable (formatted, mt_formatted)
|
||||
|
||||
-- the user will call world.TranslateDebug to invoke this
|
||||
function Debug ()
|
||||
|
||||
-- for sorting
|
||||
local t = {}
|
||||
|
||||
-- build into table which can be sorted
|
||||
for k, v in pairs (counts) do
|
||||
table.insert (t, k)
|
||||
end -- for
|
||||
|
||||
-- clear out notepad, make heading
|
||||
utils.appendtonotepad ("translation", "Translation counts\n\n", true)
|
||||
|
||||
-- sort into descending order
|
||||
table.sort (t, function (a, b)
|
||||
return counts [a] > counts [b]
|
||||
end)
|
||||
|
||||
-- display results
|
||||
for k, v in ipairs (t) do
|
||||
utils.appendtonotepad ("translation", string.format ("%4i: %q \n", counts [v], v))
|
||||
end -- for
|
||||
|
||||
end -- Debug
|
||||
|
||||
|
||||
67
cosmic rage/locale/detect_locale_changes.lua
Normal file
67
cosmic rage/locale/detect_locale_changes.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- stuff already localized
|
||||
locale = "en" -- change to suit you
|
||||
|
||||
dofile (locale .. ".lua")
|
||||
|
||||
-- make copy
|
||||
original = {
|
||||
messages = messages,
|
||||
formatted = formatted,
|
||||
times = times,
|
||||
headings = headings
|
||||
}
|
||||
|
||||
messages, formatted, times, headings = nil
|
||||
|
||||
-- from distribution
|
||||
dofile ("Localize_template.lua")
|
||||
|
||||
-- make copy
|
||||
distribution = {
|
||||
messages = messages,
|
||||
formatted = formatted,
|
||||
times = times,
|
||||
headings = headings
|
||||
}
|
||||
|
||||
messages, formatted, times, headings = nil
|
||||
|
||||
function compare_table (name)
|
||||
local count = 0
|
||||
local old = original [name]
|
||||
local new = distribution [name]
|
||||
|
||||
print ("Processing table", name)
|
||||
print ""
|
||||
|
||||
-- new message is in distribution, but not in already localized file
|
||||
for k, v in pairs (new) do
|
||||
if not old [k] then
|
||||
count = count + 1
|
||||
print (string.format (" New message: %q", k))
|
||||
end -- if not there
|
||||
end -- for
|
||||
|
||||
|
||||
print ("Found ", count, " new messages")
|
||||
print ""
|
||||
|
||||
count = 0
|
||||
|
||||
-- old message is in already localized file, but not in distribution
|
||||
for k, v in pairs (old) do
|
||||
if not new [k] then
|
||||
count = count + 1
|
||||
print (string.format (" Deleted message: %q", k))
|
||||
end -- if not there
|
||||
end -- for
|
||||
|
||||
print ("Found ", count, " deleted messages")
|
||||
print ""
|
||||
|
||||
end -- compare_table
|
||||
|
||||
compare_table ("messages")
|
||||
compare_table ("formatted")
|
||||
compare_table ("times")
|
||||
compare_table ("headings")
|
||||
BIN
cosmic rage/locale/en.dll
Normal file
BIN
cosmic rage/locale/en.dll
Normal file
Binary file not shown.
BIN
cosmic rage/locale/en_small.dll
Normal file
BIN
cosmic rage/locale/en_small.dll
Normal file
Binary file not shown.
84
cosmic rage/locale/locale_notes.txt
Normal file
84
cosmic rage/locale/locale_notes.txt
Normal file
@@ -0,0 +1,84 @@
|
||||
Localization notes
|
||||
------------------
|
||||
|
||||
Author: Nick Gammon
|
||||
Date: 18th June 2007
|
||||
Amended: 27th May 2008 to mention large/small monitor handling
|
||||
|
||||
|
||||
In the "locale" directory - which is a subdirectory under where the MUSHclient.exe program is stored, you should find the following files in the standard MUSHclient distribution:
|
||||
|
||||
* locale_notes.txt --> this file
|
||||
|
||||
* Localize_template.lua --> template for creating a new translation file
|
||||
|
||||
* en.dll --> resources for MUSHclient - in English (for screen resolution 1024 x 768 or larger)
|
||||
|
||||
* en_small.dll --> resources for MUSHclient - in English (for small screen resolutions)
|
||||
|
||||
* count_locale_usage.lua --> Lua script for counting which messages need translating the most
|
||||
|
||||
* detect_locale_changes.lua --> Lua script for detecting changes between one MUSHclient distribution and the next
|
||||
|
||||
|
||||
See the following forum posting for detailed descriptions about localizing MUSHclient:
|
||||
|
||||
http://www.gammon.com.au/forum/?id=7953
|
||||
|
||||
|
||||
To localize
|
||||
-----------
|
||||
|
||||
If you are planning to localize to another language, you would take these steps. Let us take French as an example, which has a locale code of FR.
|
||||
|
||||
1. Copy en.dll as fr.dll (make a copy, rename the copy fr.dll)
|
||||
|
||||
NOTE: You now have two resource files (en.dll and en_small.dll). One is designed for small monitors and one for larger ones. Use the appropriate file depending on the size monitor you plan to use.
|
||||
|
||||
|
||||
2. Copy Localize_template.lua as fr.lua (make a copy, rename the copy fr.lua)
|
||||
|
||||
3. Use a resource editor (search the Internet for an appropriate tool) and edit fr.dll, changing menus, dialogs, and string resources to have the appropriate translations.
|
||||
|
||||
An alternative is to download the Visual Studio project which built the resources file, change that with an appropriate tool (eg. Visual Studio) and recompile to build a new DLL from scratch.
|
||||
|
||||
4. Use a text editor (such as Crimson Editor) to edit the fr.lua file, translating the "empty" strings for each message, into French. Read the forum posting mentioned above for how to handle the "formatted" part.
|
||||
|
||||
You can get Crimson Editor from:
|
||||
|
||||
http://www.crimsoneditor.com/
|
||||
|
||||
Make sure you set the Document Encoding type to UTF-8 (w/o BOM).
|
||||
|
||||
----
|
||||
|
||||
To test, change the locale code in the MUSHclient Global Preferences -> General tab, to "FR".
|
||||
|
||||
Then close and re-open MUSHclient. It should now detect the new files and show the translated messages.
|
||||
|
||||
|
||||
|
||||
Counting translation usage
|
||||
--------------------------
|
||||
|
||||
As there are around 750 messages to be translated in the Localize_template.lua file, you may prefer to concentrate on the ones that occur most frequently.
|
||||
|
||||
To find out what they are, edit your xx.lua file (eg. fr.lua) and add this line to the bottom:
|
||||
|
||||
dofile "locale/count_locale_usage.lua"
|
||||
|
||||
This adds the extra debugging code into your local file. Then, after you have been using MUSHclient for a while, you can enter the following script command:
|
||||
|
||||
/TranslateDebug ()
|
||||
|
||||
This will display which messages were called upon to be translated, sorted into most frequent first, to least frequent.
|
||||
|
||||
|
||||
|
||||
Checking if new messages appear
|
||||
-------------------------------
|
||||
|
||||
With each new release of MUSHclient, you can check if new messages have been added to the file Localize_template.lua by running the Lua script detect_locale_changes.lua. This compares the messages in your locale file (eg. en.lua) to the new template file (ie. Localize_template.lua) and reports on any new ones.
|
||||
|
||||
|
||||
|
||||
1678
cosmic rage/lua/InfoBox.lua
Normal file
1678
cosmic rage/lua/InfoBox.lua
Normal file
File diff suppressed because it is too large
Load Diff
158
cosmic rage/lua/addxml.lua
Normal file
158
cosmic rage/lua/addxml.lua
Normal file
@@ -0,0 +1,158 @@
|
||||
-- addxml.lua
|
||||
|
||||
-- lets you add triggers, aliases, timers, macros using XML code
|
||||
--
|
||||
-- See: http://www.gammon.com.au/forum/?id=7123
|
||||
|
||||
--[[
|
||||
|
||||
This lets you add items by simply setting up a table of their attributes and then adding it.
|
||||
|
||||
Exposed functions are:
|
||||
|
||||
addxml.trigger -- add a trigger
|
||||
addxml.alias -- add an alias
|
||||
addxml.timer -- add a timer
|
||||
addxml.macro -- add a macro
|
||||
addxml.save -- convert one of the above back into a table
|
||||
|
||||
Example of adding a trigger:
|
||||
|
||||
require "addxml"
|
||||
addxml.trigger { match = "swordfish",
|
||||
regexp = true,
|
||||
['repeat'] = true, -- repeat is lua keyword
|
||||
send = "hi there",
|
||||
sequence = 50,
|
||||
enabled = true,
|
||||
name = "boris",
|
||||
}
|
||||
|
||||
Example of converting a trigger back into a table:
|
||||
|
||||
require "tprint"
|
||||
require "addxml"
|
||||
tprint (addxml.save ("trigger", "boris"))
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
module (..., package.seeall)
|
||||
|
||||
local html_replacements = {
|
||||
["<"] = "<",
|
||||
[">"] = ">",
|
||||
["&"] = "&",
|
||||
['"'] = """,
|
||||
}
|
||||
|
||||
-- fix text so that < > & and double-quote are escaped
|
||||
local function fixhtml (s)
|
||||
|
||||
return (string.gsub (tostring (s), '[<>&"]',
|
||||
function (str)
|
||||
return html_replacements [str] or str
|
||||
end ))
|
||||
|
||||
end -- fixhtml
|
||||
|
||||
|
||||
local function GeneralAdd (t, which, plural)
|
||||
|
||||
assert (type (t) == "table", "Table must be supplied to add a " .. which)
|
||||
|
||||
local k, v
|
||||
local xml = {}
|
||||
|
||||
local send = fixhtml (t.send or "") -- send is done differently
|
||||
t.send = nil
|
||||
|
||||
-- turn into XML options
|
||||
for k, v in pairs (t) do
|
||||
|
||||
-- fix true/false to y/n
|
||||
if v == true then
|
||||
v = "y"
|
||||
elseif v == false then
|
||||
v = "n"
|
||||
end -- if true or false
|
||||
|
||||
table.insert (xml, k .. '="' .. fixhtml (v) .. '"')
|
||||
end -- for loop
|
||||
|
||||
assert (ImportXML (string.format (
|
||||
"<%s><%s %s ><send>%s</send></%s></%s>",
|
||||
plural, -- eg. triggers
|
||||
which, -- eg. trigger
|
||||
table.concat (xml, "\n"), -- eg. match="nick"
|
||||
send, -- eg. "go north"
|
||||
which, -- eg. trigger
|
||||
plural) -- eg. triggers
|
||||
) == 1, "Import of " .. which .. " failed")
|
||||
|
||||
end -- GeneralAdd
|
||||
|
||||
function trigger (t)
|
||||
GeneralAdd (t, "trigger", "triggers")
|
||||
-- force script entry-point resolution
|
||||
if t.name and t.script then
|
||||
SetTriggerOption (t.name, "script", t.script)
|
||||
end -- if trigger has a name, and a script name
|
||||
end -- addxml.trigger
|
||||
|
||||
function alias (t)
|
||||
GeneralAdd (t, "alias", "aliases")
|
||||
-- force script entry-point resolution
|
||||
if t.name and t.script then
|
||||
SetAliasOption (t.name, "script", t.script)
|
||||
end -- if alias has a name, and a script name
|
||||
end -- addxml.alias
|
||||
|
||||
function timer (t)
|
||||
GeneralAdd (t, "timer", "timers")
|
||||
-- force script entry-point resolution
|
||||
if t.name and t.script then
|
||||
SetTimerOption (t.name, "script", t.script)
|
||||
end -- if timer has a name, and a script name
|
||||
end -- addxml.timer
|
||||
|
||||
function macro (t)
|
||||
GeneralAdd (t, "macro", "macros")
|
||||
end -- addxml.macro
|
||||
|
||||
function save (which, name)
|
||||
|
||||
local typeconversion =
|
||||
{
|
||||
trigger = 0,
|
||||
alias = 1,
|
||||
timer = 2,
|
||||
macro = 3,
|
||||
-- variable = 4,
|
||||
-- keypad = 5
|
||||
}
|
||||
|
||||
local itemtype = assert (typeconversion [which], "Unknown type: " .. which)
|
||||
|
||||
local xml = ExportXML (itemtype, name)
|
||||
|
||||
-- if not found returns empty string
|
||||
assert (xml ~= "", "Can't find " .. which .. ": " .. name)
|
||||
|
||||
-- parse back into table entries
|
||||
local xmlnodes = assert (utils.xmlread (xml), "Bad XML")
|
||||
|
||||
-- all attributes should be a couple of levels down
|
||||
local result = xmlnodes.nodes [1].nodes [1].attributes
|
||||
|
||||
-- find "send" text
|
||||
|
||||
-- another level?
|
||||
if xmlnodes.nodes [1].nodes [1].nodes then
|
||||
if xmlnodes.nodes [1].nodes [1].nodes [1].name == "send" then
|
||||
result.send = xmlnodes.nodes [1].nodes [1].nodes [1].content
|
||||
end -- have a "send" field
|
||||
end -- have a child node
|
||||
|
||||
return result
|
||||
end -- addxml.save
|
||||
80
cosmic rage/lua/alphanum.lua
Normal file
80
cosmic rage/lua/alphanum.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
-- alphanum.lua
|
||||
--
|
||||
-- Adapted somewhat from: http://www.davekoelle.com/files/alphanum.lua
|
||||
-- Also see: http://www.davekoelle.com/alphanum.html
|
||||
--
|
||||
-- Implements a sort function that does a more "human readable" sort order.
|
||||
-- It breaks the sort strings into "chunks" and then compares each one naturally,
|
||||
-- depending on whether it is a string or a number (eg. z9.doc compares less than z20.doc)
|
||||
-- It also does a case-insensitive compare (so "nick" and "Nick" come out together).
|
||||
|
||||
-- See also: http://www.gammon.com.au/forum/?id=8698
|
||||
|
||||
--[[
|
||||
Example:
|
||||
|
||||
require "alphanum"
|
||||
|
||||
t={
|
||||
"z18.doc","z19.doc","z2.doc","z16.doc","z17.doc",
|
||||
"z1.doc","z101.doc","z102.doc","z11.doc","z12.doc",
|
||||
"z13.doc","z14.doc","z15.doc","z20.doc","z3.doc",
|
||||
"z4.doc","z5.doc","z6.doc","z10.doc","z100.doc",
|
||||
"z7.doc","z8.doc","z9.doc", "Z9A.doc",
|
||||
}
|
||||
|
||||
table.sort(t, alphanum (t))
|
||||
|
||||
for i=1, #t do
|
||||
print(t[i])
|
||||
end
|
||||
|
||||
--]]
|
||||
|
||||
function alphanum (t)
|
||||
assert (type (t) == "table", "Must pass table to be sorted to alphanum")
|
||||
|
||||
local function chunkString(str)
|
||||
local c = {}
|
||||
for a, b in tostring (str):gmatch("(%d*)(%D*)") do
|
||||
if a ~= "" then c[#c+1] = tonumber(a) end
|
||||
if b ~= "" then c[#c+1] = b end
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local chunks = {}
|
||||
-- build temporary table of the keys
|
||||
for i=1, #t do
|
||||
chunks [t [i]] = chunkString (t [i])
|
||||
end
|
||||
|
||||
return function (a, b) -- return our sort comparison function
|
||||
|
||||
-- lookup chunked information from previously-built table
|
||||
local achunks = chunks [a]
|
||||
local bchunks = chunks [b]
|
||||
|
||||
for i = 1, math.min (#achunks, #bchunks) do
|
||||
local as, bs = achunks [i], bchunks [i]
|
||||
|
||||
-- if one is a string, make them both strings
|
||||
if type (as) == "string" or type (bs) == "string" then
|
||||
as = (tostring (as)):upper ()
|
||||
bs = (tostring (bs)):upper ()
|
||||
end -- at least one is a string
|
||||
|
||||
-- if they are equal, move onto the next chunk
|
||||
if as ~= bs then
|
||||
return as < bs
|
||||
end -- if
|
||||
end -- for each chunk
|
||||
|
||||
-- still equal? the one with fewer chunks compares less
|
||||
return #achunks < #bchunks
|
||||
|
||||
end -- sort function
|
||||
|
||||
end -- alphanum
|
||||
|
||||
return alphanum
|
||||
29
cosmic rage/lua/check.lua
Normal file
29
cosmic rage/lua/check.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
--
|
||||
-- check.lua
|
||||
--
|
||||
-- ----------------------------------------------------------
|
||||
-- return-code checker for MUSHclient functions that return error codes
|
||||
-- ----------------------------------------------------------
|
||||
--
|
||||
--[[
|
||||
|
||||
Call for those MUSHclient functions that return a result code (like eOK).
|
||||
Not all functions return such a code.
|
||||
|
||||
eg.
|
||||
|
||||
require "check
|
||||
check (SetVariable ("abc", "def")) --> works ok
|
||||
check (SetVariable ("abc-", "def")) --> The name of this object is invalid
|
||||
|
||||
--]]
|
||||
|
||||
function check (result)
|
||||
if result ~= error_code.eOK then
|
||||
error (error_desc [result] or
|
||||
string.format ("Unknown error code: %i", result),
|
||||
2) -- error level - whoever called this function
|
||||
end -- if
|
||||
end -- function check
|
||||
|
||||
return check
|
||||
90
cosmic rage/lua/checkplugin.lua
Normal file
90
cosmic rage/lua/checkplugin.lua
Normal file
@@ -0,0 +1,90 @@
|
||||
-- checkplugin.lua
|
||||
|
||||
-- Checks the nominated plugin is installed
|
||||
|
||||
function do_plugin_check_now (id, name)
|
||||
|
||||
local me -- who am I? plugin or main world script?
|
||||
local location -- location to attempt to load plugin from
|
||||
|
||||
-- allow for being called from main world script
|
||||
if GetPluginID () == "" then
|
||||
me = "world script"
|
||||
location = GetInfo (60)
|
||||
else
|
||||
me = GetPluginName () .. " plugin"
|
||||
location = GetPluginInfo(GetPluginID (), 20)
|
||||
end -- if
|
||||
|
||||
-- first check if installed
|
||||
if not IsPluginInstalled (id) then
|
||||
ColourNote ("white", "green", "Plugin '" .. name .. "' not installed. Attempting to install it...")
|
||||
LoadPlugin (location .. name .. ".xml")
|
||||
|
||||
if IsPluginInstalled (id) then
|
||||
ColourNote ("white", "green", "Success!")
|
||||
|
||||
-- here if still not installed
|
||||
else
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
ColourNote ("white", "red", "Plugin '" .. name .. "' not installed. Please download and install it.")
|
||||
ColourNote ("white", "red", "It is required for the correct operation of the " .. me)
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
return -- skip enabled check
|
||||
end -- if not installed
|
||||
end -- plugin was not installed
|
||||
|
||||
|
||||
-- now make sure enabled (suggested by Fiendish - version 4.74+ )
|
||||
|
||||
if not GetPluginInfo(id, 17) then
|
||||
ColourNote ("white", "green", "Plugin '" .. name .. "' not enabled. Attempting to enable it...")
|
||||
EnablePlugin(id, true)
|
||||
if GetPluginInfo(id, 17) then
|
||||
ColourNote ("white", "green", "Success!")
|
||||
else
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
ColourNote ("white", "red", "Plugin '" .. name .. "' not enabled. Please make sure it can be enabled.")
|
||||
ColourNote ("white", "red", "It is required for the correct operation of the " .. me)
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
end -- if
|
||||
end -- if not enabled
|
||||
|
||||
end -- do_plugin_check_now
|
||||
|
||||
|
||||
function checkplugin (id, name)
|
||||
|
||||
if GetOption ("enable_timers") ~= 1 then
|
||||
ColourNote ("white", "red", "WARNING! Timers not enabled. Plugin dependency checks will not work properly.")
|
||||
end -- if timers disabled
|
||||
|
||||
-- give them time to load
|
||||
DoAfterSpecial (2,
|
||||
"do_plugin_check_now ('" .. id .. "', '" .. name .. "')",
|
||||
sendto.script)
|
||||
end -- checkplugin
|
||||
|
||||
function load_ppi (id, name)
|
||||
local PPI = require "ppi"
|
||||
|
||||
local ppi = PPI.Load(id)
|
||||
if ppi then
|
||||
return ppi
|
||||
end
|
||||
|
||||
ColourNote ("white", "green", "Plugin '" .. name .. "' not installed. Attempting to install it...")
|
||||
LoadPlugin (GetPluginInfo(GetPluginID (), 20) .. name .. ".xml")
|
||||
|
||||
ppi = PPI.Load(id) -- try again
|
||||
if ppi then
|
||||
ColourNote ("white", "green", "Success!")
|
||||
return ppi
|
||||
end
|
||||
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
ColourNote ("white", "red", "Plugin '" .. name .. "' not installed. Please download and install it.")
|
||||
ColourNote ("white", "red", string.rep ("-", 80))
|
||||
|
||||
return nil
|
||||
end -- function load_ppi
|
||||
269
cosmic rage/lua/colors.lua
Normal file
269
cosmic rage/lua/colors.lua
Normal file
@@ -0,0 +1,269 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- Provides support for color manipulation in HSL color space.
|
||||
--
|
||||
-- http://sputnik.freewisdom.org/lib/colors/
|
||||
--
|
||||
-- License: MIT/X
|
||||
--
|
||||
-- (c) 2008 Yuri Takhteyev (yuri@freewisdom.org) *
|
||||
--
|
||||
-- * rgb_to_hsl() implementation was contributed by Markus Fleck-Graffe.
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module(..., package.seeall)
|
||||
|
||||
local Color = {}
|
||||
local Color_mt = {__metatable = {}, __index = Color}
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Instantiates a new "color".
|
||||
--
|
||||
-- @param H hue (0-360) _or_ an RGB string ("#930219")
|
||||
-- @param S saturation (0.0-1.0)
|
||||
-- @param L lightness (0.0-1.0)
|
||||
-- @return an instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function new(H, S, L)
|
||||
if type(H) == "string" and H:sub(1,1)=="#" and H:len() == 7 then
|
||||
H, S, L = rgb_string_to_hsl(H)
|
||||
end
|
||||
assert(Color_mt)
|
||||
return setmetatable({H = H, S = S, L = L}, Color_mt)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Converts an HSL triplet to RGB
|
||||
-- (see http://homepages.cwi.nl/~steven/css/hsl.html).
|
||||
--
|
||||
-- @param h hue (0-360)
|
||||
-- @param s saturation (0.0-1.0)
|
||||
-- @param L lightness (0.0-1.0)
|
||||
-- @return an R, G, and B component of RGB
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
function hsl_to_rgb(h, s, L)
|
||||
h = h/360
|
||||
local m1, m2
|
||||
if L<=0.5 then
|
||||
m2 = L*(s+1)
|
||||
else
|
||||
m2 = L+s-L*s
|
||||
end
|
||||
m1 = L*2-m2
|
||||
|
||||
local function _h2rgb(m1, m2, h)
|
||||
if h<0 then h = h+1 end
|
||||
if h>1 then h = h-1 end
|
||||
if h*6<1 then
|
||||
return m1+(m2-m1)*h*6
|
||||
elseif h*2<1 then
|
||||
return m2
|
||||
elseif h*3<2 then
|
||||
return m1+(m2-m1)*(2/3-h)*6
|
||||
else
|
||||
return m1
|
||||
end
|
||||
end
|
||||
|
||||
return _h2rgb(m1, m2, h+1/3), _h2rgb(m1, m2, h), _h2rgb(m1, m2, h-1/3)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Converts an RGB triplet to HSL.
|
||||
-- (see http://easyrgb.com)
|
||||
--
|
||||
-- @param r red (0.0-1.0)
|
||||
-- @param g green (0.0-1.0)
|
||||
-- @param b blue (0.0-1.0)
|
||||
-- @return corresponding H, S and L components
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
function rgb_to_hsl(r, g, b)
|
||||
--r, g, b = r/255, g/255, b/255
|
||||
local min = math.min(r, g, b)
|
||||
local max = math.max(r, g, b)
|
||||
local delta = max - min
|
||||
|
||||
local h, s, l = 0, 0, ((min+max)/2)
|
||||
|
||||
if l > 0 and l < 0.5 then s = delta/(max+min) end
|
||||
if l >= 0.5 and l < 1 then s = delta/(2-max-min) end
|
||||
|
||||
if delta > 0 then
|
||||
if max == r and max ~= g then h = h + (g-b)/delta end
|
||||
if max == g and max ~= b then h = h + 2 + (b-r)/delta end
|
||||
if max == b and max ~= r then h = h + 4 + (r-g)/delta end
|
||||
h = h / 6;
|
||||
end
|
||||
|
||||
if h < 0 then h = h + 1 end
|
||||
if h > 1 then h = h - 1 end
|
||||
|
||||
return h * 360, s, l
|
||||
end
|
||||
|
||||
function rgb_string_to_hsl(rgb)
|
||||
return rgb_to_hsl(tonumber(rgb:sub(2,3), 16)/255,
|
||||
tonumber(rgb:sub(4,5), 16)/255,
|
||||
tonumber(rgb:sub(6,7), 16)/255)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Converts the color to an RGB string.
|
||||
--
|
||||
-- @return a 6-digit RGB representation of the color prefixed
|
||||
-- with "#" (suitable for inclusion in HTML)
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
function Color:to_rgb()
|
||||
local rgb = {hsl_to_rgb(self.H, self.S, self.L)}
|
||||
local buffer = "#"
|
||||
for i,v in ipairs(rgb) do
|
||||
buffer = buffer..string.format("%02x",math.floor(v*255+0.5))
|
||||
end
|
||||
return buffer
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a new color with hue different by delta.
|
||||
--
|
||||
-- @param delta a delta for hue.
|
||||
-- @return a new instance of Color.
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:hue_offset(delta)
|
||||
return new((self.H + delta) % 360, self.S, self.L)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a complementary color.
|
||||
--
|
||||
-- @return a new instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:complementary()
|
||||
return self:hue_offset(180)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates two neighboring colors (by hue), offset by "angle".
|
||||
--
|
||||
-- @param angle the difference in hue between this color and the
|
||||
-- neighbors
|
||||
-- @return two new instances of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:neighbors(angle)
|
||||
local angle = angle or 30
|
||||
return self:hue_offset(angle), self:hue_offset(360-angle)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates two new colors to make a triadic color scheme.
|
||||
--
|
||||
-- @return two new instances of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:triadic()
|
||||
return self:neighbors(120)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates two new colors, offset by angle from this colors complementary.
|
||||
--
|
||||
-- @param angle the difference in hue between the complementary and
|
||||
-- the returned colors
|
||||
-- @return two new instances of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:split_complementary(angle)
|
||||
return self:neighbors(180-(angle or 30))
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a new color with saturation set to a new value.
|
||||
--
|
||||
-- @param saturation the new saturation value (0.0 - 1.0)
|
||||
-- @return a new instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:desaturate_to(saturation)
|
||||
return new(self.H, saturation, self.L)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a new color with saturation set to a old saturation times r.
|
||||
--
|
||||
-- @param r the multiplier for the new saturation
|
||||
-- @return a new instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:desaturate_by(r)
|
||||
return new(self.H, self.S*r, self.L)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a new color with lightness set to a new value.
|
||||
--
|
||||
-- @param lightness the new lightness value (0.0 - 1.0)
|
||||
-- @return a new instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:lighten_to(lightness)
|
||||
return new(self.H, self.S, lightness)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates a new color with lightness set to a old lightness times r.
|
||||
--
|
||||
-- @param r the multiplier for the new lightness
|
||||
-- @return a new instance of Color
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:lighten_by(r)
|
||||
return new(self.H, self.S, self.L*r)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates n variations of this color using supplied function and returns
|
||||
-- them as a table.
|
||||
--
|
||||
-- @param f the function to create variations
|
||||
-- @param n the number of variations
|
||||
-- @return a table with n values containing the new colors
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:variations(f, n)
|
||||
n = n or 5
|
||||
local results = {}
|
||||
for i=1,n do
|
||||
table.insert(results, f(self, i, n))
|
||||
end
|
||||
return results
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates n tints of this color and returns them as a table
|
||||
--
|
||||
-- @param n the number of tints
|
||||
-- @return a table with n values containing the new colors
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:tints(n)
|
||||
local f = function (color, i, n)
|
||||
return color:lighten_to(color.L + (1-color.L)/n*i)
|
||||
end
|
||||
return self:variations(f, n)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Creates n shades of this color and returns them as a table
|
||||
--
|
||||
-- @param n the number of shades
|
||||
-- @return a table with n values containing the new colors
|
||||
-----------------------------------------------------------------------------
|
||||
function Color:shades(n)
|
||||
local f = function (color, i, n)
|
||||
return color:lighten_to(color.L - (color.L)/n*i)
|
||||
end
|
||||
return self:variations(f, n)
|
||||
end
|
||||
|
||||
function Color:tint(r)
|
||||
return self:lighten_to(self.L + (1-self.L)*r)
|
||||
end
|
||||
|
||||
function Color:shade(r)
|
||||
return self:lighten_to(self.L - self.L*r)
|
||||
end
|
||||
|
||||
Color_mt.__tostring = Color.to_rgb
|
||||
223
cosmic rage/lua/commas.lua
Normal file
223
cosmic rage/lua/commas.lua
Normal file
@@ -0,0 +1,223 @@
|
||||
-- commas.lua
|
||||
-- ----------------------------------------------------------
|
||||
-- Rounding, duration, comma functions
|
||||
-- See forum thread:
|
||||
-- http://www.gammon.com.au/forum/?id=7805
|
||||
|
||||
--[[
|
||||
|
||||
This function rounds any number to the closest integer.
|
||||
The "tricky" case is exactly half-way.
|
||||
That is, should 1.5 round to 1 or 2? How about -1.5?
|
||||
|
||||
This function rounds 1.5 "up" to 2, and -1.5 "down" to -2.
|
||||
|
||||
--]]
|
||||
|
||||
-- ----------------------------------------------------------
|
||||
|
||||
|
||||
-- round "up" to absolute value, so we treat negative differently
|
||||
-- that is, round (-1.5) will return -2
|
||||
|
||||
function round (x)
|
||||
if x >= 0 then
|
||||
return math.floor (x + 0.5)
|
||||
end -- if positive
|
||||
|
||||
return math.ceil (x - 0.5)
|
||||
end -- function round
|
||||
|
||||
--[[
|
||||
|
||||
Duration
|
||||
|
||||
This function is designed to display a time interval in "short form".
|
||||
That is, rounded to the nearest major time interval. Some examples of intervals:
|
||||
|
||||
|
||||
* 3.6 days - displays "4 d"
|
||||
* 3.5 days - displays "4 d"
|
||||
* 3.4 days - displays "3 d"
|
||||
|
||||
* 3.6 hours - displays "4 h"
|
||||
* 3.5 hours - displays "4 h"
|
||||
* 3.4 hours - displays "3 h"
|
||||
|
||||
* 3.6 minutes - displays "4 m"
|
||||
* 3.5 minutes - displays "4 m"
|
||||
* 3.4 minutes - displays "3 m"
|
||||
|
||||
* 59 seconds - displays "59 s"
|
||||
* 58 seconds - displays "58 s"
|
||||
* 57 seconds - displays "57 s" ... and so on to "0 s"
|
||||
|
||||
|
||||
--]]
|
||||
|
||||
-- ----------------------------------------------------------
|
||||
|
||||
function convert_time (secs)
|
||||
|
||||
-- handle negative numbers
|
||||
local sign = ""
|
||||
if secs < 0 then
|
||||
secs = math.abs (secs)
|
||||
sign = "-"
|
||||
end -- if negative seconds
|
||||
|
||||
-- weeks
|
||||
if secs >= (60 * 60 * 24 * 6.5) then
|
||||
return sign .. round (secs / (60 * 60 * 24 * 7)) .. " w"
|
||||
end -- 6.5 or more days
|
||||
|
||||
-- days
|
||||
if secs >= (60 * 60 * 23.5) then
|
||||
return sign .. round (secs / (60 * 60 * 24)) .. " d"
|
||||
end -- 23.5 or more hours
|
||||
|
||||
-- hours
|
||||
if secs >= (60 * 59.5) then
|
||||
return sign .. round (secs / (60 * 60)) .. " h"
|
||||
end -- 59.5 or more minutes
|
||||
|
||||
-- minutes
|
||||
if secs >= 59.5 then
|
||||
return sign .. round (secs / 60) .. " m"
|
||||
end -- 59.5 or more seconds
|
||||
|
||||
-- seconds
|
||||
return sign .. round (secs) .. " s"
|
||||
end -- function convert_time
|
||||
|
||||
--[[
|
||||
|
||||
Commas in numbers
|
||||
|
||||
This function adds commas to big numbers.
|
||||
For example 123456 becomes "123,456".
|
||||
|
||||
--]]
|
||||
|
||||
-- ----------------------------------------------------------
|
||||
|
||||
function commas (num)
|
||||
assert (type (num) == "number" or
|
||||
type (num) == "string")
|
||||
|
||||
local result = ""
|
||||
|
||||
-- split number into 3 parts, eg. -1234.545e22
|
||||
-- sign = + or -
|
||||
-- before = 1234
|
||||
-- after = .545e22
|
||||
|
||||
local sign, before, after =
|
||||
string.match (tostring (num), "^([%+%-]?)(%d*)(%.?.*)$")
|
||||
|
||||
-- pull out batches of 3 digits from the end, put a comma before them
|
||||
|
||||
while string.len (before) > 3 do
|
||||
result = "," .. string.sub (before, -3, -1) .. result
|
||||
before = string.sub (before, 1, -4) -- remove last 3 digits
|
||||
end -- while
|
||||
|
||||
-- we want the original sign, any left-over digits, the comma part,
|
||||
-- and the stuff after the decimal point, if any
|
||||
return sign .. before .. result .. after
|
||||
|
||||
end -- function commas
|
||||
|
||||
|
||||
-- trim leading and trailing spaces from a string
|
||||
function trim (s)
|
||||
return (string.gsub (s, "^%s*(.-)%s*$", "%1"))
|
||||
end -- trim
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
Shuffle a table
|
||||
|
||||
-- see: http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
|
||||
|
||||
Example:
|
||||
|
||||
cards = { "Ace", "King", "Queen", "Jack", 10, 9, 8, 7, 6, 5, 4, 3, 2 }
|
||||
|
||||
shuffle (cards)
|
||||
|
||||
--]]
|
||||
|
||||
function shuffle(t)
|
||||
local n = #t
|
||||
|
||||
while n >= 2 do
|
||||
-- n is now the last pertinent index
|
||||
local k = math.random(n) -- 1 <= k <= n
|
||||
-- Quick swap
|
||||
t[n], t[k] = t[k], t[n]
|
||||
n = n - 1
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
Directory scanner.
|
||||
|
||||
Calls function "f" for every file found in a path starting at "path".
|
||||
Recurses to handle nested directories. Function "f" is called with two
|
||||
arguments: (full) filename, statistics
|
||||
|
||||
See utils.readdir for the exact names of the entries supplied for each file.
|
||||
|
||||
See: http://www.gammon.com.au/forum/?id=9906
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
plugins = {}
|
||||
|
||||
-- this function is called for every found file
|
||||
function load_file (name, stats)
|
||||
|
||||
if stats.size > 0 and
|
||||
string.match (name:lower (), "%.xml$") and
|
||||
not stats.hidden then
|
||||
table.insert (plugins, name)
|
||||
end -- if
|
||||
|
||||
end -- load_file
|
||||
|
||||
-- Scan plugins folder, passing each file found to "load_file" function.
|
||||
|
||||
scan_dir (GetInfo (60), load_file)
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
function scan_dir (path, f)
|
||||
|
||||
-- find all files in that directory
|
||||
local t = assert (utils.readdir (path .. "\\*"))
|
||||
|
||||
for k, v in pairs (t) do
|
||||
|
||||
-- recurse to process subdirectory
|
||||
if v.directory then
|
||||
|
||||
if k ~= "." and k ~= ".." then
|
||||
scan_dir (path .. "\\" .. k, f)
|
||||
end -- not current or owner directory
|
||||
|
||||
else -- call supplied function
|
||||
f (path .. "\\" .. k, v)
|
||||
end -- if
|
||||
|
||||
end -- for
|
||||
|
||||
end -- scan_dir
|
||||
89
cosmic rage/lua/copytable.lua
Normal file
89
cosmic rage/lua/copytable.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
-- copytable.lua
|
||||
|
||||
--[[
|
||||
|
||||
Table copying functions.
|
||||
|
||||
See: http://www.gammon.com.au/forum/?id=8042
|
||||
|
||||
Ideas by Shaun Biggs, David Haley, Nick Gammon
|
||||
|
||||
Date: 21st July 2007
|
||||
|
||||
This is intended to copy tables (make a real copy, rather than just the table
|
||||
reference).
|
||||
|
||||
You can do a deep or shallow copy.
|
||||
|
||||
Shallow: Simply copies the keys and values.
|
||||
If a value is a table, you will get the same table as in the original.
|
||||
|
||||
Deep: Copies keys and values recursively.
|
||||
If a value is a table, makes a copy of that table, and so on.
|
||||
|
||||
Deep copy based on: http://lua-users.org/wiki/CopyTable
|
||||
|
||||
Restrictions: Items must be "safe" to copy (eg. not file IO userdata).
|
||||
|
||||
The deep copied tables share the same metatable as the original ones.
|
||||
To change this, change the line:
|
||||
|
||||
return setmetatable(new_table, getmetatable(object))
|
||||
|
||||
to:
|
||||
|
||||
return setmetatable(new_table, _copy (getmetatable(object))
|
||||
|
||||
Example:
|
||||
|
||||
t1 = {
|
||||
m = { a = 1, b = 2 },
|
||||
n = { c = 3, d = 4 },
|
||||
}
|
||||
|
||||
require "copytable" -- load this file
|
||||
|
||||
t2 = copytable.shallow (t1) -- shallow copy
|
||||
t3 = copytable.deep (t1) -- copies sub tables as well
|
||||
|
||||
--]]
|
||||
|
||||
module (..., package.seeall)
|
||||
|
||||
|
||||
function deep (object)
|
||||
local lookup_table = {}
|
||||
|
||||
local function _copy (object)
|
||||
if type (object) ~= "table" then
|
||||
return object
|
||||
elseif lookup_table [object] then
|
||||
return lookup_table [object]
|
||||
end -- if
|
||||
|
||||
local new_table = {}
|
||||
lookup_table [object] = new_table
|
||||
|
||||
for index, value in pairs (object) do
|
||||
new_table [_copy (index)] = _copy (value)
|
||||
end -- for
|
||||
|
||||
return setmetatable (new_table, getmetatable (object))
|
||||
end -- function _copy
|
||||
|
||||
return _copy (object)
|
||||
end -- function deepcopy
|
||||
|
||||
function shallow (t)
|
||||
assert (type (t) == "table", "You must specify a table to copy")
|
||||
|
||||
local result = {}
|
||||
|
||||
for k, v in pairs (t) do
|
||||
result [k] = v
|
||||
end -- for each table element
|
||||
|
||||
-- copy the metatable
|
||||
return setmetatable (result, getmetatable (t))
|
||||
|
||||
end -- function shallow
|
||||
47
cosmic rage/lua/declare.lua
Normal file
47
cosmic rage/lua/declare.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
-- declare.lua
|
||||
-- See: http://www.gammon.com.au/forum/?id=7327
|
||||
--
|
||||
-- If you use this inside a function you cannot access global variables that have
|
||||
-- not already been declared, and must declare all local variables
|
||||
|
||||
function force_declarations ()
|
||||
setfenv (2, setmetatable ({},
|
||||
{
|
||||
__index = function (t, n)
|
||||
error("variable '"..n.."' is not declared", 2)
|
||||
end,
|
||||
__newindex = function (t, n, v)
|
||||
error("assign to undeclared variable '"..n.."'", 2)
|
||||
end })
|
||||
)
|
||||
end -- force_declarations
|
||||
|
||||
return force_declarations
|
||||
|
||||
--[[
|
||||
|
||||
Example of use:
|
||||
|
||||
|
||||
require "declare"
|
||||
|
||||
function test (x)
|
||||
-- capture any global variables we want
|
||||
local print = print
|
||||
|
||||
-- after this we can't access global variables, and must declare local ones
|
||||
force_declarations ()
|
||||
|
||||
-- must declare every variable now before we use it
|
||||
local a, b, c
|
||||
|
||||
print (a)
|
||||
a = 1
|
||||
b = 2
|
||||
c = x * 2
|
||||
print (c)
|
||||
end -- test
|
||||
|
||||
test (1)
|
||||
|
||||
--]]
|
||||
186
cosmic rage/lua/gauge.lua
Normal file
186
cosmic rage/lua/gauge.lua
Normal file
@@ -0,0 +1,186 @@
|
||||
--[[
|
||||
|
||||
Function to draw a gauge (health bar).
|
||||
|
||||
You specify the starting point, width, and height.
|
||||
Also the name to show for the mouse-over window (eg. "HP).
|
||||
|
||||
Author: Nick Gammon
|
||||
Date: 14 February 2010
|
||||
|
||||
--]]
|
||||
|
||||
function gauge (win, -- miniwindow ID to draw in
|
||||
name, -- string, eg: "HP"
|
||||
current, max, -- current and max value (eg. 50, 100)
|
||||
-- if max is nil, then current is a percentage
|
||||
left, top, width, height, -- where to put it inside the window
|
||||
fg_colour, bg_colour, -- colour for bar, colour for unfilled part
|
||||
ticks, tick_colour, -- number of ticks to draw, and in what colour
|
||||
frame_colour, -- colour for frame around bar
|
||||
shadow_colour, -- colour for shadow, nil for no shadow
|
||||
no_gradient) -- don't use the gradient fill effect
|
||||
|
||||
local Fraction
|
||||
|
||||
if not current then
|
||||
return
|
||||
end -- if
|
||||
|
||||
-- max == nil, means current is a percentage
|
||||
if max then
|
||||
if max <= 0 then
|
||||
return
|
||||
end -- no divide by zero
|
||||
|
||||
Fraction = current / max
|
||||
else
|
||||
Fraction = current / 100
|
||||
end -- if
|
||||
|
||||
-- fraction in range 0 to 1
|
||||
Fraction = math.min (math.max (Fraction, 0), 1)
|
||||
|
||||
-- set up some defaults
|
||||
height = height or 15
|
||||
fg_colour = fg_colour or ColourNameToRGB "mediumblue"
|
||||
bg_colour = bg_colour or ColourNameToRGB "rosybrown"
|
||||
ticks = ticks or 5
|
||||
tick_colour = tick_colour or ColourNameToRGB "silver"
|
||||
frame_colour = frame_colour or ColourNameToRGB "lightgrey"
|
||||
|
||||
-- shadow
|
||||
if shadow_colour then
|
||||
WindowRectOp (win, miniwin.rect_fill, left + 2, top + 2, left + width + 2, top + height + 2, shadow_colour)
|
||||
end -- if
|
||||
|
||||
-- background colour - for un-filled part
|
||||
WindowRectOp (win, miniwin.rect_fill, left, top, left + width, top + height, bg_colour) -- fill entire box
|
||||
|
||||
-- how big filled part is
|
||||
local gauge_width = (width - 2) * Fraction
|
||||
|
||||
-- box size must be > 0 or WindowGradient fills the whole thing
|
||||
if math.floor (gauge_width) > 0 then
|
||||
|
||||
if no_gradient then
|
||||
WindowRectOp (win, miniwin.rect_fill, left+1, top, left+1+gauge_width, top+height, fg_colour)
|
||||
else
|
||||
-- top half
|
||||
WindowGradient (win, left, top,
|
||||
left + gauge_width, top + height / 2,
|
||||
0x000000, -- black
|
||||
fg_colour, 2) -- vertical top to bottom
|
||||
|
||||
-- bottom half
|
||||
WindowGradient (win, left, top + height / 2,
|
||||
left + gauge_width, top + height-1,
|
||||
fg_colour,
|
||||
0x000000, -- black
|
||||
2) -- vertical top to bottom
|
||||
end
|
||||
|
||||
end -- non-zero
|
||||
|
||||
-- draw tick marks if wanted
|
||||
if ticks > 0 then
|
||||
|
||||
-- show ticks (if there are 5 ticks there are 6 gaps)
|
||||
local ticks_at = width / (ticks + 1)
|
||||
|
||||
-- ticks
|
||||
for i = 1, ticks do
|
||||
WindowLine (win, left + (i * ticks_at), top,
|
||||
left + (i * ticks_at), top + height,
|
||||
tick_colour, 0, 1)
|
||||
end -- for
|
||||
|
||||
end -- ticks wanted
|
||||
|
||||
-- draw a box around it (frame)
|
||||
WindowRectOp (win, miniwin.rect_frame, left, top, left + width, top + height, frame_colour)
|
||||
|
||||
if name and #name > 0 then
|
||||
-- mouse-over information: add hotspot
|
||||
WindowAddHotspot (win, name, left, top, left + width, top + height,
|
||||
"", "", "", "", "", "", 0, 0)
|
||||
|
||||
-- store numeric values in case they mouse over it
|
||||
if max then
|
||||
WindowHotspotTooltip(win, name, string.format ("%s\t%i / %i (%i%%)",
|
||||
name, current, max, Fraction * 100) )
|
||||
else
|
||||
WindowHotspotTooltip(win, name, string.format ("%s\t(%i%%)",
|
||||
name, Fraction * 100) )
|
||||
end -- if
|
||||
|
||||
end -- hotspot wanted
|
||||
|
||||
end -- function gauge
|
||||
|
||||
-- find which element in an array has the largest text size
|
||||
function max_text_width (win, font_id, t, utf8)
|
||||
local max = 0
|
||||
for _, s in ipairs (t) do
|
||||
max = math.max (max, WindowTextWidth (win, font_id, s, utf8))
|
||||
end -- for each item
|
||||
return max
|
||||
end -- max_text_width
|
||||
|
||||
-- get font from preferred font list
|
||||
function get_preferred_font (t)
|
||||
local fonts = utils.getfontfamilies ()
|
||||
|
||||
-- convert to upper-case
|
||||
local f2 = {}
|
||||
for k in pairs (fonts) do
|
||||
f2 [k:upper ()] = true
|
||||
end -- for
|
||||
|
||||
for _, s in ipairs (t) do
|
||||
if f2 [s:upper ()] then
|
||||
return s
|
||||
end -- if
|
||||
end -- for each item
|
||||
|
||||
return "Courier"
|
||||
end -- get_preferred_font
|
||||
|
||||
function capitalize (x)
|
||||
return string.upper (string.sub(x, 1, 1)) .. string.lower (string.sub(x, 2))
|
||||
end -- capitalize
|
||||
|
||||
function draw_3d_box (win, left, top, width, height)
|
||||
local right = left + width
|
||||
local bottom = top + height
|
||||
|
||||
WindowCircleOp (win, miniwin.circle_round_rectangle, left, top, right, bottom, 0x505050, 0, 3, 0, 1) -- dark grey border (3 pixels)
|
||||
WindowCircleOp (win, miniwin.circle_round_rectangle, left + 1, top + 1, right - 1, bottom - 1, 0x7C7C7C, 0, 1, 0, 1) -- lighter inner border
|
||||
WindowCircleOp (win, miniwin.circle_round_rectangle, left + 2, top + 2, right - 2, bottom - 2, 0x000000, 0, 1, 0, 1) -- black inside that
|
||||
WindowLine (win, left + 1, top + 1, right - 1, top + 1, 0xC2C2C2, 0, 1) -- light top edge
|
||||
WindowLine (win, left + 1, top + 1, left + 1, bottom - 1, 0xC2C2C2, 0, 1) -- light left edge (for 3D look)
|
||||
end -- draw_3d_box
|
||||
|
||||
function draw_text_box (win, font, left, top, text, utf8, text_colour, fill_colour, border_colour)
|
||||
local width = WindowTextWidth (win, font, text, utf8)
|
||||
local font_height = WindowFontInfo (win, font, 1)
|
||||
|
||||
WindowRectOp (win, miniwin.rect_fill, left - 3, top, left + width + 3, top + font_height + 4, fill_colour) -- fill
|
||||
WindowText (win, font, text, left, top + 2, 0, 0, text_colour, utf8) -- draw text
|
||||
WindowRectOp (win, miniwin.rect_frame, left - 3, top, left + width + 3, top + font_height + 4, border_colour) -- border
|
||||
return width
|
||||
end -- draw_text_box
|
||||
|
||||
-- text with a black outline
|
||||
function outlined_text(win, font, text, startx, starty, endx, endy, color, utf8)
|
||||
WindowText(win, font, text, startx-1, starty-1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx-1, starty, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx-1, starty+1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx, starty-1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx, starty+1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx+1, starty-1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx+1, starty, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx+1, starty+1, endx, endy, 0x000000, utf8)
|
||||
WindowText(win, font, text, startx, starty, endx, endy, color, utf8)
|
||||
end
|
||||
|
||||
48
cosmic rage/lua/getlines.lua
Normal file
48
cosmic rage/lua/getlines.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
-- getlines.lua
|
||||
-- getlines iterator - iterates over a string and returns one item per line
|
||||
|
||||
function getlines (str)
|
||||
|
||||
local pos = 0
|
||||
|
||||
-- the for loop calls this for every iteration
|
||||
-- returning nil terminates the loop
|
||||
local function iterator (s)
|
||||
|
||||
if not pos then
|
||||
return nil
|
||||
end -- end of string, exit loop
|
||||
|
||||
local oldpos = pos + 1 -- step past previous newline
|
||||
pos = string.find (s, "\n", oldpos) -- find next newline
|
||||
|
||||
if not pos then -- no more newlines, return rest of string
|
||||
return string.sub (s, oldpos)
|
||||
end -- no newline
|
||||
|
||||
return string.sub (s, oldpos, pos - 1)
|
||||
|
||||
end -- iterator
|
||||
|
||||
return iterator, str
|
||||
end -- getlines
|
||||
|
||||
return getlines
|
||||
|
||||
--[=[
|
||||
|
||||
Example of use:
|
||||
|
||||
require "getlines"
|
||||
|
||||
test = [[
|
||||
every good
|
||||
boy
|
||||
deserves
|
||||
fruit]]
|
||||
|
||||
for l in getlines (test) do
|
||||
print ('"' .. l .. '"')
|
||||
end -- for
|
||||
|
||||
--]=]
|
||||
49
cosmic rage/lua/getstyle.lua
Normal file
49
cosmic rage/lua/getstyle.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
-- getstyle.lua
|
||||
--
|
||||
|
||||
--[[
|
||||
|
||||
See forum thread: http://www.gammon.com.au/forum/?id=7818
|
||||
|
||||
GetStyle:
|
||||
Finds a style run corresponding to a given column
|
||||
|
||||
Returns nil if style run not found (eg. column out of range)
|
||||
|
||||
If style run found returns:
|
||||
* the style table (see below)
|
||||
* the character at that column
|
||||
* the style run number (eg. style 3)
|
||||
|
||||
The style table should contain the following:
|
||||
|
||||
t.text --> text of that (entire) style run
|
||||
t.length --> length of the (entire) style run
|
||||
t.textcolour --> text colour (RGB number)
|
||||
t.backcolour --> background colour (RGB number)
|
||||
t.style --> style bits (1=bold, 2=underline, 4=italic)
|
||||
|
||||
--]]
|
||||
|
||||
function GetStyle (styleRuns, wantedColumn)
|
||||
local currentColumn = 1
|
||||
|
||||
-- check arguments
|
||||
assert (type (styleRuns) == "table",
|
||||
"First argument to GetStyle must be table of style runs")
|
||||
|
||||
assert (type (wantedColumn) == "number" and wantedColumn >= 1,
|
||||
"Second argument to GetStyle must be column number to find")
|
||||
|
||||
-- go through each style
|
||||
for item, style in ipairs (styleRuns) do
|
||||
local position = wantedColumn - currentColumn + 1 -- where letter is in style
|
||||
currentColumn = currentColumn + style.length -- next style starts here
|
||||
if currentColumn > wantedColumn then -- if we are within this style
|
||||
return style, string.sub (style.text, position, position), item -- done
|
||||
end -- if found column
|
||||
end -- for each style
|
||||
|
||||
-- if not found: result is nil
|
||||
|
||||
end -- function GetStyle
|
||||
111
cosmic rage/lua/getworld.lua
Normal file
111
cosmic rage/lua/getworld.lua
Normal file
@@ -0,0 +1,111 @@
|
||||
|
||||
-- table of worlds we couldn't open
|
||||
cannot_open_world = cannot_open_world or {} -- set flag here if can't open world
|
||||
-- getworld.lua
|
||||
--
|
||||
|
||||
--[[
|
||||
|
||||
See forum thread: http://www.gammon.com.au/forum/?id=7991
|
||||
|
||||
This simplifies sending triggered lines to another, dummy, world.
|
||||
|
||||
get_a_world (name) - returns a world pointer to the named world, opening it if necessary
|
||||
|
||||
send_to_world (name, styles) - sends the style runs to the named world, calling get_a_world
|
||||
to get it
|
||||
|
||||
--]]
|
||||
|
||||
|
||||
-- make the named world, if necessary - adds "extra" lines to the world file (eg. plugins)
|
||||
function make_world (name, extra, folder)
|
||||
|
||||
local filename = GetInfo (57)
|
||||
if folder then
|
||||
filename = filename .. folder .. "\\"
|
||||
end -- if folder wanted
|
||||
|
||||
filename = filename .. name .. ".mcl"
|
||||
local f = io.open (filename, "r")
|
||||
|
||||
if f then
|
||||
f:close ()
|
||||
return
|
||||
end -- world file exists
|
||||
|
||||
f = io.output (filename) -- create world file
|
||||
|
||||
assert (f:write ([[
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!DOCTYPE muclient>
|
||||
<!-- MUSHclient world file -->
|
||||
<!-- Written by Nick Gammon -->
|
||||
<!-- Home Page: http://www.mushclient.com/ -->
|
||||
<!-- Generated by getworld.lua plugin -->
|
||||
<muclient>
|
||||
<world defaults="y"
|
||||
name="]] .. name .. [["
|
||||
site="0.0.0.0"
|
||||
port="4000"
|
||||
/>
|
||||
]] .. extra .. [[
|
||||
|
||||
</muclient>
|
||||
]]))
|
||||
|
||||
f:close () -- close world file now
|
||||
|
||||
-- and open the file ;P
|
||||
Open (filename)
|
||||
|
||||
end -- make_world
|
||||
|
||||
-- open a world by name, return world object or nil if cannot
|
||||
function get_a_world (name, folder)
|
||||
|
||||
-- try to find world
|
||||
local w = GetWorld (name) -- get world
|
||||
|
||||
-- if not found, try to open it in worlds directory
|
||||
|
||||
if not cannot_open_world [name] and not w then
|
||||
local filename = GetInfo (57)
|
||||
if folder then
|
||||
filename = filename .. folder .. "\\"
|
||||
end -- if folder wanted
|
||||
|
||||
filename = filename .. name .. ".mcl"
|
||||
Open (filename) -- get MUSHclient to open it
|
||||
Activate () -- make our original world active again
|
||||
w = GetWorld (name) -- try again to get the world object
|
||||
if w then
|
||||
w:DeleteOutput () -- delete "welcome to MUSHclient" message
|
||||
else
|
||||
ColourNote ("white", "red", "Can't open world file: " .. filename)
|
||||
cannot_open_world [name] = true -- don't repeatedly show failure message
|
||||
end -- can't find world
|
||||
end -- can't find world first time around
|
||||
|
||||
return w
|
||||
|
||||
end -- get_a_world
|
||||
|
||||
-- send the styles (eg. from a trigger) to the named world, opening it if necessary
|
||||
function send_to_world (name, styles)
|
||||
|
||||
local w = get_a_world (name)
|
||||
|
||||
if w then -- if present
|
||||
for _, v in ipairs (styles) do
|
||||
w:ColourTell (RGBColourToName (v.textcolour),
|
||||
RGBColourToName (v.backcolour),
|
||||
v.text)
|
||||
end -- for each style run
|
||||
w:Note ("") -- wrap up line
|
||||
|
||||
end -- world found
|
||||
|
||||
return w -- so they can check if we succeeded
|
||||
|
||||
end -- send_to_world
|
||||
24
cosmic rage/lua/json.lua
Normal file
24
cosmic rage/lua/json.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local decode = require("json.decode")
|
||||
local encode = require("json.encode")
|
||||
local util = require("json.util")
|
||||
|
||||
local _G = _G
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local json = {
|
||||
_VERSION = "1.3.4",
|
||||
_DESCRIPTION = "LuaJSON : customizable JSON decoder/encoder",
|
||||
_COPYRIGHT = "Copyright (c) 2007-2014 Thomas Harning Jr. <harningt@gmail.com>",
|
||||
decode = decode,
|
||||
encode = encode,
|
||||
util = util
|
||||
}
|
||||
|
||||
_G.json = json
|
||||
|
||||
return json
|
||||
171
cosmic rage/lua/json/decode.lua
Normal file
171
cosmic rage/lua/json/decode.lua
Normal file
@@ -0,0 +1,171 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local lpeg = require("lpeg")
|
||||
|
||||
local error = error
|
||||
local pcall = pcall
|
||||
|
||||
local jsonutil = require("json.util")
|
||||
local merge = jsonutil.merge
|
||||
local util = require("json.decode.util")
|
||||
|
||||
local decode_state = require("json.decode.state")
|
||||
|
||||
local setmetatable, getmetatable = setmetatable, getmetatable
|
||||
local assert = assert
|
||||
local ipairs, pairs = ipairs, pairs
|
||||
local string_char = require("string").char
|
||||
|
||||
local type = type
|
||||
|
||||
local require = require
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local modulesToLoad = {
|
||||
"composite",
|
||||
"strings",
|
||||
"number",
|
||||
"others"
|
||||
}
|
||||
local loadedModules = {
|
||||
}
|
||||
|
||||
local json_decode = {}
|
||||
|
||||
json_decode.default = {
|
||||
unicodeWhitespace = true,
|
||||
initialObject = false,
|
||||
nothrow = false
|
||||
}
|
||||
|
||||
local modes_defined = { "default", "strict", "simple" }
|
||||
|
||||
json_decode.simple = {}
|
||||
|
||||
json_decode.strict = {
|
||||
unicodeWhitespace = true,
|
||||
initialObject = true,
|
||||
nothrow = false
|
||||
}
|
||||
|
||||
for _,name in ipairs(modulesToLoad) do
|
||||
local mod = require("json.decode." .. name)
|
||||
if mod.mergeOptions then
|
||||
for _, mode in pairs(modes_defined) do
|
||||
mod.mergeOptions(json_decode[mode], mode)
|
||||
end
|
||||
end
|
||||
loadedModules[#loadedModules + 1] = mod
|
||||
end
|
||||
|
||||
-- Shift over default into defaultOptions to permit build optimization
|
||||
local defaultOptions = json_decode.default
|
||||
json_decode.default = nil
|
||||
|
||||
local function generateDecoder(lexer, options)
|
||||
-- Marker to permit detection of final end
|
||||
local marker = {}
|
||||
local parser = lpeg.Ct((options.ignored * lexer)^0 * lpeg.Cc(marker)) * options.ignored * (lpeg.P(-1) + util.unexpected())
|
||||
local decoder = function(data)
|
||||
local state = decode_state.create(options)
|
||||
local parsed = parser:match(data)
|
||||
assert(parsed, "Invalid JSON data")
|
||||
local i = 0
|
||||
while true do
|
||||
i = i + 1
|
||||
local item = parsed[i]
|
||||
if item == marker then break end
|
||||
if type(item) == 'function' and item ~= jsonutil.undefined and item ~= jsonutil.null then
|
||||
item(state)
|
||||
else
|
||||
state:set_value(item)
|
||||
end
|
||||
end
|
||||
if options.initialObject then
|
||||
assert(type(state.previous) == 'table', "Initial value not an object or array")
|
||||
end
|
||||
-- Make sure stack is empty
|
||||
assert(state.i == 0, "Unclosed elements present")
|
||||
return state.previous
|
||||
end
|
||||
if options.nothrow then
|
||||
return function(data)
|
||||
local status, rv = pcall(decoder, data)
|
||||
if status then
|
||||
return rv
|
||||
else
|
||||
return nil, rv
|
||||
end
|
||||
end
|
||||
end
|
||||
return decoder
|
||||
end
|
||||
|
||||
local function buildDecoder(mode)
|
||||
mode = mode and merge({}, defaultOptions, mode) or defaultOptions
|
||||
for _, mod in ipairs(loadedModules) do
|
||||
if mod.mergeOptions then
|
||||
mod.mergeOptions(mode)
|
||||
end
|
||||
end
|
||||
local ignored = mode.unicodeWhitespace and util.unicode_ignored or util.ascii_ignored
|
||||
-- Store 'ignored' in the global options table
|
||||
mode.ignored = ignored
|
||||
|
||||
--local grammar = {
|
||||
-- [1] = mode.initialObject and (ignored * (object_type + array_type)) or value_type
|
||||
--}
|
||||
local lexer
|
||||
for _, mod in ipairs(loadedModules) do
|
||||
local new_lexer = mod.generateLexer(mode)
|
||||
lexer = lexer and lexer + new_lexer or new_lexer
|
||||
end
|
||||
return generateDecoder(lexer, mode)
|
||||
end
|
||||
|
||||
-- Since 'default' is nil, we cannot take map it
|
||||
local defaultDecoder = buildDecoder(json_decode.default)
|
||||
local prebuilt_decoders = {}
|
||||
for _, mode in pairs(modes_defined) do
|
||||
if json_decode[mode] ~= nil then
|
||||
prebuilt_decoders[json_decode[mode]] = buildDecoder(json_decode[mode])
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Options:
|
||||
number => number decode options
|
||||
string => string decode options
|
||||
array => array decode options
|
||||
object => object decode options
|
||||
initialObject => whether or not to require the initial object to be a table/array
|
||||
allowUndefined => whether or not to allow undefined values
|
||||
]]
|
||||
local function getDecoder(mode)
|
||||
mode = mode == true and json_decode.strict or mode or json_decode.default
|
||||
local decoder = mode == nil and defaultDecoder or prebuilt_decoders[mode]
|
||||
if decoder then
|
||||
return decoder
|
||||
end
|
||||
return buildDecoder(mode)
|
||||
end
|
||||
|
||||
local function decode(data, mode)
|
||||
local decoder = getDecoder(mode)
|
||||
return decoder(data)
|
||||
end
|
||||
|
||||
local mt = {}
|
||||
mt.__call = function(self, ...)
|
||||
return decode(...)
|
||||
end
|
||||
|
||||
json_decode.getDecoder = getDecoder
|
||||
json_decode.decode = decode
|
||||
json_decode.util = util
|
||||
setmetatable(json_decode, mt)
|
||||
|
||||
return json_decode
|
||||
64
cosmic rage/lua/json/decode/array.lua
Normal file
64
cosmic rage/lua/json/decode/array.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
--]]
|
||||
local lpeg = require("lpeg")
|
||||
|
||||
local util = require("json.decode.util")
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local table_maxn = require("table").maxn
|
||||
|
||||
local unpack = unpack
|
||||
|
||||
module("json.decode.array")
|
||||
|
||||
-- Utility function to help manage slighly sparse arrays
|
||||
local function processArray(array)
|
||||
local max_n = table_maxn(array)
|
||||
-- Only populate 'n' if it is necessary
|
||||
if #array ~= max_n then
|
||||
array.n = max_n
|
||||
end
|
||||
if jsonutil.InitArray then
|
||||
array = jsonutil.InitArray(array) or array
|
||||
end
|
||||
return array
|
||||
end
|
||||
|
||||
local defaultOptions = {
|
||||
trailingComma = true
|
||||
}
|
||||
|
||||
default = nil -- Let the buildCapture optimization take place
|
||||
strict = {
|
||||
trailingComma = false
|
||||
}
|
||||
|
||||
local function buildCapture(options, global_options)
|
||||
local ignored = global_options.ignored
|
||||
-- arrayItem == element
|
||||
local arrayItem = lpeg.V(util.types.VALUE)
|
||||
local arrayElements = lpeg.Ct(arrayItem * (ignored * lpeg.P(',') * ignored * arrayItem)^0 + 0) / processArray
|
||||
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
local capture = lpeg.P("[")
|
||||
capture = capture * ignored
|
||||
* arrayElements * ignored
|
||||
if options.trailingComma then
|
||||
capture = capture * (lpeg.P(",") + 0) * ignored
|
||||
end
|
||||
capture = capture * lpeg.P("]")
|
||||
return capture
|
||||
end
|
||||
|
||||
function register_types()
|
||||
util.register_type("ARRAY")
|
||||
end
|
||||
|
||||
function load_types(options, global_options, grammar)
|
||||
local capture = buildCapture(options, global_options)
|
||||
local array_id = util.types.ARRAY
|
||||
grammar[array_id] = capture
|
||||
util.append_grammar_item(grammar, "VALUE", lpeg.V(array_id))
|
||||
end
|
||||
116
cosmic rage/lua/json/decode/calls.lua
Normal file
116
cosmic rage/lua/json/decode/calls.lua
Normal file
@@ -0,0 +1,116 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
--]]
|
||||
local lpeg = require("lpeg")
|
||||
local tostring = tostring
|
||||
local pairs, ipairs = pairs, ipairs
|
||||
local next, type = next, type
|
||||
local error = error
|
||||
|
||||
local util = require("json.decode.util")
|
||||
|
||||
local buildCall = require("json.util").buildCall
|
||||
|
||||
local getmetatable = getmetatable
|
||||
|
||||
module("json.decode.calls")
|
||||
|
||||
local defaultOptions = {
|
||||
defs = nil,
|
||||
-- By default, do not allow undefined calls to be de-serialized as call objects
|
||||
allowUndefined = false
|
||||
}
|
||||
|
||||
-- No real default-option handling needed...
|
||||
default = nil
|
||||
strict = nil
|
||||
|
||||
local isPattern
|
||||
if lpeg.type then
|
||||
function isPattern(value)
|
||||
return lpeg.type(value) == 'pattern'
|
||||
end
|
||||
else
|
||||
local metaAdd = getmetatable(lpeg.P("")).__add
|
||||
function isPattern(value)
|
||||
return getmetatable(value).__add == metaAdd
|
||||
end
|
||||
end
|
||||
|
||||
local function buildDefinedCaptures(argumentCapture, defs)
|
||||
local callCapture
|
||||
if not defs then return end
|
||||
for name, func in pairs(defs) do
|
||||
if type(name) ~= 'string' and not isPattern(name) then
|
||||
error("Invalid functionCalls name: " .. tostring(name) .. " not a string or LPEG pattern")
|
||||
end
|
||||
-- Allow boolean or function to match up w/ encoding permissions
|
||||
if type(func) ~= 'boolean' and type(func) ~= 'function' then
|
||||
error("Invalid functionCalls item: " .. name .. " not a function")
|
||||
end
|
||||
local nameCallCapture
|
||||
if type(name) == 'string' then
|
||||
nameCallCapture = lpeg.P(name .. "(") * lpeg.Cc(name)
|
||||
else
|
||||
-- Name matcher expected to produce a capture
|
||||
nameCallCapture = name * "("
|
||||
end
|
||||
-- Call func over nameCallCapture and value to permit function receiving name
|
||||
|
||||
-- Process 'func' if it is not a function
|
||||
if type(func) == 'boolean' then
|
||||
local allowed = func
|
||||
func = function(name, ...)
|
||||
if not allowed then
|
||||
error("Function call on '" .. name .. "' not permitted")
|
||||
end
|
||||
return buildCall(name, ...)
|
||||
end
|
||||
else
|
||||
local inner_func = func
|
||||
func = function(...)
|
||||
return (inner_func(...))
|
||||
end
|
||||
end
|
||||
local newCapture = (nameCallCapture * argumentCapture) / func * ")"
|
||||
if not callCapture then
|
||||
callCapture = newCapture
|
||||
else
|
||||
callCapture = callCapture + newCapture
|
||||
end
|
||||
end
|
||||
return callCapture
|
||||
end
|
||||
|
||||
local function buildCapture(options)
|
||||
if not options -- No ops, don't bother to parse
|
||||
or not (options.defs and (nil ~= next(options.defs)) or options.allowUndefined) then
|
||||
return nil
|
||||
end
|
||||
-- Allow zero or more arguments separated by commas
|
||||
local value = lpeg.V(util.types.VALUE)
|
||||
local argumentCapture = (value * (lpeg.P(",") * value)^0) + 0
|
||||
local callCapture = buildDefinedCaptures(argumentCapture, options.defs)
|
||||
if options.allowUndefined then
|
||||
local function func(name, ...)
|
||||
return buildCall(name, ...)
|
||||
end
|
||||
-- Identifier-type-match
|
||||
local nameCallCapture = lpeg.C(util.identifier) * "("
|
||||
local newCapture = (nameCallCapture * argumentCapture) / func * ")"
|
||||
if not callCapture then
|
||||
callCapture = newCapture
|
||||
else
|
||||
callCapture = callCapture + newCapture
|
||||
end
|
||||
end
|
||||
return callCapture
|
||||
end
|
||||
|
||||
function load_types(options, global_options, grammar)
|
||||
local capture = buildCapture(options, global_options)
|
||||
if capture then
|
||||
util.append_grammar_item(grammar, "VALUE", capture)
|
||||
end
|
||||
end
|
||||
190
cosmic rage/lua/json/decode/composite.lua
Normal file
190
cosmic rage/lua/json/decode/composite.lua
Normal file
@@ -0,0 +1,190 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local pairs = pairs
|
||||
local type = type
|
||||
|
||||
local lpeg = require("lpeg")
|
||||
|
||||
local util = require("json.decode.util")
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local rawset = rawset
|
||||
|
||||
local assert = assert
|
||||
local tostring = tostring
|
||||
|
||||
local error = error
|
||||
local getmetatable = getmetatable
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local defaultOptions = {
|
||||
array = {
|
||||
trailingComma = true
|
||||
},
|
||||
object = {
|
||||
trailingComma = true,
|
||||
number = true,
|
||||
identifier = true,
|
||||
setObjectKey = rawset
|
||||
},
|
||||
calls = {
|
||||
defs = nil,
|
||||
-- By default, do not allow undefined calls to be de-serialized as call objects
|
||||
allowUndefined = false
|
||||
}
|
||||
}
|
||||
|
||||
local modeOptions = {
|
||||
default = nil,
|
||||
strict = {
|
||||
array = {
|
||||
trailingComma = false
|
||||
},
|
||||
object = {
|
||||
trailingComma = false,
|
||||
number = false,
|
||||
identifier = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local function BEGIN_ARRAY(state)
|
||||
state:push()
|
||||
state:new_array()
|
||||
end
|
||||
local function END_ARRAY(state)
|
||||
state:end_array()
|
||||
state:pop()
|
||||
end
|
||||
|
||||
local function BEGIN_OBJECT(state)
|
||||
state:push()
|
||||
state:new_object()
|
||||
end
|
||||
local function END_OBJECT(state)
|
||||
state:end_object()
|
||||
state:pop()
|
||||
end
|
||||
|
||||
local function END_CALL(state)
|
||||
state:end_call()
|
||||
state:pop()
|
||||
end
|
||||
|
||||
local function SET_KEY(state)
|
||||
state:set_key()
|
||||
end
|
||||
|
||||
local function NEXT_VALUE(state)
|
||||
state:put_value()
|
||||
end
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, true, 'array', defaultOptions, mode and modeOptions[mode])
|
||||
jsonutil.doOptionMerge(options, true, 'object', defaultOptions, mode and modeOptions[mode])
|
||||
jsonutil.doOptionMerge(options, true, 'calls', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
|
||||
local isPattern
|
||||
if lpeg.type then
|
||||
function isPattern(value)
|
||||
return lpeg.type(value) == 'pattern'
|
||||
end
|
||||
else
|
||||
local metaAdd = getmetatable(lpeg.P("")).__add
|
||||
function isPattern(value)
|
||||
return getmetatable(value).__add == metaAdd
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function generateSingleCallLexer(name, func)
|
||||
if type(name) ~= 'string' and not isPattern(name) then
|
||||
error("Invalid functionCalls name: " .. tostring(name) .. " not a string or LPEG pattern")
|
||||
end
|
||||
-- Allow boolean or function to match up w/ encoding permissions
|
||||
if type(func) ~= 'boolean' and type(func) ~= 'function' then
|
||||
error("Invalid functionCalls item: " .. name .. " not a function")
|
||||
end
|
||||
local function buildCallCapture(name)
|
||||
return function(state)
|
||||
if func == false then
|
||||
error("Function call on '" .. name .. "' not permitted")
|
||||
end
|
||||
state:push()
|
||||
state:new_call(name, func)
|
||||
end
|
||||
end
|
||||
local nameCallCapture
|
||||
if type(name) == 'string' then
|
||||
nameCallCapture = lpeg.P(name .. "(") * lpeg.Cc(name) / buildCallCapture
|
||||
else
|
||||
-- Name matcher expected to produce a capture
|
||||
nameCallCapture = name * "(" / buildCallCapture
|
||||
end
|
||||
-- Call func over nameCallCapture and value to permit function receiving name
|
||||
return nameCallCapture
|
||||
end
|
||||
|
||||
local function generateNamedCallLexers(options)
|
||||
if not options.calls or not options.calls.defs then
|
||||
return
|
||||
end
|
||||
local callCapture
|
||||
for name, func in pairs(options.calls.defs) do
|
||||
local newCapture = generateSingleCallLexer(name, func)
|
||||
if not callCapture then
|
||||
callCapture = newCapture
|
||||
else
|
||||
callCapture = callCapture + newCapture
|
||||
end
|
||||
end
|
||||
return callCapture
|
||||
end
|
||||
|
||||
local function generateCallLexer(options)
|
||||
local lexer
|
||||
local namedCapture = generateNamedCallLexers(options)
|
||||
if options.calls and options.calls.allowUndefined then
|
||||
lexer = generateSingleCallLexer(lpeg.C(util.identifier), true)
|
||||
end
|
||||
if namedCapture then
|
||||
lexer = lexer and lexer + namedCapture or namedCapture
|
||||
end
|
||||
if lexer then
|
||||
lexer = lexer + lpeg.P(")") * lpeg.Cc(END_CALL)
|
||||
end
|
||||
return lexer
|
||||
end
|
||||
|
||||
local function generateLexer(options)
|
||||
local ignored = options.ignored
|
||||
local array_options, object_options = options.array, options.object
|
||||
local lexer =
|
||||
lpeg.P("[") * lpeg.Cc(BEGIN_ARRAY)
|
||||
+ lpeg.P("]") * lpeg.Cc(END_ARRAY)
|
||||
+ lpeg.P("{") * lpeg.Cc(BEGIN_OBJECT)
|
||||
+ lpeg.P("}") * lpeg.Cc(END_OBJECT)
|
||||
+ lpeg.P(":") * lpeg.Cc(SET_KEY)
|
||||
+ lpeg.P(",") * lpeg.Cc(NEXT_VALUE)
|
||||
if object_options.identifier then
|
||||
-- Add identifier match w/ validation check that it is in key
|
||||
lexer = lexer + lpeg.C(util.identifier) * ignored * lpeg.P(":") * lpeg.Cc(SET_KEY)
|
||||
end
|
||||
local callLexers = generateCallLexer(options)
|
||||
if callLexers then
|
||||
lexer = lexer + callLexers
|
||||
end
|
||||
return lexer
|
||||
end
|
||||
|
||||
local composite = {
|
||||
mergeOptions = mergeOptions,
|
||||
generateLexer = generateLexer
|
||||
}
|
||||
|
||||
return composite
|
||||
100
cosmic rage/lua/json/decode/number.lua
Normal file
100
cosmic rage/lua/json/decode/number.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local lpeg = require("lpeg")
|
||||
local tonumber = tonumber
|
||||
local jsonutil = require("json.util")
|
||||
local merge = jsonutil.merge
|
||||
local util = require("json.decode.util")
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local digit = lpeg.R("09")
|
||||
local digits = digit^1
|
||||
|
||||
-- Illegal octal declaration
|
||||
local illegal_octal_detect = #(lpeg.P('0') * digits) * util.denied("Octal numbers")
|
||||
|
||||
local int = (lpeg.P('-') + 0) * (lpeg.R("19") * digits + illegal_octal_detect + digit)
|
||||
|
||||
local frac = lpeg.P('.') * digits
|
||||
|
||||
local exp = lpeg.S("Ee") * (lpeg.S("-+") + 0) * digits
|
||||
|
||||
local nan = lpeg.S("Nn") * lpeg.S("Aa") * lpeg.S("Nn")
|
||||
local inf = lpeg.S("Ii") * lpeg.P("nfinity")
|
||||
local ninf = lpeg.P('-') * lpeg.S("Ii") * lpeg.P("nfinity")
|
||||
local hex = (lpeg.P("0x") + lpeg.P("0X")) * lpeg.R("09","AF","af")^1
|
||||
|
||||
local defaultOptions = {
|
||||
nan = true,
|
||||
inf = true,
|
||||
frac = true,
|
||||
exp = true,
|
||||
hex = false
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
modeOptions.strict = {
|
||||
nan = false,
|
||||
inf = false
|
||||
}
|
||||
|
||||
local nan_value = 0/0
|
||||
local inf_value = 1/0
|
||||
local ninf_value = -1/0
|
||||
|
||||
--[[
|
||||
Options: configuration options for number rules
|
||||
nan: match NaN
|
||||
inf: match Infinity
|
||||
frac: match fraction portion (.0)
|
||||
exp: match exponent portion (e1)
|
||||
DEFAULT: nan, inf, frac, exp
|
||||
]]
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
local function generateLexer(options)
|
||||
options = options.number
|
||||
local ret = int
|
||||
if options.frac then
|
||||
ret = ret * (frac + 0)
|
||||
else
|
||||
ret = ret * (#frac * util.denied("Fractions", "number.frac") + 0)
|
||||
end
|
||||
if options.exp then
|
||||
ret = ret * (exp + 0)
|
||||
else
|
||||
ret = ret * (#exp * util.denied("Exponents", "number.exp") + 0)
|
||||
end
|
||||
if options.hex then
|
||||
ret = hex + ret
|
||||
else
|
||||
ret = #hex * util.denied("Hexadecimal", "number.hex") + ret
|
||||
end
|
||||
-- Capture number now
|
||||
ret = ret / tonumber
|
||||
if options.nan then
|
||||
ret = ret + nan / function() return nan_value end
|
||||
else
|
||||
ret = ret + #nan * util.denied("NaN", "number.nan")
|
||||
end
|
||||
if options.inf then
|
||||
ret = ret + ninf / function() return ninf_value end + inf / function() return inf_value end
|
||||
else
|
||||
ret = ret + (#ninf + #inf) * util.denied("+/-Inf", "number.inf")
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local number = {
|
||||
int = int,
|
||||
mergeOptions = mergeOptions,
|
||||
generateLexer = generateLexer
|
||||
}
|
||||
|
||||
return number
|
||||
103
cosmic rage/lua/json/decode/object.lua
Normal file
103
cosmic rage/lua/json/decode/object.lua
Normal file
@@ -0,0 +1,103 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
--]]
|
||||
local lpeg = require("lpeg")
|
||||
|
||||
local util = require("json.decode.util")
|
||||
local merge = require("json.util").merge
|
||||
|
||||
local tonumber = tonumber
|
||||
local unpack = unpack
|
||||
local print = print
|
||||
local tostring = tostring
|
||||
|
||||
local rawset = rawset
|
||||
|
||||
module("json.decode.object")
|
||||
|
||||
-- BEGIN LPEG < 0.9 SUPPORT
|
||||
local initObject, applyObjectKey
|
||||
if not (lpeg.Cg and lpeg.Cf and lpeg.Ct) then
|
||||
function initObject()
|
||||
return {}
|
||||
end
|
||||
function applyObjectKey(tab, key, val)
|
||||
tab[key] = val
|
||||
return tab
|
||||
end
|
||||
end
|
||||
-- END LPEG < 0.9 SUPPORT
|
||||
|
||||
local defaultOptions = {
|
||||
number = true,
|
||||
identifier = true,
|
||||
trailingComma = true
|
||||
}
|
||||
|
||||
default = nil -- Let the buildCapture optimization take place
|
||||
|
||||
strict = {
|
||||
number = false,
|
||||
identifier = false,
|
||||
trailingComma = false
|
||||
}
|
||||
|
||||
local function buildItemSequence(objectItem, ignored)
|
||||
return (objectItem * (ignored * lpeg.P(",") * ignored * objectItem)^0) + 0
|
||||
end
|
||||
|
||||
local function buildCapture(options, global_options)
|
||||
local ignored = global_options.ignored
|
||||
local string_type = lpeg.V(util.types.STRING)
|
||||
local integer_type = lpeg.V(util.types.INTEGER)
|
||||
local value_type = lpeg.V(util.types.VALUE)
|
||||
options = options and merge({}, defaultOptions, options) or defaultOptions
|
||||
local key = string_type
|
||||
if options.identifier then
|
||||
key = key + lpeg.C(util.identifier)
|
||||
end
|
||||
if options.number then
|
||||
key = key + integer_type
|
||||
end
|
||||
local objectItems
|
||||
local objectItem = (key * ignored * lpeg.P(":") * ignored * value_type)
|
||||
-- BEGIN LPEG < 0.9 SUPPORT
|
||||
if not (lpeg.Cg and lpeg.Cf and lpeg.Ct) then
|
||||
local set_key = applyObjectKey
|
||||
if options.setObjectKey then
|
||||
local setObjectKey = options.setObjectKey
|
||||
set_key = function(tab, key, val)
|
||||
setObjectKey(tab, key, val)
|
||||
return tab
|
||||
end
|
||||
end
|
||||
|
||||
objectItems = buildItemSequence(objectItem / set_key, ignored)
|
||||
objectItems = lpeg.Ca(lpeg.Cc(false) / initObject * objectItems)
|
||||
-- END LPEG < 0.9 SUPPORT
|
||||
else
|
||||
objectItems = buildItemSequence(lpeg.Cg(objectItem), ignored)
|
||||
objectItems = lpeg.Cf(lpeg.Ct(0) * objectItems, options.setObjectKey or rawset)
|
||||
end
|
||||
|
||||
|
||||
local capture = lpeg.P("{") * ignored
|
||||
capture = capture * objectItems * ignored
|
||||
if options.trailingComma then
|
||||
capture = capture * (lpeg.P(",") + 0) * ignored
|
||||
end
|
||||
capture = capture * lpeg.P("}")
|
||||
return capture
|
||||
end
|
||||
|
||||
function register_types()
|
||||
util.register_type("OBJECT")
|
||||
end
|
||||
|
||||
function load_types(options, global_options, grammar)
|
||||
local capture = buildCapture(options, global_options)
|
||||
local object_id = util.types.OBJECT
|
||||
grammar[object_id] = capture
|
||||
util.append_grammar_item(grammar, "VALUE", lpeg.V(object_id))
|
||||
end
|
||||
62
cosmic rage/lua/json/decode/others.lua
Normal file
62
cosmic rage/lua/json/decode/others.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local lpeg = require("lpeg")
|
||||
local jsonutil = require("json.util")
|
||||
local merge = jsonutil.merge
|
||||
local util = require("json.decode.util")
|
||||
|
||||
-- Container module for other JavaScript types (bool, null, undefined)
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
-- For null and undefined, use the util.null value to preserve null-ness
|
||||
local booleanCapture =
|
||||
lpeg.P("true") * lpeg.Cc(true)
|
||||
+ lpeg.P("false") * lpeg.Cc(false)
|
||||
|
||||
local nullCapture = lpeg.P("null")
|
||||
local undefinedCapture = lpeg.P("undefined")
|
||||
|
||||
local defaultOptions = {
|
||||
allowUndefined = true,
|
||||
null = jsonutil.null,
|
||||
undefined = jsonutil.undefined
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
modeOptions.simple = {
|
||||
null = false, -- Mapped to nil
|
||||
undefined = false -- Mapped to nil
|
||||
}
|
||||
modeOptions.strict = {
|
||||
allowUndefined = false
|
||||
}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
local function generateLexer(options)
|
||||
-- The 'or nil' clause allows false to map to a nil value since 'nil' cannot be merged
|
||||
options = options.others
|
||||
local valueCapture = (
|
||||
booleanCapture
|
||||
+ nullCapture * lpeg.Cc(options.null or nil)
|
||||
)
|
||||
if options.allowUndefined then
|
||||
valueCapture = valueCapture + undefinedCapture * lpeg.Cc(options.undefined or nil)
|
||||
else
|
||||
valueCapture = valueCapture + #undefinedCapture * util.denied("undefined", "others.allowUndefined")
|
||||
end
|
||||
return valueCapture
|
||||
end
|
||||
|
||||
local others = {
|
||||
mergeOptions = mergeOptions,
|
||||
generateLexer = generateLexer
|
||||
}
|
||||
|
||||
return others
|
||||
189
cosmic rage/lua/json/decode/state.lua
Normal file
189
cosmic rage/lua/json/decode/state.lua
Normal file
@@ -0,0 +1,189 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
|
||||
local setmetatable = setmetatable
|
||||
local jsonutil = require("json.util")
|
||||
local assert = assert
|
||||
local type = type
|
||||
local next = next
|
||||
local unpack = require("table").unpack or unpack
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local state_ops = {}
|
||||
local state_mt = {
|
||||
__index = state_ops
|
||||
}
|
||||
|
||||
function state_ops.pop(self)
|
||||
self.previous_set = true
|
||||
self.previous = self.active
|
||||
local i = self.i
|
||||
-- Load in this array into the active item
|
||||
self.active = self.stack[i]
|
||||
self.active_state = self.state_stack[i]
|
||||
self.active_key = self.key_stack[i]
|
||||
self.stack[i] = nil
|
||||
self.state_stack[i] = nil
|
||||
self.key_stack[i] = nil
|
||||
|
||||
self.i = i - 1
|
||||
end
|
||||
|
||||
function state_ops.push(self)
|
||||
local i = self.i + 1
|
||||
self.i = i
|
||||
|
||||
self.stack[i] = self.active
|
||||
self.state_stack[i] = self.active_state
|
||||
self.key_stack[i] = self.active_key
|
||||
end
|
||||
|
||||
function state_ops.put_object_value(self, trailing)
|
||||
local object_options = self.options.object
|
||||
if trailing and object_options.trailingComma then
|
||||
if not self.active_key then
|
||||
return
|
||||
end
|
||||
end
|
||||
assert(self.active_key, "Missing key value")
|
||||
object_options.setObjectKey(self.active, self.active_key, self:grab_value())
|
||||
self.active_key = nil
|
||||
end
|
||||
|
||||
function state_ops.put_array_value(self, trailing)
|
||||
-- Safety check
|
||||
if trailing and not self.previous_set and self.options.array.trailingComma then
|
||||
return
|
||||
end
|
||||
local new_index = self.active_state + 1
|
||||
self.active_state = new_index
|
||||
self.active[new_index] = self:grab_value()
|
||||
end
|
||||
|
||||
function state_ops.put_value(self, trailing)
|
||||
if self.active_state == 'object' then
|
||||
self:put_object_value(trailing)
|
||||
else
|
||||
self:put_array_value(trailing)
|
||||
end
|
||||
end
|
||||
|
||||
function state_ops.new_array(self)
|
||||
local new_array = {}
|
||||
if jsonutil.InitArray then
|
||||
new_array = jsonutil.InitArray(new_array) or new_array
|
||||
end
|
||||
self.active = new_array
|
||||
self.active_state = 0
|
||||
self.active_key = nil
|
||||
self:unset_value()
|
||||
end
|
||||
|
||||
function state_ops.end_array(self)
|
||||
if self.previous_set or self.active_state ~= 0 then
|
||||
-- Not an empty array
|
||||
self:put_value(true)
|
||||
end
|
||||
if self.active_state ~= #self.active then
|
||||
-- Store the length in
|
||||
self.active.n = self.active_state
|
||||
end
|
||||
end
|
||||
|
||||
function state_ops.new_object(self)
|
||||
local new_object = {}
|
||||
self.active = new_object
|
||||
self.active_state = 'object'
|
||||
self.active_key = nil
|
||||
self:unset_value()
|
||||
end
|
||||
|
||||
function state_ops.end_object(self)
|
||||
if self.previous_set or next(self.active) then
|
||||
-- Not an empty object
|
||||
self:put_value(true)
|
||||
end
|
||||
end
|
||||
|
||||
function state_ops.new_call(self, name, func)
|
||||
-- TODO setup properly
|
||||
local new_call = {}
|
||||
new_call.name = name
|
||||
new_call.func = func
|
||||
self.active = new_call
|
||||
self.active_state = 0
|
||||
self.active_key = nil
|
||||
self:unset_value()
|
||||
end
|
||||
|
||||
function state_ops.end_call(self)
|
||||
if self.previous_set or self.active_state ~= 0 then
|
||||
-- Not an empty array
|
||||
self:put_value(true)
|
||||
end
|
||||
if self.active_state ~= #self.active then
|
||||
-- Store the length in
|
||||
self.active.n = self.active_state
|
||||
end
|
||||
local func = self.active.func
|
||||
if func == true then
|
||||
func = jsonutil.buildCall
|
||||
end
|
||||
self.active = func(self.active.name, unpack(self.active, 1, self.active.n or #self.active))
|
||||
end
|
||||
|
||||
|
||||
function state_ops.unset_value(self)
|
||||
self.previous_set = false
|
||||
self.previous = nil
|
||||
end
|
||||
|
||||
function state_ops.grab_value(self)
|
||||
assert(self.previous_set, "Previous value not set")
|
||||
self.previous_set = false
|
||||
return self.previous
|
||||
end
|
||||
|
||||
function state_ops.set_value(self, value)
|
||||
assert(not self.previous_set, "Value set when one already in slot")
|
||||
self.previous_set = true
|
||||
self.previous = value
|
||||
end
|
||||
|
||||
function state_ops.set_key(self)
|
||||
assert(self.active_state == 'object', "Cannot set key on array")
|
||||
local value = self:grab_value()
|
||||
local value_type = type(value)
|
||||
if self.options.object.number then
|
||||
assert(value_type == 'string' or value_type == 'number', "As configured, a key must be a number or string")
|
||||
else
|
||||
assert(value_type == 'string', "As configured, a key must be a string")
|
||||
end
|
||||
self.active_key = value
|
||||
end
|
||||
|
||||
|
||||
local function create(options)
|
||||
local ret = {
|
||||
options = options,
|
||||
stack = {},
|
||||
state_stack = {},
|
||||
key_stack = {},
|
||||
i = 0,
|
||||
active = nil,
|
||||
active_key = nil,
|
||||
previous = nil,
|
||||
active_state = nil
|
||||
|
||||
}
|
||||
return setmetatable(ret, state_mt)
|
||||
end
|
||||
|
||||
local state = {
|
||||
create = create
|
||||
}
|
||||
|
||||
return state
|
||||
133
cosmic rage/lua/json/decode/strings.lua
Normal file
133
cosmic rage/lua/json/decode/strings.lua
Normal file
@@ -0,0 +1,133 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local lpeg = require("lpeg")
|
||||
local jsonutil = require("json.util")
|
||||
local util = require("json.decode.util")
|
||||
local merge = jsonutil.merge
|
||||
|
||||
local tonumber = tonumber
|
||||
local string_char = require("string").char
|
||||
local floor = require("math").floor
|
||||
local table_concat = require("table").concat
|
||||
|
||||
local error = error
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local function get_error(item)
|
||||
local fmt_string = item .. " in string [%q] @ %i:%i"
|
||||
return lpeg.P(function(data, index)
|
||||
local line, line_index, bad_char, last_line = util.get_invalid_character_info(data, index)
|
||||
local err = fmt_string:format(bad_char, line, line_index)
|
||||
error(err)
|
||||
end) * 1
|
||||
end
|
||||
|
||||
local bad_unicode = get_error("Illegal unicode escape")
|
||||
local bad_hex = get_error("Illegal hex escape")
|
||||
local bad_character = get_error("Illegal character")
|
||||
local bad_escape = get_error("Illegal escape")
|
||||
|
||||
local knownReplacements = {
|
||||
["'"] = "'",
|
||||
['"'] = '"',
|
||||
['\\'] = '\\',
|
||||
['/'] = '/',
|
||||
b = '\b',
|
||||
f = '\f',
|
||||
n = '\n',
|
||||
r = '\r',
|
||||
t = '\t',
|
||||
v = '\v',
|
||||
z = '\z'
|
||||
}
|
||||
|
||||
-- according to the table at http://da.wikipedia.org/wiki/UTF-8
|
||||
local function utf8DecodeUnicode(code1, code2)
|
||||
code1, code2 = tonumber(code1, 16), tonumber(code2, 16)
|
||||
if code1 == 0 and code2 < 0x80 then
|
||||
return string_char(code2)
|
||||
end
|
||||
if code1 < 0x08 then
|
||||
return string_char(
|
||||
0xC0 + code1 * 4 + floor(code2 / 64),
|
||||
0x80 + code2 % 64)
|
||||
end
|
||||
return string_char(
|
||||
0xE0 + floor(code1 / 16),
|
||||
0x80 + (code1 % 16) * 4 + floor(code2 / 64),
|
||||
0x80 + code2 % 64)
|
||||
end
|
||||
|
||||
local function decodeX(code)
|
||||
code = tonumber(code, 16)
|
||||
return string_char(code)
|
||||
end
|
||||
|
||||
local doSimpleSub = lpeg.C(lpeg.S("'\"\\/bfnrtvz")) / knownReplacements
|
||||
local doUniSub = lpeg.P('u') * (lpeg.C(util.hexpair) * lpeg.C(util.hexpair) + bad_unicode)
|
||||
local doXSub = lpeg.P('x') * (lpeg.C(util.hexpair) + bad_hex)
|
||||
|
||||
local defaultOptions = {
|
||||
badChars = '',
|
||||
additionalEscapes = false, -- disallow untranslated escapes
|
||||
escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'), -- no check on valid characters
|
||||
decodeUnicode = utf8DecodeUnicode,
|
||||
strict_quotes = false
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
modeOptions.strict = {
|
||||
badChars = '\b\f\n\r\t\v',
|
||||
additionalEscapes = false, -- no additional escapes
|
||||
escapeCheck = #lpeg.S('bfnrtv/\\"u'), --only these chars are allowed to be escaped
|
||||
strict_quotes = true
|
||||
}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
local function buildCaptureString(quote, badChars, escapeMatch)
|
||||
local captureChar = (1 - lpeg.S("\\" .. badChars .. quote)) + (lpeg.P("\\") / "" * escapeMatch)
|
||||
-- During error, force end
|
||||
local captureString = captureChar^0 + (-#lpeg.P(quote) * bad_character + -1)
|
||||
return lpeg.P(quote) * lpeg.Cs(captureString) * lpeg.P(quote)
|
||||
end
|
||||
|
||||
local function generateLexer(options)
|
||||
options = options.strings
|
||||
local quotes = { '"' }
|
||||
if not options.strict_quotes then
|
||||
quotes[#quotes + 1] = "'"
|
||||
end
|
||||
local escapeMatch = doSimpleSub
|
||||
escapeMatch = escapeMatch + doXSub / decodeX
|
||||
escapeMatch = escapeMatch + doUniSub / options.decodeUnicode
|
||||
if options.escapeCheck then
|
||||
escapeMatch = options.escapeCheck * escapeMatch + bad_escape
|
||||
end
|
||||
if options.additionalEscapes then
|
||||
escapeMatch = options.additionalEscapes + escapeMatch
|
||||
end
|
||||
local captureString
|
||||
for i = 1, #quotes do
|
||||
local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch)
|
||||
if captureString == nil then
|
||||
captureString = cap
|
||||
else
|
||||
captureString = captureString + cap
|
||||
end
|
||||
end
|
||||
return captureString
|
||||
end
|
||||
|
||||
local strings = {
|
||||
mergeOptions = mergeOptions,
|
||||
generateLexer = generateLexer
|
||||
}
|
||||
|
||||
return strings
|
||||
121
cosmic rage/lua/json/decode/util.lua
Normal file
121
cosmic rage/lua/json/decode/util.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local lpeg = require("lpeg")
|
||||
local select = select
|
||||
local pairs, ipairs = pairs, ipairs
|
||||
local tonumber = tonumber
|
||||
local string_char = require("string").char
|
||||
local rawset = rawset
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local error = error
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local table_concat = require("table").concat
|
||||
|
||||
local merge = require("json.util").merge
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local function get_invalid_character_info(input, index)
|
||||
local parsed = input:sub(1, index)
|
||||
local bad_character = input:sub(index, index)
|
||||
local _, line_number = parsed:gsub('\n',{})
|
||||
local last_line = parsed:match("\n([^\n]+.)$") or parsed
|
||||
return line_number, #last_line, bad_character, last_line
|
||||
end
|
||||
|
||||
local function build_report(msg)
|
||||
local fmt = msg:gsub("%%", "%%%%") .. " @ character: %i %i:%i [%s] line:\n%s"
|
||||
return lpeg.P(function(data, pos)
|
||||
local line, line_index, bad_char, last_line = get_invalid_character_info(data, pos)
|
||||
local text = fmt:format(pos, line, line_index, bad_char, last_line)
|
||||
error(text)
|
||||
end) * 1
|
||||
end
|
||||
local function unexpected()
|
||||
local msg = "unexpected character"
|
||||
return build_report(msg)
|
||||
end
|
||||
local function denied(item, option)
|
||||
local msg
|
||||
if option then
|
||||
msg = ("'%s' denied by option set '%s'"):format(item, option)
|
||||
else
|
||||
msg = ("'%s' denied"):format(item)
|
||||
end
|
||||
return build_report(msg)
|
||||
end
|
||||
|
||||
-- 09, 0A, 0B, 0C, 0D, 20
|
||||
local ascii_space = lpeg.S("\t\n\v\f\r ")
|
||||
local unicode_space
|
||||
do
|
||||
local chr = string_char
|
||||
local u_space = ascii_space
|
||||
-- \u0085 \u00A0
|
||||
u_space = u_space + lpeg.P(chr(0xC2)) * lpeg.S(chr(0x85) .. chr(0xA0))
|
||||
-- \u1680 \u180E
|
||||
u_space = u_space + lpeg.P(chr(0xE1)) * (lpeg.P(chr(0x9A, 0x80)) + chr(0xA0, 0x8E))
|
||||
-- \u2000 - \u200A, also 200B
|
||||
local spacing_end = ""
|
||||
for i = 0x80,0x8b do
|
||||
spacing_end = spacing_end .. chr(i)
|
||||
end
|
||||
-- \u2028 \u2029 \u202F
|
||||
spacing_end = spacing_end .. chr(0xA8) .. chr(0xA9) .. chr(0xAF)
|
||||
u_space = u_space + lpeg.P(chr(0xE2, 0x80)) * lpeg.S(spacing_end)
|
||||
-- \u205F
|
||||
u_space = u_space + lpeg.P(chr(0xE2, 0x81, 0x9F))
|
||||
-- \u3000
|
||||
u_space = u_space + lpeg.P(chr(0xE3, 0x80, 0x80))
|
||||
-- BOM \uFEFF
|
||||
u_space = u_space + lpeg.P(chr(0xEF, 0xBB, 0xBF))
|
||||
unicode_space = u_space
|
||||
end
|
||||
|
||||
local identifier = lpeg.R("AZ","az","__") * lpeg.R("AZ","az", "__", "09") ^0
|
||||
|
||||
local hex = lpeg.R("09","AF","af")
|
||||
local hexpair = hex * hex
|
||||
|
||||
local comments = {
|
||||
cpp = lpeg.P("//") * (1 - lpeg.P("\n"))^0 * lpeg.P("\n"),
|
||||
c = lpeg.P("/*") * (1 - lpeg.P("*/"))^0 * lpeg.P("*/")
|
||||
}
|
||||
|
||||
local comment = comments.cpp + comments.c
|
||||
|
||||
local ascii_ignored = (ascii_space + comment)^0
|
||||
|
||||
local unicode_ignored = (unicode_space + comment)^0
|
||||
|
||||
-- Parse the lpeg version skipping patch-values
|
||||
-- LPEG <= 0.7 have no version value... so 0.7 is value
|
||||
local DecimalLpegVersion = lpeg.version and tonumber(lpeg.version():match("^(%d+%.%d+)")) or 0.7
|
||||
|
||||
local function setObjectKeyForceNumber(t, key, value)
|
||||
key = tonumber(key) or key
|
||||
return rawset(t, key, value)
|
||||
end
|
||||
|
||||
local util = {
|
||||
unexpected = unexpected,
|
||||
denied = denied,
|
||||
ascii_space = ascii_space,
|
||||
unicode_space = unicode_space,
|
||||
identifier = identifier,
|
||||
hex = hex,
|
||||
hexpair = hexpair,
|
||||
comments = comments,
|
||||
comment = comment,
|
||||
ascii_ignored = ascii_ignored,
|
||||
unicode_ignored = unicode_ignored,
|
||||
DecimalLpegVersion = DecimalLpegVersion,
|
||||
get_invalid_character_info = get_invalid_character_info,
|
||||
setObjectKeyForceNumber = setObjectKeyForceNumber
|
||||
}
|
||||
|
||||
return util
|
||||
161
cosmic rage/lua/json/encode.lua
Normal file
161
cosmic rage/lua/json/encode.lua
Normal file
@@ -0,0 +1,161 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local type = type
|
||||
local assert, error = assert, error
|
||||
local getmetatable, setmetatable = getmetatable, setmetatable
|
||||
|
||||
local ipairs, pairs = ipairs, pairs
|
||||
local require = require
|
||||
|
||||
local output = require("json.encode.output")
|
||||
|
||||
local util = require("json.util")
|
||||
local util_merge, isCall = util.merge, util.isCall
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
--[[
|
||||
List of encoding modules to load.
|
||||
Loaded in sequence such that earlier encoders get priority when
|
||||
duplicate type-handlers exist.
|
||||
]]
|
||||
local modulesToLoad = {
|
||||
"strings",
|
||||
"number",
|
||||
"calls",
|
||||
"others",
|
||||
"array",
|
||||
"object"
|
||||
}
|
||||
-- Modules that have been loaded
|
||||
local loadedModules = {}
|
||||
|
||||
local json_encode = {}
|
||||
|
||||
-- Configuration bases for client apps
|
||||
local modes_defined = { "default", "strict" }
|
||||
|
||||
json_encode.default = {}
|
||||
json_encode.strict = {
|
||||
initialObject = true -- Require an object at the root
|
||||
}
|
||||
|
||||
-- For each module, load it and its defaults
|
||||
for _,name in ipairs(modulesToLoad) do
|
||||
local mod = require("json.encode." .. name)
|
||||
if mod.mergeOptions then
|
||||
for _, mode in pairs(modes_defined) do
|
||||
mod.mergeOptions(json_encode[mode], mode)
|
||||
end
|
||||
end
|
||||
loadedModules[name] = mod
|
||||
end
|
||||
|
||||
-- NOTE: Nested not found, so assume unsupported until use case arises
|
||||
local function flattenOutput(out, value)
|
||||
assert(type(value) ~= 'table')
|
||||
out = out or {}
|
||||
out[#out + 1] = value
|
||||
return out
|
||||
end
|
||||
|
||||
-- Prepares the encoding map from the already provided modules and new config
|
||||
local function prepareEncodeMap(options)
|
||||
local map = {}
|
||||
for _, name in ipairs(modulesToLoad) do
|
||||
local encodermap = loadedModules[name].getEncoder(options[name])
|
||||
for valueType, encoderSet in pairs(encodermap) do
|
||||
map[valueType] = flattenOutput(map[valueType], encoderSet)
|
||||
end
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
--[[
|
||||
Encode a value with a given encoding map and state
|
||||
]]
|
||||
local function encodeWithMap(value, map, state, isObjectKey)
|
||||
local t = type(value)
|
||||
local encoderList = assert(map[t], "Failed to encode value, unhandled type: " .. t)
|
||||
for _, encoder in ipairs(encoderList) do
|
||||
local ret = encoder(value, state, isObjectKey)
|
||||
if false ~= ret then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
error("Failed to encode value, encoders for " .. t .. " deny encoding")
|
||||
end
|
||||
|
||||
|
||||
local function getBaseEncoder(options)
|
||||
local encoderMap = prepareEncodeMap(options)
|
||||
if options.preProcess then
|
||||
local preProcess = options.preProcess
|
||||
return function(value, state, isObjectKey)
|
||||
local ret = preProcess(value, isObjectKey or false)
|
||||
if nil ~= ret then
|
||||
value = ret
|
||||
end
|
||||
return encodeWithMap(value, encoderMap, state)
|
||||
end
|
||||
end
|
||||
return function(value, state, isObjectKey)
|
||||
return encodeWithMap(value, encoderMap, state)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
Retreive an initial encoder instance based on provided options
|
||||
the initial encoder is responsible for initializing state
|
||||
State has at least these values configured: encode, check_unique, already_encoded
|
||||
]]
|
||||
function json_encode.getEncoder(options)
|
||||
options = options and util_merge({}, json_encode.default, options) or json_encode.default
|
||||
local encode = getBaseEncoder(options)
|
||||
|
||||
local function initialEncode(value)
|
||||
if options.initialObject then
|
||||
local errorMessage = "Invalid arguments: expects a JSON Object or Array at the root"
|
||||
assert(type(value) == 'table' and not isCall(value, options), errorMessage)
|
||||
end
|
||||
|
||||
local alreadyEncoded = {}
|
||||
local function check_unique(value)
|
||||
assert(not alreadyEncoded[value], "Recursive encoding of value")
|
||||
alreadyEncoded[value] = true
|
||||
end
|
||||
|
||||
local outputEncoder = options.output and options.output() or output.getDefault()
|
||||
local state = {
|
||||
encode = encode,
|
||||
check_unique = check_unique,
|
||||
already_encoded = alreadyEncoded, -- To unmark encoding when moving up stack
|
||||
outputEncoder = outputEncoder
|
||||
}
|
||||
local ret = encode(value, state)
|
||||
if nil ~= ret then
|
||||
return outputEncoder.simple and outputEncoder.simple(ret) or ret
|
||||
end
|
||||
end
|
||||
return initialEncode
|
||||
end
|
||||
|
||||
-- CONSTRUCT STATE WITH FOLLOWING (at least)
|
||||
--[[
|
||||
encoder
|
||||
check_unique -- used by inner encoders to make sure value is unique
|
||||
already_encoded -- used to unmark a value as unique
|
||||
]]
|
||||
function json_encode.encode(data, options)
|
||||
return json_encode.getEncoder(options)(data)
|
||||
end
|
||||
|
||||
local mt = {}
|
||||
mt.__call = function(self, ...)
|
||||
return json_encode.encode(...)
|
||||
end
|
||||
|
||||
setmetatable(json_encode, mt)
|
||||
|
||||
return json_encode
|
||||
110
cosmic rage/lua/json/encode/array.lua
Normal file
110
cosmic rage/lua/json/encode/array.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local type = type
|
||||
local pairs = pairs
|
||||
local assert = assert
|
||||
|
||||
local table = require("table")
|
||||
local math = require("math")
|
||||
local table_concat = table.concat
|
||||
local math_floor, math_modf = math.floor, math.modf
|
||||
|
||||
local jsonutil = require("json.util")
|
||||
local util_IsArray = jsonutil.IsArray
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local defaultOptions = {
|
||||
isArray = util_IsArray
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'array', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
--[[
|
||||
Utility function to determine whether a table is an array or not.
|
||||
Criteria for it being an array:
|
||||
* ExternalIsArray returns true (or false directly reports not-array)
|
||||
* If the table has an 'n' value that is an integer >= 1 then it
|
||||
is an array... may result in false positives (should check some values
|
||||
before it)
|
||||
* It is a contiguous list of values with zero string-based keys
|
||||
]]
|
||||
local function isArray(val, options)
|
||||
local externalIsArray = options and options.isArray
|
||||
|
||||
if externalIsArray then
|
||||
local ret = externalIsArray(val)
|
||||
if ret == true or ret == false then
|
||||
return ret
|
||||
end
|
||||
end
|
||||
-- Use the 'n' element if it's a number
|
||||
if type(val.n) == 'number' and math_floor(val.n) == val.n and val.n >= 1 then
|
||||
return true
|
||||
end
|
||||
local len = #val
|
||||
for k,v in pairs(val) do
|
||||
if type(k) ~= 'number' then
|
||||
return false
|
||||
end
|
||||
local _, decim = math_modf(k)
|
||||
if not (decim == 0 and 1<=k) then
|
||||
return false
|
||||
end
|
||||
if k > len then -- Use Lua's length as absolute determiner
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--[[
|
||||
Cleanup function to unmark a value as in the encoding process and return
|
||||
trailing results
|
||||
]]
|
||||
local function unmarkAfterEncode(tab, state, ...)
|
||||
state.already_encoded[tab] = nil
|
||||
return ...
|
||||
end
|
||||
local function getEncoder(options)
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
local function encodeArray(tab, state)
|
||||
if not isArray(tab, options) then
|
||||
return false
|
||||
end
|
||||
-- Make sure this value hasn't been encoded yet
|
||||
state.check_unique(tab)
|
||||
local encode = state.encode
|
||||
local compositeEncoder = state.outputEncoder.composite
|
||||
local valueEncoder = [[
|
||||
for i = 1, (composite.n or #composite) do
|
||||
local val = composite[i]
|
||||
PUTINNER(i ~= 1)
|
||||
val = encode(val, state)
|
||||
val = val or ''
|
||||
if val then
|
||||
PUTVALUE(val)
|
||||
end
|
||||
end
|
||||
]]
|
||||
return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '[', ']', ',', tab, encode, state))
|
||||
end
|
||||
return { table = encodeArray }
|
||||
end
|
||||
|
||||
local array = {
|
||||
mergeOptions = mergeOptions,
|
||||
isArray = isArray,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return array
|
||||
68
cosmic rage/lua/json/encode/calls.lua
Normal file
68
cosmic rage/lua/json/encode/calls.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local table = require("table")
|
||||
local table_concat = table.concat
|
||||
|
||||
local select = select
|
||||
local getmetatable, setmetatable = getmetatable, setmetatable
|
||||
local assert = assert
|
||||
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local isCall, decodeCall = jsonutil.isCall, jsonutil.decodeCall
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local defaultOptions = {
|
||||
}
|
||||
|
||||
-- No real default-option handling needed...
|
||||
local modeOptions = {}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'calls', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Encodes 'value' as a function call
|
||||
Must have parameters in the 'callData' field of the metatable
|
||||
name == name of the function call
|
||||
parameters == array of parameters to encode
|
||||
]]
|
||||
local function getEncoder(options)
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
local function encodeCall(value, state)
|
||||
if not isCall(value) then
|
||||
return false
|
||||
end
|
||||
local encode = state.encode
|
||||
local name, params = decodeCall(value)
|
||||
local compositeEncoder = state.outputEncoder.composite
|
||||
local valueEncoder = [[
|
||||
for i = 1, (composite.n or #composite) do
|
||||
local val = composite[i]
|
||||
PUTINNER(i ~= 1)
|
||||
val = encode(val, state)
|
||||
val = val or ''
|
||||
if val then
|
||||
PUTVALUE(val)
|
||||
end
|
||||
end
|
||||
]]
|
||||
return compositeEncoder(valueEncoder, name .. '(', ')', ',', params, encode, state)
|
||||
end
|
||||
return {
|
||||
table = encodeCall,
|
||||
['function'] = encodeCall
|
||||
}
|
||||
end
|
||||
|
||||
local calls = {
|
||||
mergeOptions = mergeOptions,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return calls
|
||||
58
cosmic rage/lua/json/encode/number.lua
Normal file
58
cosmic rage/lua/json/encode/number.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local tostring = tostring
|
||||
local assert = assert
|
||||
local jsonutil = require("json.util")
|
||||
local huge = require("math").huge
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local defaultOptions = {
|
||||
nan = true,
|
||||
inf = true
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
modeOptions.strict = {
|
||||
nan = false,
|
||||
inf = false
|
||||
}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
|
||||
local function encodeNumber(number, options)
|
||||
if number ~= number then
|
||||
assert(options.nan, "Invalid number: NaN not enabled")
|
||||
return "NaN"
|
||||
end
|
||||
if number == huge then
|
||||
assert(options.inf, "Invalid number: Infinity not enabled")
|
||||
return "Infinity"
|
||||
end
|
||||
if number == -huge then
|
||||
assert(options.inf, "Invalid number: Infinity not enabled")
|
||||
return "-Infinity"
|
||||
end
|
||||
return tostring(number)
|
||||
end
|
||||
|
||||
local function getEncoder(options)
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
return {
|
||||
number = function(number, state)
|
||||
return encodeNumber(number, options)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
local number = {
|
||||
mergeOptions = mergeOptions,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return number
|
||||
77
cosmic rage/lua/json/encode/object.lua
Normal file
77
cosmic rage/lua/json/encode/object.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local pairs = pairs
|
||||
local assert = assert
|
||||
|
||||
local type = type
|
||||
local tostring = tostring
|
||||
|
||||
local table_concat = require("table").concat
|
||||
local jsonutil = require("json.util")
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local defaultOptions = {
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'object', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
--[[
|
||||
Cleanup function to unmark a value as in the encoding process and return
|
||||
trailing results
|
||||
]]
|
||||
local function unmarkAfterEncode(tab, state, ...)
|
||||
state.already_encoded[tab] = nil
|
||||
return ...
|
||||
end
|
||||
--[[
|
||||
Encode a table as a JSON Object ( keys = strings, values = anything else )
|
||||
]]
|
||||
local function encodeTable(tab, options, state)
|
||||
-- Make sure this value hasn't been encoded yet
|
||||
state.check_unique(tab)
|
||||
local encode = state.encode
|
||||
local compositeEncoder = state.outputEncoder.composite
|
||||
local valueEncoder = [[
|
||||
local first = true
|
||||
for k, v in pairs(composite) do
|
||||
local ti = type(k)
|
||||
assert(ti == 'string' or ti == 'number' or ti == 'boolean', "Invalid object index type: " .. ti)
|
||||
local name = encode(tostring(k), state, true)
|
||||
if first then
|
||||
first = false
|
||||
else
|
||||
name = ',' .. name
|
||||
end
|
||||
PUTVALUE(name .. ':')
|
||||
local val = encode(v, state)
|
||||
val = val or ''
|
||||
if val then
|
||||
PUTVALUE(val)
|
||||
end
|
||||
end
|
||||
]]
|
||||
return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '{', '}', nil, tab, encode, state))
|
||||
end
|
||||
|
||||
local function getEncoder(options)
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
return {
|
||||
table = function(tab, state)
|
||||
return encodeTable(tab, options, state)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
local object = {
|
||||
mergeOptions = mergeOptions,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return object
|
||||
66
cosmic rage/lua/json/encode/others.lua
Normal file
66
cosmic rage/lua/json/encode/others.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local tostring = tostring
|
||||
|
||||
local assert = assert
|
||||
local jsonutil = require("json.util")
|
||||
local type = type
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
-- Shortcut that works
|
||||
local encodeBoolean = tostring
|
||||
|
||||
local defaultOptions = {
|
||||
allowUndefined = true,
|
||||
null = jsonutil.null,
|
||||
undefined = jsonutil.undefined
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
modeOptions.strict = {
|
||||
allowUndefined = false
|
||||
}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
local function getEncoder(options)
|
||||
options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions
|
||||
local function encodeOthers(value, state)
|
||||
if value == options.null then
|
||||
return 'null'
|
||||
elseif value == options.undefined then
|
||||
assert(options.allowUndefined, "Invalid value: Unsupported 'Undefined' parameter")
|
||||
return 'undefined'
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
local function encodeBoolean(value, state)
|
||||
return value and 'true' or 'false'
|
||||
end
|
||||
local nullType = type(options.null)
|
||||
local undefinedType = options.undefined and type(options.undefined)
|
||||
-- Make sure that all of the types handled here are handled
|
||||
local ret = {
|
||||
boolean = encodeBoolean,
|
||||
['nil'] = function() return 'null' end,
|
||||
[nullType] = encodeOthers
|
||||
}
|
||||
if undefinedType then
|
||||
ret[undefinedType] = encodeOthers
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local others = {
|
||||
encodeBoolean = encodeBoolean,
|
||||
mergeOptions = mergeOptions,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return others
|
||||
91
cosmic rage/lua/json/encode/output.lua
Normal file
91
cosmic rage/lua/json/encode/output.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local type = type
|
||||
local assert, error = assert, error
|
||||
local table_concat = require("table").concat
|
||||
local loadstring = loadstring or load
|
||||
|
||||
local io = require("io")
|
||||
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local output_utility = require("json.encode.output_utility")
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local tableCompositeCache = setmetatable({}, {__mode = 'v'})
|
||||
|
||||
local TABLE_VALUE_WRITER = [[
|
||||
ret[#ret + 1] = %VALUE%
|
||||
]]
|
||||
|
||||
local TABLE_INNER_WRITER = ""
|
||||
|
||||
--[[
|
||||
nextValues can output a max of two values to throw into the data stream
|
||||
expected to be called until nil is first return value
|
||||
value separator should either be attached to v1 or in innerValue
|
||||
]]
|
||||
local function defaultTableCompositeWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state)
|
||||
if type(nextValues) == 'string' then
|
||||
local fun = output_utility.prepareEncoder(defaultTableCompositeWriter, nextValues, innerValue, TABLE_VALUE_WRITER, TABLE_INNER_WRITER)
|
||||
local ret = {}
|
||||
fun(composite, ret, encode, state)
|
||||
return beginValue .. table_concat(ret, innerValue) .. closeValue
|
||||
end
|
||||
end
|
||||
|
||||
-- no 'simple' as default action is just to return the value
|
||||
local function getDefault()
|
||||
return { composite = defaultTableCompositeWriter }
|
||||
end
|
||||
|
||||
-- BEGIN IO-WRITER OUTPUT
|
||||
local IO_INNER_WRITER = [[
|
||||
if %WRITE_INNER% then
|
||||
state.__outputFile:write(%INNER_VALUE%)
|
||||
end
|
||||
]]
|
||||
local IO_VALUE_WRITER = [[
|
||||
state.__outputFile:write(%VALUE%)
|
||||
]]
|
||||
|
||||
local function buildIoWriter(output)
|
||||
if not output then -- Default to stdout
|
||||
output = io.output()
|
||||
end
|
||||
local function ioWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state)
|
||||
-- HOOK OUTPUT STATE
|
||||
state.__outputFile = output
|
||||
if type(nextValues) == 'string' then
|
||||
local fun = output_utility.prepareEncoder(ioWriter, nextValues, innerValue, IO_VALUE_WRITER, IO_INNER_WRITER)
|
||||
local ret = {}
|
||||
output:write(beginValue)
|
||||
fun(composite, ret, encode, state)
|
||||
output:write(closeValue)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local function ioSimpleWriter(encoded)
|
||||
if encoded then
|
||||
output:write(encoded)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
return { composite = ioWriter, simple = ioSimpleWriter }
|
||||
end
|
||||
local function getIoWriter(output)
|
||||
return function()
|
||||
return buildIoWriter(output)
|
||||
end
|
||||
end
|
||||
|
||||
local output = {
|
||||
getDefault = getDefault,
|
||||
getIoWriter = getIoWriter
|
||||
}
|
||||
|
||||
return output
|
||||
54
cosmic rage/lua/json/encode/output_utility.lua
Normal file
54
cosmic rage/lua/json/encode/output_utility.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local setmetatable = setmetatable
|
||||
local assert, loadstring = assert, loadstring or load
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
-- Key == weak, if main key goes away, then cache cleared
|
||||
local outputCache = setmetatable({}, {__mode = 'k'})
|
||||
-- TODO: inner tables weak?
|
||||
|
||||
local function buildFunction(nextValues, innerValue, valueWriter, innerWriter)
|
||||
local putInner = ""
|
||||
if innerValue and innerWriter then
|
||||
-- Prepare the lua-string representation of the separator to put in between values
|
||||
local formattedInnerValue = ("%q"):format(innerValue)
|
||||
-- Fill in the condition %WRITE_INNER% and the %INNER_VALUE% to actually write
|
||||
putInner = innerWriter:gsub("%%WRITE_INNER%%", "%%1"):gsub("%%INNER_VALUE%%", formattedInnerValue)
|
||||
end
|
||||
-- Template-in the value writer (if present) and its conditional argument
|
||||
local functionCode = nextValues:gsub("PUTINNER(%b())", putInner)
|
||||
-- %VALUE% is to be filled in by the value-to-write
|
||||
valueWriter = valueWriter:gsub("%%VALUE%%", "%%1")
|
||||
-- Template-in the value writer with its argument
|
||||
functionCode = functionCode:gsub("PUTVALUE(%b())", valueWriter)
|
||||
functionCode = [[
|
||||
return function(composite, ret, encode, state)
|
||||
]] .. functionCode .. [[
|
||||
end
|
||||
]]
|
||||
return assert(loadstring(functionCode))()
|
||||
end
|
||||
|
||||
local function prepareEncoder(cacheKey, nextValues, innerValue, valueWriter, innerWriter)
|
||||
local cache = outputCache[cacheKey]
|
||||
if not cache then
|
||||
cache = {}
|
||||
outputCache[cacheKey] = cache
|
||||
end
|
||||
local fun = cache[nextValues]
|
||||
if not fun then
|
||||
fun = buildFunction(nextValues, innerValue, valueWriter, innerWriter)
|
||||
cache[nextValues] = fun
|
||||
end
|
||||
return fun
|
||||
end
|
||||
|
||||
local output_utility = {
|
||||
prepareEncoder = prepareEncoder
|
||||
}
|
||||
|
||||
return output_utility
|
||||
88
cosmic rage/lua/json/encode/strings.lua
Normal file
88
cosmic rage/lua/json/encode/strings.lua
Normal file
@@ -0,0 +1,88 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local string_char = require("string").char
|
||||
local pairs = pairs
|
||||
|
||||
local jsonutil = require("json.util")
|
||||
local util_merge = jsonutil.merge
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local normalEncodingMap = {
|
||||
['"'] = '\\"',
|
||||
['\\'] = '\\\\',
|
||||
['/'] = '\\/',
|
||||
['\b'] = '\\b',
|
||||
['\f'] = '\\f',
|
||||
['\n'] = '\\n',
|
||||
['\r'] = '\\r',
|
||||
['\t'] = '\\t',
|
||||
['\v'] = '\\v' -- not in official spec, on report, removing
|
||||
}
|
||||
|
||||
local xEncodingMap = {}
|
||||
for char, encoded in pairs(normalEncodingMap) do
|
||||
xEncodingMap[char] = encoded
|
||||
end
|
||||
|
||||
-- Pre-encode the control characters to speed up encoding...
|
||||
-- NOTE: UTF-8 may not work out right w/ JavaScript
|
||||
-- JavaScript uses 2 bytes after a \u... yet UTF-8 is a
|
||||
-- byte-stream encoding, not pairs of bytes (it does encode
|
||||
-- some letters > 1 byte, but base case is 1)
|
||||
for i = 0, 255 do
|
||||
local c = string_char(i)
|
||||
if c:match('[%z\1-\031\128-\255]') and not normalEncodingMap[c] then
|
||||
-- WARN: UTF8 specializes values >= 0x80 as parts of sequences...
|
||||
-- without \x encoding, do not allow encoding > 7F
|
||||
normalEncodingMap[c] = ('\\u%.4X'):format(i)
|
||||
xEncodingMap[c] = ('\\x%.2X'):format(i)
|
||||
end
|
||||
end
|
||||
|
||||
local defaultOptions = {
|
||||
xEncode = false, -- Encode single-bytes as \xXX
|
||||
processor = nil, -- Simple processor for the string prior to quoting
|
||||
-- / is not required to be quoted but it helps with certain decoding
|
||||
-- Required encoded characters, " \, and 00-1F (0 - 31)
|
||||
encodeSet = '\\"/%z\1-\031',
|
||||
encodeSetAppend = nil -- Chars to append to the default set
|
||||
}
|
||||
|
||||
local modeOptions = {}
|
||||
|
||||
local function mergeOptions(options, mode)
|
||||
jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode])
|
||||
end
|
||||
|
||||
local function getEncoder(options)
|
||||
options = options and util_merge({}, defaultOptions, options) or defaultOptions
|
||||
local encodeSet = options.encodeSet
|
||||
if options.encodeSetAppend then
|
||||
encodeSet = encodeSet .. options.encodeSetAppend
|
||||
end
|
||||
local encodingMap = options.xEncode and xEncodingMap or normalEncodingMap
|
||||
local encodeString
|
||||
if options.processor then
|
||||
local processor = options.processor
|
||||
encodeString = function(s, state)
|
||||
return '"' .. processor(s:gsub('[' .. encodeSet .. ']', encodingMap)) .. '"'
|
||||
end
|
||||
else
|
||||
encodeString = function(s, state)
|
||||
return '"' .. s:gsub('[' .. encodeSet .. ']', encodingMap) .. '"'
|
||||
end
|
||||
end
|
||||
return {
|
||||
string = encodeString
|
||||
}
|
||||
end
|
||||
|
||||
local strings = {
|
||||
mergeOptions = mergeOptions,
|
||||
getEncoder = getEncoder
|
||||
}
|
||||
|
||||
return strings
|
||||
152
cosmic rage/lua/json/util.lua
Normal file
152
cosmic rage/lua/json/util.lua
Normal file
@@ -0,0 +1,152 @@
|
||||
--[[
|
||||
Licensed according to the included 'LICENSE' document
|
||||
Author: Thomas Harning Jr <harningt@gmail.com>
|
||||
]]
|
||||
local type = type
|
||||
local print = print
|
||||
local tostring = tostring
|
||||
local pairs = pairs
|
||||
local getmetatable, setmetatable = getmetatable, setmetatable
|
||||
local select = select
|
||||
|
||||
local _ENV = nil
|
||||
|
||||
local function foreach(tab, func)
|
||||
for k, v in pairs(tab) do
|
||||
func(k,v)
|
||||
end
|
||||
end
|
||||
local function printValue(tab, name)
|
||||
local parsed = {}
|
||||
local function doPrint(key, value, space)
|
||||
space = space or ''
|
||||
if type(value) == 'table' then
|
||||
if parsed[value] then
|
||||
print(space .. key .. '= <' .. parsed[value] .. '>')
|
||||
else
|
||||
parsed[value] = key
|
||||
print(space .. key .. '= {')
|
||||
space = space .. ' '
|
||||
foreach(value, function(key, value) doPrint(key, value, space) end)
|
||||
end
|
||||
else
|
||||
if type(value) == 'string' then
|
||||
value = '[[' .. tostring(value) .. ']]'
|
||||
end
|
||||
print(space .. key .. '=' .. tostring(value))
|
||||
end
|
||||
end
|
||||
doPrint(name, tab)
|
||||
end
|
||||
|
||||
local function clone(t)
|
||||
local ret = {}
|
||||
for k,v in pairs(t) do
|
||||
ret[k] = v
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local function inner_merge(t, remaining, from, ...)
|
||||
if remaining == 0 then
|
||||
return t
|
||||
end
|
||||
if from then
|
||||
for k,v in pairs(from) do
|
||||
t[k] = v
|
||||
end
|
||||
end
|
||||
return inner_merge(t, remaining - 1, ...)
|
||||
end
|
||||
|
||||
--[[*
|
||||
Shallow-merges tables in order onto the first table.
|
||||
|
||||
@param t table to merge entries onto
|
||||
@param ... sequence of 0 or more tables to merge onto 't'
|
||||
|
||||
@returns table 't' from input
|
||||
]]
|
||||
local function merge(t, ...)
|
||||
return inner_merge(t, select('#', ...), ...)
|
||||
end
|
||||
|
||||
-- Function to insert nulls into the JSON stream
|
||||
local function null()
|
||||
return null
|
||||
end
|
||||
|
||||
-- Marker for 'undefined' values
|
||||
local function undefined()
|
||||
return undefined
|
||||
end
|
||||
|
||||
local ArrayMT = {}
|
||||
|
||||
--[[
|
||||
Return's true if the metatable marks it as an array..
|
||||
Or false if it has no array component at all
|
||||
Otherwise nil to get the normal detection component working
|
||||
]]
|
||||
local function IsArray(value)
|
||||
if type(value) ~= 'table' then return false end
|
||||
local meta = getmetatable(value)
|
||||
local ret = meta == ArrayMT or (meta ~= nil and meta.__is_luajson_array)
|
||||
if not ret then
|
||||
if #value == 0 then return false end
|
||||
else
|
||||
return ret
|
||||
end
|
||||
end
|
||||
local function InitArray(array)
|
||||
setmetatable(array, ArrayMT)
|
||||
return array
|
||||
end
|
||||
|
||||
local CallMT = {}
|
||||
|
||||
local function isCall(value)
|
||||
return CallMT == getmetatable(value)
|
||||
end
|
||||
|
||||
local function buildCall(name, ...)
|
||||
local callData = {
|
||||
name = name,
|
||||
parameters = {n = select('#', ...), ...}
|
||||
}
|
||||
return setmetatable(callData, CallMT)
|
||||
end
|
||||
|
||||
local function decodeCall(callData)
|
||||
if not isCall(callData) then return nil end
|
||||
return callData.name, callData.parameters
|
||||
end
|
||||
|
||||
local function doOptionMerge(options, nested, name, defaultOptions, modeOptions)
|
||||
if nested then
|
||||
modeOptions = modeOptions and modeOptions[name]
|
||||
defaultOptions = defaultOptions and defaultOptions[name]
|
||||
end
|
||||
options[name] = merge(
|
||||
{},
|
||||
defaultOptions,
|
||||
modeOptions,
|
||||
options[name]
|
||||
)
|
||||
end
|
||||
|
||||
local json_util = {
|
||||
printValue = printValue,
|
||||
clone = clone,
|
||||
merge = merge,
|
||||
null = null,
|
||||
undefined = undefined,
|
||||
IsArray = IsArray,
|
||||
InitArray = InitArray,
|
||||
isCall = isCall,
|
||||
buildCall = buildCall,
|
||||
decodeCall = decodeCall,
|
||||
doOptionMerge = doOptionMerge
|
||||
}
|
||||
|
||||
return json_util
|
||||
292
cosmic rage/lua/ltn12.lua
Normal file
292
cosmic rage/lua/ltn12.lua
Normal file
@@ -0,0 +1,292 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- LTN12 - Filters, sources, sinks and pumps.
|
||||
-- LuaSocket toolkit.
|
||||
-- Author: Diego Nehab
|
||||
-- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Declare module
|
||||
-----------------------------------------------------------------------------
|
||||
local string = require("string")
|
||||
local table = require("table")
|
||||
local base = _G
|
||||
module("ltn12")
|
||||
|
||||
filter = {}
|
||||
source = {}
|
||||
sink = {}
|
||||
pump = {}
|
||||
|
||||
-- 2048 seems to be better in windows...
|
||||
BLOCKSIZE = 2048
|
||||
_VERSION = "LTN12 1.0.1"
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Filter stuff
|
||||
-----------------------------------------------------------------------------
|
||||
-- returns a high level filter that cycles a low-level filter
|
||||
function filter.cycle(low, ctx, extra)
|
||||
base.assert(low)
|
||||
return function(chunk)
|
||||
local ret
|
||||
ret, ctx = low(ctx, chunk, extra)
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
-- chains a bunch of filters together
|
||||
-- (thanks to Wim Couwenberg)
|
||||
function filter.chain(...)
|
||||
local n = table.getn(arg)
|
||||
local top, index = 1, 1
|
||||
local retry = ""
|
||||
return function(chunk)
|
||||
retry = chunk and retry
|
||||
while true do
|
||||
if index == top then
|
||||
chunk = arg[index](chunk)
|
||||
if chunk == "" or top == n then return chunk
|
||||
elseif chunk then index = index + 1
|
||||
else
|
||||
top = top+1
|
||||
index = top
|
||||
end
|
||||
else
|
||||
chunk = arg[index](chunk or "")
|
||||
if chunk == "" then
|
||||
index = index - 1
|
||||
chunk = retry
|
||||
elseif chunk then
|
||||
if index == n then return chunk
|
||||
else index = index + 1 end
|
||||
else base.error("filter returned inappropriate nil") end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Source stuff
|
||||
-----------------------------------------------------------------------------
|
||||
-- create an empty source
|
||||
local function empty()
|
||||
return nil
|
||||
end
|
||||
|
||||
function source.empty()
|
||||
return empty
|
||||
end
|
||||
|
||||
-- returns a source that just outputs an error
|
||||
function source.error(err)
|
||||
return function()
|
||||
return nil, err
|
||||
end
|
||||
end
|
||||
|
||||
-- creates a file source
|
||||
function source.file(handle, io_err)
|
||||
if handle then
|
||||
return function()
|
||||
local chunk = handle:read(BLOCKSIZE)
|
||||
if not chunk then handle:close() end
|
||||
return chunk
|
||||
end
|
||||
else return source.error(io_err or "unable to open file") end
|
||||
end
|
||||
|
||||
-- turns a fancy source into a simple source
|
||||
function source.simplify(src)
|
||||
base.assert(src)
|
||||
return function()
|
||||
local chunk, err_or_new = src()
|
||||
src = err_or_new or src
|
||||
if not chunk then return nil, err_or_new
|
||||
else return chunk end
|
||||
end
|
||||
end
|
||||
|
||||
-- creates string source
|
||||
function source.string(s)
|
||||
if s then
|
||||
local i = 1
|
||||
return function()
|
||||
local chunk = string.sub(s, i, i+BLOCKSIZE-1)
|
||||
i = i + BLOCKSIZE
|
||||
if chunk ~= "" then return chunk
|
||||
else return nil end
|
||||
end
|
||||
else return source.empty() end
|
||||
end
|
||||
|
||||
-- creates rewindable source
|
||||
function source.rewind(src)
|
||||
base.assert(src)
|
||||
local t = {}
|
||||
return function(chunk)
|
||||
if not chunk then
|
||||
chunk = table.remove(t)
|
||||
if not chunk then return src()
|
||||
else return chunk end
|
||||
else
|
||||
table.insert(t, chunk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function source.chain(src, f)
|
||||
base.assert(src and f)
|
||||
local last_in, last_out = "", ""
|
||||
local state = "feeding"
|
||||
local err
|
||||
return function()
|
||||
if not last_out then
|
||||
base.error('source is empty!', 2)
|
||||
end
|
||||
while true do
|
||||
if state == "feeding" then
|
||||
last_in, err = src()
|
||||
if err then return nil, err end
|
||||
last_out = f(last_in)
|
||||
if not last_out then
|
||||
if last_in then
|
||||
base.error('filter returned inappropriate nil')
|
||||
else
|
||||
return nil
|
||||
end
|
||||
elseif last_out ~= "" then
|
||||
state = "eating"
|
||||
if last_in then last_in = "" end
|
||||
return last_out
|
||||
end
|
||||
else
|
||||
last_out = f(last_in)
|
||||
if last_out == "" then
|
||||
if last_in == "" then
|
||||
state = "feeding"
|
||||
else
|
||||
base.error('filter returned ""')
|
||||
end
|
||||
elseif not last_out then
|
||||
if last_in then
|
||||
base.error('filter returned inappropriate nil')
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
return last_out
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- creates a source that produces contents of several sources, one after the
|
||||
-- other, as if they were concatenated
|
||||
-- (thanks to Wim Couwenberg)
|
||||
function source.cat(...)
|
||||
local src = table.remove(arg, 1)
|
||||
return function()
|
||||
while src do
|
||||
local chunk, err = src()
|
||||
if chunk then return chunk end
|
||||
if err then return nil, err end
|
||||
src = table.remove(arg, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Sink stuff
|
||||
-----------------------------------------------------------------------------
|
||||
-- creates a sink that stores into a table
|
||||
function sink.table(t)
|
||||
t = t or {}
|
||||
local f = function(chunk, err)
|
||||
if chunk then table.insert(t, chunk) end
|
||||
return 1
|
||||
end
|
||||
return f, t
|
||||
end
|
||||
|
||||
-- turns a fancy sink into a simple sink
|
||||
function sink.simplify(snk)
|
||||
base.assert(snk)
|
||||
return function(chunk, err)
|
||||
local ret, err_or_new = snk(chunk, err)
|
||||
if not ret then return nil, err_or_new end
|
||||
snk = err_or_new or snk
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
-- creates a file sink
|
||||
function sink.file(handle, io_err)
|
||||
if handle then
|
||||
return function(chunk, err)
|
||||
if not chunk then
|
||||
handle:close()
|
||||
return 1
|
||||
else return handle:write(chunk) end
|
||||
end
|
||||
else return sink.error(io_err or "unable to open file") end
|
||||
end
|
||||
|
||||
-- creates a sink that discards data
|
||||
local function null()
|
||||
return 1
|
||||
end
|
||||
|
||||
function sink.null()
|
||||
return null
|
||||
end
|
||||
|
||||
-- creates a sink that just returns an error
|
||||
function sink.error(err)
|
||||
return function()
|
||||
return nil, err
|
||||
end
|
||||
end
|
||||
|
||||
-- chains a sink with a filter
|
||||
function sink.chain(f, snk)
|
||||
base.assert(f and snk)
|
||||
return function(chunk, err)
|
||||
if chunk ~= "" then
|
||||
local filtered = f(chunk)
|
||||
local done = chunk and ""
|
||||
while true do
|
||||
local ret, snkerr = snk(filtered, err)
|
||||
if not ret then return nil, snkerr end
|
||||
if filtered == done then return 1 end
|
||||
filtered = f(done)
|
||||
end
|
||||
else return 1 end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Pump stuff
|
||||
-----------------------------------------------------------------------------
|
||||
-- pumps one chunk from the source to the sink
|
||||
function pump.step(src, snk)
|
||||
local chunk, src_err = src()
|
||||
local ret, snk_err = snk(chunk, src_err)
|
||||
if chunk and ret then return 1
|
||||
else return nil, src_err or snk_err end
|
||||
end
|
||||
|
||||
-- pumps all data from a source to a sink, using a step function
|
||||
function pump.all(src, snk, step)
|
||||
base.assert(src and snk)
|
||||
step = step or pump.step
|
||||
while true do
|
||||
local ret, err = step(src, snk)
|
||||
if not ret then
|
||||
if err then return nil, err
|
||||
else return 1 end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
1001
cosmic rage/lua/luacom5.lua
Normal file
1001
cosmic rage/lua/luacom5.lua
Normal file
File diff suppressed because it is too large
Load Diff
1633
cosmic rage/lua/mapper.lua
Normal file
1633
cosmic rage/lua/mapper.lua
Normal file
File diff suppressed because it is too large
Load Diff
87
cosmic rage/lua/mime.lua
Normal file
87
cosmic rage/lua/mime.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- MIME support for the Lua language.
|
||||
-- Author: Diego Nehab
|
||||
-- Conforming to RFCs 2045-2049
|
||||
-- RCS ID: $Id: mime.lua,v 1.29 2007/06/11 23:44:54 diego Exp $
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Declare module and import dependencies
|
||||
-----------------------------------------------------------------------------
|
||||
local base = _G
|
||||
local ltn12 = require("ltn12")
|
||||
local mime = require("mime.core")
|
||||
local io = require("io")
|
||||
local string = require("string")
|
||||
module("mime")
|
||||
|
||||
-- encode, decode and wrap algorithm tables
|
||||
encodet = {}
|
||||
decodet = {}
|
||||
wrapt = {}
|
||||
|
||||
-- creates a function that chooses a filter by name from a given table
|
||||
local function choose(table)
|
||||
return function(name, opt1, opt2)
|
||||
if base.type(name) ~= "string" then
|
||||
name, opt1, opt2 = "default", name, opt1
|
||||
end
|
||||
local f = table[name or "nil"]
|
||||
if not f then
|
||||
base.error("unknown key (" .. base.tostring(name) .. ")", 3)
|
||||
else return f(opt1, opt2) end
|
||||
end
|
||||
end
|
||||
|
||||
-- define the encoding filters
|
||||
encodet['base64'] = function()
|
||||
return ltn12.filter.cycle(b64, "")
|
||||
end
|
||||
|
||||
encodet['quoted-printable'] = function(mode)
|
||||
return ltn12.filter.cycle(qp, "",
|
||||
(mode == "binary") and "=0D=0A" or "\r\n")
|
||||
end
|
||||
|
||||
-- define the decoding filters
|
||||
decodet['base64'] = function()
|
||||
return ltn12.filter.cycle(unb64, "")
|
||||
end
|
||||
|
||||
decodet['quoted-printable'] = function()
|
||||
return ltn12.filter.cycle(unqp, "")
|
||||
end
|
||||
|
||||
local function format(chunk)
|
||||
if chunk then
|
||||
if chunk == "" then return "''"
|
||||
else return string.len(chunk) end
|
||||
else return "nil" end
|
||||
end
|
||||
|
||||
-- define the line-wrap filters
|
||||
wrapt['text'] = function(length)
|
||||
length = length or 76
|
||||
return ltn12.filter.cycle(wrp, length, length)
|
||||
end
|
||||
wrapt['base64'] = wrapt['text']
|
||||
wrapt['default'] = wrapt['text']
|
||||
|
||||
wrapt['quoted-printable'] = function()
|
||||
return ltn12.filter.cycle(qpwrp, 76, 76)
|
||||
end
|
||||
|
||||
-- function that choose the encoding, decoding or wrap algorithm
|
||||
encode = choose(encodet)
|
||||
decode = choose(decodet)
|
||||
wrap = choose(wrapt)
|
||||
|
||||
-- define the end-of-line normalization filter
|
||||
function normalize(marker)
|
||||
return ltn12.filter.cycle(eol, 0, marker)
|
||||
end
|
||||
|
||||
-- high level stuffing filter
|
||||
function stuff()
|
||||
return ltn12.filter.cycle(dot, 2)
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user