summaryrefslogtreecommitdiff
path: root/tolua
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-10-09 11:45:47 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2014-10-09 11:45:47 +0200
commitc439b87bc9bc4d25982ec0044468bd405fac8296 (patch)
treeb19c1a4a81491f356f1fbc69f94fa88731ac3dda /tolua
parent0c04c39ba95d38418b2bc4c78e7ce52483e4d96b (diff)
downloadcrawler-c439b87bc9bc4d25982ec0044468bd405fac8296.tar.gz
crawler-c439b87bc9bc4d25982ec0044468bd405fac8296.tar.bz2
dos2unix for lua code in tolua
Diffstat (limited to 'tolua')
-rw-r--r--tolua/src/bin/lua/basic.lua424
-rw-r--r--tolua/src/bin/lua/clean.lua150
-rw-r--r--tolua/src/bin/lua/compat.lua402
3 files changed, 488 insertions, 488 deletions
diff --git a/tolua/src/bin/lua/basic.lua b/tolua/src/bin/lua/basic.lua
index 0bfe8bb..26ceb4c 100644
--- a/tolua/src/bin/lua/basic.lua
+++ b/tolua/src/bin/lua/basic.lua
@@ -1,212 +1,212 @@
--- tolua: basic utility functions
--- Written by Waldemar Celes
--- TeCGraf/PUC-Rio
--- Jul 1998
--- Last update: Apr 2003
--- $Id: basic.lua,v 1.4 2009/11/24 16:45:13 fabraham Exp $
-
--- This code is free software; you can redistribute it and/or modify it.
--- The software provided hereunder is on an "as is" basis, and
--- the author has no obligation to provide maintenance, support, updates,
--- enhancements, or modifications.
-
-
--- Basic C types and their corresponding Lua types
--- All occurrences of "char*" will be replaced by "_cstring",
--- and all occurrences of "void*" will be replaced by "_userdata"
-_basic = {
- ['void'] = '',
- ['char'] = 'number',
- ['tolua_index'] = 'number',
- ['tolua_byte'] = 'number',
- ['tolua_ubyte'] = 'number',
- ['int'] = 'number',
- ['short'] = 'number',
- ['long'] = 'number',
- ['unsigned'] = 'number',
- ['float'] = 'number',
- ['double'] = 'number',
- ['_cstring'] = 'string',
- ['_userdata'] = 'userdata',
- ['char*'] = 'string',
- ['void*'] = 'userdata',
- ['bool'] = 'boolean',
- ['lua_State*'] = 'state',
- ['_lstate'] = 'state',
- ['lua_Object'] = 'value',
- ['lua_Function'] = 'function',
- ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.0
-}
-
-_basic_ctype = {
- number = "lua_Number",
- string = "const char*",
- userdata = "void*",
- boolean = "bool",
- value = "int",
-}
-
--- List of user defined types
--- Each type corresponds to a variable name that stores its tag value.
-_usertype = {}
-
--- List of types that have to be collected
-_collect = {}
-
-
--- List of auto renaming
-_renaming = {}
-function appendrenaming (s)
- local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$")
- if not b then
- error("#Invalid renaming syntax; it should be of the form: pattern@pattern")
- end
- tinsert(_renaming,{old=old, new=new})
-end
-
-function applyrenaming (s)
- for i=1,getn(_renaming) do
- local m,n = gsub(s,_renaming[i].old,_renaming[i].new)
- if n ~= 0 then
- return m
- end
- end
- return nil
-end
-
--- Error handler
-function tolua_error (s,f)
- local out = _OUTPUT
- _OUTPUT = _STDERR
- if strsub(s,1,1) == '#' then
- write("\n** tolua: "..strsub(s,2)..".\n\n")
- if _curr_code then
- local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line
- if s==nil then s = _curr_code end
- s = gsub(s,"_userdata","void*") -- return with 'void*'
- s = gsub(s,"_cstring","char*") -- return with 'char*'
- s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*'
- write("Code being processed:\n"..s.."\n")
- end
- else
- print(debug.traceback("\n** tolua internal error: "..f..s..".\n\n"))
- return
- end
- _OUTPUT = out
-end
-
-function warning (msg)
- local out = _OUTPUT
- _OUTPUT = _STDERR
- write("\n** tolua warning: "..msg..".\n\n")
- _OUTPUT = out
-end
-
--- register an user defined type: returns full type
-function regtype (t)
- local ft = findtype(t)
- if isbasic(t) then
- return t
- end
- if not ft then
- return appendusertype(t)
- end
-end
-
--- return type name: returns full type
-function typevar(type)
- if type == '' or type == 'void' or type == "..." then
- return type
- else
- local ft = findtype(type)
- if ft then
- return ft
- end
- _usertype[type] = type
- return type
- end
-end
-
--- check if basic type
-function isbasic (type)
- local t = gsub(type,'const ','')
- local m,t = applytypedef(t)
- local b = _basic[t]
- if b then
- return b,_basic_ctype[b]
- end
- return nil
-end
-
--- split string using a token
-function split (s,t)
- local l = {n=0}
- local f = function (s)
- l.n = l.n + 1
- l[l.n] = s
- return ""
- end
- local p = "%s*(.-)%s*"..t.."%s*"
- s = gsub(s,"^%s+","")
- s = gsub(s,"%s+$","")
- s = gsub(s,p,f)
- l.n = l.n + 1
- l[l.n] = gsub(s,"(%s%s*)$","")
- return l
-end
-
-
--- concatenate strings of a table
-function concat (t,f,l)
- local s = ''
- local i=f
- while i<=l do
- s = s..t[i]
- i = i+1
- if i <= l then s = s..' ' end
- end
- return s
-end
-
--- concatenate all parameters, following output rules
-function concatparam (line, ...)
- local arg = {...}
- local i=1
- while i<=#arg do
- if _cont and not strfind(_cont,'[%(,"]') and
- strfind(arg[i],"^[%a_~]") then
- line = line .. ' '
- end
- line = line .. arg[i]
- if arg[i] ~= '' then
- _cont = strsub(arg[i],-1,-1)
- end
- i = i+1
- end
- if strfind(arg[#arg],"[%/%)%;%{%}]$") then
- _cont=nil line = line .. '\n'
- end
- return line
-end
-
--- output line
-function output (...)
- local arg = {...}
- local i=1
- while i<=#arg do
- if _cont and not strfind(_cont,'[%(,"]') and
- strfind(arg[i],"^[%a_~]") then
- write(' ')
- end
- write(arg[i])
- if arg[i] ~= '' then
- _cont = strsub(arg[i],-1,-1)
- end
- i = i+1
- end
- if strfind(arg[#arg],"[%/%)%;%{%}]$") then
- _cont=nil write('\n')
- end
-end
-
-
+-- tolua: basic utility functions
+-- Written by Waldemar Celes
+-- TeCGraf/PUC-Rio
+-- Jul 1998
+-- Last update: Apr 2003
+-- $Id: basic.lua,v 1.4 2009/11/24 16:45:13 fabraham Exp $
+
+-- This code is free software; you can redistribute it and/or modify it.
+-- The software provided hereunder is on an "as is" basis, and
+-- the author has no obligation to provide maintenance, support, updates,
+-- enhancements, or modifications.
+
+
+-- Basic C types and their corresponding Lua types
+-- All occurrences of "char*" will be replaced by "_cstring",
+-- and all occurrences of "void*" will be replaced by "_userdata"
+_basic = {
+ ['void'] = '',
+ ['char'] = 'number',
+ ['tolua_index'] = 'number',
+ ['tolua_byte'] = 'number',
+ ['tolua_ubyte'] = 'number',
+ ['int'] = 'number',
+ ['short'] = 'number',
+ ['long'] = 'number',
+ ['unsigned'] = 'number',
+ ['float'] = 'number',
+ ['double'] = 'number',
+ ['_cstring'] = 'string',
+ ['_userdata'] = 'userdata',
+ ['char*'] = 'string',
+ ['void*'] = 'userdata',
+ ['bool'] = 'boolean',
+ ['lua_State*'] = 'state',
+ ['_lstate'] = 'state',
+ ['lua_Object'] = 'value',
+ ['lua_Function'] = 'function',
+ ['LUA_VALUE'] = 'value', -- for compatibility with tolua 4.0
+}
+
+_basic_ctype = {
+ number = "lua_Number",
+ string = "const char*",
+ userdata = "void*",
+ boolean = "bool",
+ value = "int",
+}
+
+-- List of user defined types
+-- Each type corresponds to a variable name that stores its tag value.
+_usertype = {}
+
+-- List of types that have to be collected
+_collect = {}
+
+
+-- List of auto renaming
+_renaming = {}
+function appendrenaming (s)
+ local b,e,old,new = strfind(s,"%s*(.-)%s*@%s*(.-)%s*$")
+ if not b then
+ error("#Invalid renaming syntax; it should be of the form: pattern@pattern")
+ end
+ tinsert(_renaming,{old=old, new=new})
+end
+
+function applyrenaming (s)
+ for i=1,getn(_renaming) do
+ local m,n = gsub(s,_renaming[i].old,_renaming[i].new)
+ if n ~= 0 then
+ return m
+ end
+ end
+ return nil
+end
+
+-- Error handler
+function tolua_error (s,f)
+ local out = _OUTPUT
+ _OUTPUT = _STDERR
+ if strsub(s,1,1) == '#' then
+ write("\n** tolua: "..strsub(s,2)..".\n\n")
+ if _curr_code then
+ local _,_,s = strfind(_curr_code,"^%s*(.-\n)") -- extract first line
+ if s==nil then s = _curr_code end
+ s = gsub(s,"_userdata","void*") -- return with 'void*'
+ s = gsub(s,"_cstring","char*") -- return with 'char*'
+ s = gsub(s,"_lstate","lua_State*") -- return with 'lua_State*'
+ write("Code being processed:\n"..s.."\n")
+ end
+ else
+ print(debug.traceback("\n** tolua internal error: "..f..s..".\n\n"))
+ return
+ end
+ _OUTPUT = out
+end
+
+function warning (msg)
+ local out = _OUTPUT
+ _OUTPUT = _STDERR
+ write("\n** tolua warning: "..msg..".\n\n")
+ _OUTPUT = out
+end
+
+-- register an user defined type: returns full type
+function regtype (t)
+ local ft = findtype(t)
+ if isbasic(t) then
+ return t
+ end
+ if not ft then
+ return appendusertype(t)
+ end
+end
+
+-- return type name: returns full type
+function typevar(type)
+ if type == '' or type == 'void' or type == "..." then
+ return type
+ else
+ local ft = findtype(type)
+ if ft then
+ return ft
+ end
+ _usertype[type] = type
+ return type
+ end
+end
+
+-- check if basic type
+function isbasic (type)
+ local t = gsub(type,'const ','')
+ local m,t = applytypedef(t)
+ local b = _basic[t]
+ if b then
+ return b,_basic_ctype[b]
+ end
+ return nil
+end
+
+-- split string using a token
+function split (s,t)
+ local l = {n=0}
+ local f = function (s)
+ l.n = l.n + 1
+ l[l.n] = s
+ return ""
+ end
+ local p = "%s*(.-)%s*"..t.."%s*"
+ s = gsub(s,"^%s+","")
+ s = gsub(s,"%s+$","")
+ s = gsub(s,p,f)
+ l.n = l.n + 1
+ l[l.n] = gsub(s,"(%s%s*)$","")
+ return l
+end
+
+
+-- concatenate strings of a table
+function concat (t,f,l)
+ local s = ''
+ local i=f
+ while i<=l do
+ s = s..t[i]
+ i = i+1
+ if i <= l then s = s..' ' end
+ end
+ return s
+end
+
+-- concatenate all parameters, following output rules
+function concatparam (line, ...)
+ local arg = {...}
+ local i=1
+ while i<=#arg do
+ if _cont and not strfind(_cont,'[%(,"]') and
+ strfind(arg[i],"^[%a_~]") then
+ line = line .. ' '
+ end
+ line = line .. arg[i]
+ if arg[i] ~= '' then
+ _cont = strsub(arg[i],-1,-1)
+ end
+ i = i+1
+ end
+ if strfind(arg[#arg],"[%/%)%;%{%}]$") then
+ _cont=nil line = line .. '\n'
+ end
+ return line
+end
+
+-- output line
+function output (...)
+ local arg = {...}
+ local i=1
+ while i<=#arg do
+ if _cont and not strfind(_cont,'[%(,"]') and
+ strfind(arg[i],"^[%a_~]") then
+ write(' ')
+ end
+ write(arg[i])
+ if arg[i] ~= '' then
+ _cont = strsub(arg[i],-1,-1)
+ end
+ i = i+1
+ end
+ if strfind(arg[#arg],"[%/%)%;%{%}]$") then
+ _cont=nil write('\n')
+ end
+end
+
+
diff --git a/tolua/src/bin/lua/clean.lua b/tolua/src/bin/lua/clean.lua
index 2442291..b11e38c 100644
--- a/tolua/src/bin/lua/clean.lua
+++ b/tolua/src/bin/lua/clean.lua
@@ -1,75 +1,75 @@
--- mark up comments and strings
-STR1 = "\001"
-STR2 = "\002"
-STR3 = "\003"
-STR4 = "\004"
-REM = "\005"
-ANY = "([\001-\005])"
-ESC1 = "\006"
-ESC2 = "\007"
-
-MASK = { -- the substitution order is important
- {ESC1, "\\'", "\\'"},
- {ESC2, '\\"', '\\"'},
- {STR1, "'", "'"},
- {STR2, '"', '"'},
- {STR3, "%[%[", "[["},
- {STR4, "%]%]", "]]"},
- {REM , "%-%-", "--"},
-}
-
-function mask (s)
- for i = 1,getn(MASK) do
- s = gsub(s,MASK[i][2],MASK[i][1])
- end
- return s
-end
-
-function unmask (s)
- for i = 1,getn(MASK) do
- s = gsub(s,MASK[i][1],MASK[i][3])
- end
- return s
-end
-
-function clean (s)
- -- check for compilation error
- local code = "return function () " .. s .. " end"
- if not dostring(code) then
- return nil
- end
-
- local S = "" -- saved string
-
- s = mask(s)
-
- -- remove blanks and comments
- while 1 do
- local b,e,d = strfind(s,ANY)
- if b then
- S = S..strsub(s,1,b-1)
- s = strsub(s,b+1)
- if d==STR1 or d==STR2 then
- e = strfind(s,d)
- S = S ..d..strsub(s,1,e)
- s = strsub(s,e+1)
- elseif d==STR3 then
- e = strfind(s,STR4)
- S = S..d..strsub(s,1,e)
- s = strsub(s,e+1)
- elseif d==REM then
- s = gsub(s,"[^\n]*(\n?)","%1",1)
- end
- else
- S = S..s
- break
- end
- end
- -- eliminate unecessary spaces
- S = gsub(S,"[ \t]+"," ")
- S = gsub(S,"[ \t]*\n[ \t]*","\n")
- S = gsub(S,"\n+","\n")
- S = unmask(S)
- return S
-end
-
+-- mark up comments and strings
+STR1 = "\001"
+STR2 = "\002"
+STR3 = "\003"
+STR4 = "\004"
+REM = "\005"
+ANY = "([\001-\005])"
+ESC1 = "\006"
+ESC2 = "\007"
+
+MASK = { -- the substitution order is important
+ {ESC1, "\\'", "\\'"},
+ {ESC2, '\\"', '\\"'},
+ {STR1, "'", "'"},
+ {STR2, '"', '"'},
+ {STR3, "%[%[", "[["},
+ {STR4, "%]%]", "]]"},
+ {REM , "%-%-", "--"},
+}
+
+function mask (s)
+ for i = 1,getn(MASK) do
+ s = gsub(s,MASK[i][2],MASK[i][1])
+ end
+ return s
+end
+
+function unmask (s)
+ for i = 1,getn(MASK) do
+ s = gsub(s,MASK[i][1],MASK[i][3])
+ end
+ return s
+end
+
+function clean (s)
+ -- check for compilation error
+ local code = "return function () " .. s .. " end"
+ if not dostring(code) then
+ return nil
+ end
+
+ local S = "" -- saved string
+
+ s = mask(s)
+
+ -- remove blanks and comments
+ while 1 do
+ local b,e,d = strfind(s,ANY)
+ if b then
+ S = S..strsub(s,1,b-1)
+ s = strsub(s,b+1)
+ if d==STR1 or d==STR2 then
+ e = strfind(s,d)
+ S = S ..d..strsub(s,1,e)
+ s = strsub(s,e+1)
+ elseif d==STR3 then
+ e = strfind(s,STR4)
+ S = S..d..strsub(s,1,e)
+ s = strsub(s,e+1)
+ elseif d==REM then
+ s = gsub(s,"[^\n]*(\n?)","%1",1)
+ end
+ else
+ S = S..s
+ break
+ end
+ end
+ -- eliminate unecessary spaces
+ S = gsub(S,"[ \t]+"," ")
+ S = gsub(S,"[ \t]*\n[ \t]*","\n")
+ S = gsub(S,"\n+","\n")
+ S = unmask(S)
+ return S
+end
+
diff --git a/tolua/src/bin/lua/compat.lua b/tolua/src/bin/lua/compat.lua
index a63c31d..d200399 100644
--- a/tolua/src/bin/lua/compat.lua
+++ b/tolua/src/bin/lua/compat.lua
@@ -1,201 +1,201 @@
--------------------------------------------------------------------
--- Real globals
--- _ALERT
--- _ERRORMESSAGE
--- _VERSION
--- _G
--- assert
--- error
--- metatable
--- next
--- print
--- require
--- tonumber
--- tostring
--- type
-
--------------------------------------------------------------------
--- collectgarbage
--- gcinfo
-
--- globals
-
--- call -> protect(f, err)
-
--- rawget
--- rawset
-
--- getargs = Main.getargs ??
-
-rawtype = type
-
-function do_ (f, err)
- if not f then print(err); return end
- local a,b = pcall(f)
- if not a then print(b); return nil
- else return b or true
- end
-end
-
-function dostring(s) return do_(load(s)) end
-
--------------------------------------------------------------------
--- Table library
-local tab = table
-foreach = function(t,f)
- for k,v in pairs(t) do
- f(k,v)
- end
-end
-foreachi = function(t,f)
- for i,v in ipairs(t) do
- f(i,v)
- end
-end
-getn = function(t)
- return #t
-end
-tinsert = tab.insert
-tremove = tab.remove
-sort = tab.sort
-
--------------------------------------------------------------------
--- Debug library
-local dbg = debug
-getinfo = dbg.getinfo
-getlocal = dbg.getlocal
-setcallhook = function () error"`setcallhook' is deprecated" end
-setlinehook = function () error"`setlinehook' is deprecated" end
-setlocal = dbg.setlocal
-
--------------------------------------------------------------------
--- math library
-local math = math
-abs = math.abs
-acos = function (x) return math.deg(math.acos(x)) end
-asin = function (x) return math.deg(math.asin(x)) end
-atan = function (x) return math.deg(math.atan(x)) end
-atan2 = function (x,y) return math.deg(math.atan2(x,y)) end
-ceil = math.ceil
-cos = function (x) return math.cos(math.rad(x)) end
-deg = math.deg
-exp = math.exp
-floor = math.floor
-frexp = math.frexp
-ldexp = math.ldexp
-log = math.log
-log10 = math.log10
-max = math.max
-min = math.min
-mod = math.mod
-PI = math.pi
---??? pow = math.pow
-rad = math.rad
-random = math.random
-randomseed = math.randomseed
-sin = function (x) return math.sin(math.rad(x)) end
-sqrt = math.sqrt
-tan = function (x) return math.tan(math.rad(x)) end
-
--------------------------------------------------------------------
--- string library
-local str = string
-strbyte = str.byte
-strchar = str.char
-strfind = str.find
-format = str.format
-gsub = str.gsub
-strlen = str.len
-strlower = str.lower
-strrep = str.rep
-strsub = str.sub
-strupper = str.upper
-
--------------------------------------------------------------------
--- os library
-clock = os.clock
-date = os.date
-difftime = os.difftime
-execute = os.execute --?
-exit = os.exit
-getenv = os.getenv
-remove = os.remove
-rename = os.rename
-setlocale = os.setlocale
-time = os.time
-tmpname = os.tmpname
-
--------------------------------------------------------------------
--- compatibility only
-getglobal = function (n) return _G[n] end
-setglobal = function (n,v) _G[n] = v end
-
--------------------------------------------------------------------
-
-local io, tab = io, table
-
--- IO library (files)
-_STDIN = io.stdin
-_STDERR = io.stderr
-_STDOUT = io.stdout
-_INPUT = io.stdin
-_OUTPUT = io.stdout
-seek = io.stdin.seek -- sick ;-)
-tmpfile = io.tmpfile
-closefile = io.close
-openfile = io.open
-
-function flush (f)
- if f then f:flush()
- else _OUTPUT:flush()
- end
-end
-
-function readfrom (name)
- if name == nil then
- local f, err, cod = io.close(_INPUT)
- _INPUT = io.stdin
- return f, err, cod
- else
- local f, err, cod = io.open(name, "r")
- _INPUT = f or _INPUT
- return f, err, cod
- end
-end
-
-function writeto (name)
- if name == nil then
- local f, err, cod = io.close(_OUTPUT)
- _OUTPUT = io.stdout
- return f, err, cod
- else
- local f, err, cod = io.open(name, "w")
- _OUTPUT = f or _OUTPUT
- return f, err, cod
- end
-end
-
-function appendto (name)
- local f, err, cod = io.open(name, "a")
- _OUTPUT = f or _OUTPUT
- return f, err, cod
-end
-
-function read (...)
- local f = _INPUT
- local arg = {...}
- if rawtype(arg[1]) == 'userdata' then
- f = tab.remove(arg, 1)
- end
- return f:read(table.unpack(arg))
-end
-
-function write (...)
- local f = _OUTPUT
- local arg = {...}
- if rawtype(arg[1]) == 'userdata' then
- f = tab.remove(arg, 1)
- end
- return f:write(table.unpack(arg))
-end
-
+-------------------------------------------------------------------
+-- Real globals
+-- _ALERT
+-- _ERRORMESSAGE
+-- _VERSION
+-- _G
+-- assert
+-- error
+-- metatable
+-- next
+-- print
+-- require
+-- tonumber
+-- tostring
+-- type
+
+-------------------------------------------------------------------
+-- collectgarbage
+-- gcinfo
+
+-- globals
+
+-- call -> protect(f, err)
+
+-- rawget
+-- rawset
+
+-- getargs = Main.getargs ??
+
+rawtype = type
+
+function do_ (f, err)
+ if not f then print(err); return end
+ local a,b = pcall(f)
+ if not a then print(b); return nil
+ else return b or true
+ end
+end
+
+function dostring(s) return do_(load(s)) end
+
+-------------------------------------------------------------------
+-- Table library
+local tab = table
+foreach = function(t,f)
+ for k,v in pairs(t) do
+ f(k,v)
+ end
+end
+foreachi = function(t,f)
+ for i,v in ipairs(t) do
+ f(i,v)
+ end
+end
+getn = function(t)
+ return #t
+end
+tinsert = tab.insert
+tremove = tab.remove
+sort = tab.sort
+
+-------------------------------------------------------------------
+-- Debug library
+local dbg = debug
+getinfo = dbg.getinfo
+getlocal = dbg.getlocal
+setcallhook = function () error"`setcallhook' is deprecated" end
+setlinehook = function () error"`setlinehook' is deprecated" end
+setlocal = dbg.setlocal
+
+-------------------------------------------------------------------
+-- math library
+local math = math
+abs = math.abs
+acos = function (x) return math.deg(math.acos(x)) end
+asin = function (x) return math.deg(math.asin(x)) end
+atan = function (x) return math.deg(math.atan(x)) end
+atan2 = function (x,y) return math.deg(math.atan2(x,y)) end
+ceil = math.ceil
+cos = function (x) return math.cos(math.rad(x)) end
+deg = math.deg
+exp = math.exp
+floor = math.floor
+frexp = math.frexp
+ldexp = math.ldexp
+log = math.log
+log10 = math.log10
+max = math.max
+min = math.min
+mod = math.mod
+PI = math.pi
+--??? pow = math.pow
+rad = math.rad
+random = math.random
+randomseed = math.randomseed
+sin = function (x) return math.sin(math.rad(x)) end
+sqrt = math.sqrt
+tan = function (x) return math.tan(math.rad(x)) end
+
+-------------------------------------------------------------------
+-- string library
+local str = string
+strbyte = str.byte
+strchar = str.char
+strfind = str.find
+format = str.format
+gsub = str.gsub
+strlen = str.len
+strlower = str.lower
+strrep = str.rep
+strsub = str.sub
+strupper = str.upper
+
+-------------------------------------------------------------------
+-- os library
+clock = os.clock
+date = os.date
+difftime = os.difftime
+execute = os.execute --?
+exit = os.exit
+getenv = os.getenv
+remove = os.remove
+rename = os.rename
+setlocale = os.setlocale
+time = os.time
+tmpname = os.tmpname
+
+-------------------------------------------------------------------
+-- compatibility only
+getglobal = function (n) return _G[n] end
+setglobal = function (n,v) _G[n] = v end
+
+-------------------------------------------------------------------
+
+local io, tab = io, table
+
+-- IO library (files)
+_STDIN = io.stdin
+_STDERR = io.stderr
+_STDOUT = io.stdout
+_INPUT = io.stdin
+_OUTPUT = io.stdout
+seek = io.stdin.seek -- sick ;-)
+tmpfile = io.tmpfile
+closefile = io.close
+openfile = io.open
+
+function flush (f)
+ if f then f:flush()
+ else _OUTPUT:flush()
+ end
+end
+
+function readfrom (name)
+ if name == nil then
+ local f, err, cod = io.close(_INPUT)
+ _INPUT = io.stdin
+ return f, err, cod
+ else
+ local f, err, cod = io.open(name, "r")
+ _INPUT = f or _INPUT
+ return f, err, cod
+ end
+end
+
+function writeto (name)
+ if name == nil then
+ local f, err, cod = io.close(_OUTPUT)
+ _OUTPUT = io.stdout
+ return f, err, cod
+ else
+ local f, err, cod = io.open(name, "w")
+ _OUTPUT = f or _OUTPUT
+ return f, err, cod
+ end
+end
+
+function appendto (name)
+ local f, err, cod = io.open(name, "a")
+ _OUTPUT = f or _OUTPUT
+ return f, err, cod
+end
+
+function read (...)
+ local f = _INPUT
+ local arg = {...}
+ if rawtype(arg[1]) == 'userdata' then
+ f = tab.remove(arg, 1)
+ end
+ return f:read(table.unpack(arg))
+end
+
+function write (...)
+ local f = _OUTPUT
+ local arg = {...}
+ if rawtype(arg[1]) == 'userdata' then
+ f = tab.remove(arg, 1)
+ end
+ return f:write(table.unpack(arg))
+end
+