Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 16/11/2015
- --Last update: 06/12/2016
- --[[ Notes:
- Other
- assert
- Does:
- Produz um erro quando o valor de seu argumento v é falso.
- Args:
- value --> Argumento para verificação
- message --> Mensagem de erro
- ipairs
- Does:
- Itera os argumentos dentro de uma tabela ignorando as keys não numéricas.
- Args:
- list --> Tabela
- pairs
- Does:
- Itera os argumentos de uma tabela
- Args:
- list --> Tabela
- tostring
- Does:
- Recebe um valor de qualquer tipo e o converte para uma cadeia em um formato razoável.
- Args:
- value --> Valor
- type
- Does:
- Retorna o tipo do valor introduzido.
- Args:
- value --> Valor
- Strings
- string.len
- Does:
- Retorna o comprimento da cadeia.
- Args:
- str --> String
- string.byte
- Does:
- Retorna os códigos numéricos internos dos caracteres.
- Args:
- str --> String
- i --> Índice inicial para a string
- j --> Índice final para a string
- string.reverse
- Does:
- Retorna uma cadeia que é a cadeia s invertida.
- Args:
- str --> String
- string.upper
- Does:
- Retorna uma cópia da cadeia com todas as letras minúsculas convertidas para maiúsculas.
- Args:
- str --> String
- string.format
- Does:
- Retorna uma versão formatada de seu número variável de argumentos seguindo a descrição dada em seu primeiro argumento.
- Args:
- str --> String
- ... --> Variáveis de argumentos
- string.rep
- Does:
- Retorna uma cadeia que é a concatenação de int cópias da cadeia str separadas pela cadeia sep.
- Args:
- str --> String
- int --> Quantidade de concatenações
- sep --> Separador das concatenações
- string.lower
- Does:
- Retorna uma cópia da cadeia com todas as letras maiúsculas convertidas para minúsculas.
- Args:
- str --> String
- string.sub
- Does:
- Retorna a subcadeia de str que começa em i e continua até j
- Args:
- str --> String
- i --> Índice inicial para a string
- j --> Índice final para a string
- string.char
- Does:
- Retorna uma cadeia com comprimento igual ao número de argumentos, na qual cada caractere tem um código numérico interno igual a seu argumento correspondente.
- Args:
- ... --> Argumentos em byte
- Tables
- table.concat(list,sep,i,j)
- Does:
- Retorna uma concatenção de todos os argumentos de list entre i e j separados por sep
- Args:
- list --> Tabela
- sep --> Separação
- i --> Índice inicial para a tabela
- j --> Índice final para a tabela
- table.remove(list,pos)
- Does:
- Remove de list o elemento na posição pos, retornando o valor do elemento removido.
- Args:
- list --> Tabela
- pos --> Posição do valor na tabela
- Maths
- math.deg
- Does:
- Retorna o ângulo x (dado em radianos) em graus.
- Args:
- x --> Ângulo
- math.fmod
- Does:
- Retorna o resto da divisão de x por y que arredonda o quociente em direção a zero.
- Args:
- x --> Número 1
- y --> Número 2
- math.asin
- Does:
- Retorna o arco seno de x (em radianos).
- Args:
- x --> Número
- Requires:
- function xatan
- function satan
- math.max
- Does:
- Retorna o valor máximo entre seus argumentos.
- Args:
- x --> Primeiro argumento
- ... --> Todos os outros argumentos
- math.modf
- Does:
- Retorna dois números, a parte integral de x e a parte fracionária de x.
- Args:
- x --> Número
- math.floor
- Does:
- Retorna o maior inteiro menor ou igual a x.
- Args:
- x --> Número
- math.cosh
- Does:
- Retorna o co-seno hiperbólico de x.
- Args:
- x --> Número
- math.ldexp
- Does:
- Retorna m2^e
- Args:
- m --> Número 1
- e --> Número 2
- math.atan2
- Does:
- Retorna o arco tangente de y/x (em radianos), mas usa os sinais de ambos os parâmetros para encontrar o quadrante do resultado.
- Args:
- y --> Número 1
- x --> Número 2
- Requires:
- function xatan
- function satan
- math.pow
- Does:
- Retorna x^y
- Args:
- x --> Número 1
- y --> Número 2
- math.abs
- Does:
- Retorna o valor absoluto de x.
- Args:
- x --> Número 1
- math.tanh
- Does:
- Retorna a tangente hiperbólica de x.
- Args:
- x --> Número
- math.acos
- Does:
- Retorna o arco cosseno de x (em radianos).
- Args:
- x --> Número
- math.tan
- Does:
- Retorna a tangente de x.
- Args:
- x --> Número
- math.min
- Does:
- Retorna o valor mínimo entre seus argumentos.
- Args:
- x --> Primeiro argumento
- ... --> Todos os outros argumentos
- math.floor
- Does:
- Retorna o maior inteiro maior ou igual a x.
- Args:
- x --> Número
- math.sinh
- Does:
- Retorna o seno hiperbólico de x.
- Args:
- x --> Número
- math.sqrt
- Does:
- Retorna a raiz quadrada de x.
- Args:
- x --> Número
- math.huge
- Returns:
- Um valor maior ou igual a qualquer outro valor numérico.
- math.rad
- Does:
- Retorna o ângulo x (dado em graus) em radianos.
- Args:
- x --> Ângulo
- math.randomseed
- Does:
- Semente do math.random
- math.random
- Does:
- Retorna um número aleatório
- Args:
- m --> Número deverá partir de M
- n --> Número deverá ter o limite em N
- math.sin
- Does:
- Retorna o seno de x.
- Args:
- x --> Número
- math.exp
- Does:
- Retorna o valor e^x
- Args:
- x --> Número
- math.cos
- Does:
- Retorna o co-seno de x.
- Args:
- x --> Número
- math.atan
- Does:
- Retorna o arco tangente de x (em radianos).
- Args:
- x --> Número 2
- Requires:
- function xatan
- function satan
- math.pi
- Returns:
- O valor de π.
- ]]--
- --------------------------------------------> Other <--------------------------------------------
- assert=function(value,message)
- if value then return value else error(message or 'assertion failed!') end
- end
- ipairs=function(list)
- return (function(k,v)
- v=v+1
- local tIT=k[v]
- if tIT then
- return v,tIT
- end
- end),list,0
- end
- pairs=function(list)
- return next,list,nil
- end
- tostring=function(value)
- return string.format("%s",value)
- end
- type=function(value)
- if not value then return nil end
- if value == tonumber(value) then
- return "number"
- end
- if value == tostring(value) then
- return "string"
- end
- if tostring(value) == "true" or tostring(value) == "false" then
- return "boolean"
- end
- if tostring(value):match('^table.*') then
- return "table"
- end
- if tostring(value):match('^function.*') then
- return "function"
- end
- end
- --------------------------------------------> Strings <--------------------------------------------
- string.len=function(str)
- return #str
- end
- string.byte=function(str,i,j)
- i = i or 1;j = j or i
- local chars = [[
- !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
- ]]
- local bytes = {}
- for v = i,j do
- table.insert(bytes,(chars:find(str:sub(v,v))))
- end
- return table.unpack(bytes)
- end
- string.reverse=function(str)
- local digits = {}
- for digit in str:gmatch('.') do
- table.insert(digits,digit)
- end
- local txt = ""
- for i=#digits,1,-1 do
- txt=txt..digits[i]
- end
- return txt
- end
- string.upper=function(str)
- local digits = {}
- for digit in str:gmatch('.') do
- table.insert(digits,digit)
- end
- local txt = {}
- for i=1,#digits do
- table.insert(txt,string.char(string.byte(digits[i])-(string.byte(digits[i])>96 and string.byte(digits[i])<122 and 32 or 0)))
- end
- return table.concat(txt)
- end
- string.format=function(s,...) -- %X retorna o número string e %x não está funcionando.
- local x = {...}
- for i = 1,#x do
- if type(x[i]) == "string" then
- if s:find("%%s") then
- s = s:gsub("%%s",x[i],1)
- else
- error("String expected")
- end
- elseif type(x[i]) == "number" then
- if s:find("%%d") then
- s = s:gsub("%%d",x[i],1)
- elseif s:find("%%X") then
- s = s:gsub("%%X",tostring(x[i]):sub(3),1)
- elseif s:find("%%x") then
- error("%x is not able to work")
- else
- error("Number expected")
- end
- else
- error("Invalid Key")
- end
- end
- return s
- end
- string.rep=function(str,int,sep)
- str,int,rep = str or "",int or 1,sep or ""
- local txt = {}
- for i = 1,int do
- table.insert(txt,str)
- end
- return table.concat(txt,sep)
- end
- string.lower=function(str)
- local digits={}
- for digit in str:gmatch('.') do
- table.insert(digits,digit)
- end
- local txt={}
- for i = 1,#digits do
- table.insert(txt,string.char(string.byte(digits[i])+(string.byte(digits[i])>64 and string.byte(digits[i])<91 and 32 or 0)))
- end
- return table.concat(txt)
- end
- string.sub=function(str,i,j)
- i,j=i or 1,j or #str
- local digits = {}
- for digit in str:gmatch('.') do
- table.insert(digits,digit)
- end
- return table.concat(digits,"",i,j)
- end
- string.char=function(...)
- local chars = [[
- !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
- ]]
- local char2 = {}
- local args = {...}
- for i=1,#args do
- table.insert(char2,chars:sub(args[i],args[i]))
- end
- return table.concat(char2)
- end
- --------------------------------------------> Tables <--------------------------------------------
- table.concat=function(list,sep,i,j)
- sep,i,j = sep or "",i or 1,j or #list
- local txt = ""
- for k,v in next,list do
- if k >= i and k <= j then
- txt = txt .. v .. (k~=j and sep or "")
- end
- end
- return txt
- end
- table.remove=function(list,pos)
- local toReturn
- if pos then
- toReturn = list[remove]
- local p = {table.unpack(list)}
- for k,v in next,p do
- if k>pos then
- list[k-1]=v
- end
- end
- if pos<#list then list[#list]=nil end
- else
- toReturn = list[#list]
- list[#list]=nil
- end
- return toReturn
- end
- --------------------------------------------> Maths <--------------------------------------------
- math.deg=function(x)
- return x*(180/math.pi)
- end
- math.fmod=function(x,y)
- return x-math.floor(x/y)*y -- x%y
- end
- math.asin=function(x)
- if x == 0 then return 0 end
- local sign = false
- local temp = (1-x*x)^.5
- if x>.7 then
- temp = math.pi/2 - satan(temp/x)
- else
- temp = satan(x/temp)
- end
- return temp
- end
- math.max=function(x,...)
- local numbers = {x,...}
- return table.sort(numbers) or numbers[#numbers]
- end
- math.modf=function(x)
- return math.floor(x),x-math.floor(x)
- end
- math.floor=function(x)
- return (x-(x%1))
- end
- math.cosh=function(x)
- if x<0 then
- x = -x
- end
- if x>21 then
- return math.exp(x)/2
- end
- return (math.exp(x)+math.exp(-x))/2
- end
- math.ldexp=function(m,e)
- return m*2^e
- end
- math.atan2=function(y,x)
- local q = atan(x/y)
- if x == 0 then return 0 end
- if x < 0 then
- if q <= 0 then
- return q + math.pi
- end
- return q - math.pi
- end
- return q
- end
- math.pow=function(x,y)
- return x^y
- end
- math.abs=function(x)
- return x<0 and -x or x
- end
- math.tanh=function(x)
- if x == 0 then return 0 end
- local tanhP,tanhQ = {-9.64399179425052238628E-1,-9.92877231001918586564E1,-1.61468768441708447952E3},{1.12811678491632931402E2,2.23548839060100448583E3,4.84406305325125486048E3}
- local MAXLOG = 8.8029691931113054295988e+01
- local z = math.abs(x)
- local s
- if z > .5*MAXLOG then if x < 0 then return -1 end return 1 end
- if z >= 0.625 then
- s = math.exp(2*z)
- z = 1 - 2/(s+1)
- if x<0 then z=-z end
- end
- s = x^2
- z = x + x*s*((tanhP[1]*s+tanhP[2])*s+tanhP[3])/(((s+tanhQ[1])*s+tanhQ[2])*s+tanhQ[3])
- return z
- end
- math.acos=function(x)
- return math.pi/2 - math.asin(x)
- end
- math.tan=function(x)
- local _tanP = {
- -1.30936939181383777646E4,
- 1.15351664838587416140E6,
- -1.79565251976484877988E7,
- }
- local _tanQ = {
- 1.00000000000000000000E0,
- 1.36812963470692954678E4,
- -1.32089234440210967447E6,
- 2.50083801823357915839E7,
- -5.38695755929454629881E7,
- }
- local PI4A = 7.85398125648498535156E-1
- local PI4B = 3.77489470793079817668E-8
- local PI4C = 2.69515142907905952645E-15
- local M4PI = 1.273239544735162542821171882678754627704620361328125
- local sign = false
- if x < 0 then
- sign = true
- x = -x
- end
- local j = x * M4PI
- local y = math.floor(j)
- if j%2==1 then
- j = j + 1
- y = y + 1
- end
- local z = ((x - y*PI4A) - y*PI4B) - y*PI4C
- local zz = z^2
- if zz > 1e-14 then
- y = z + z*(zz*(((_tanP[1]*zz)+_tanP[2])*zz+_tanP[3])/((((zz+_tanQ[2])*zz+_tanQ[3])*zz+_tanQ[4])*zz+_tanQ[5]))
- else
- y = z
- end
- if j%3==2 then
- y = -1/y
- end
- if sign then y = -y end
- return y
- end
- math.min=function(x,...)
- local numbers = {x,...}
- return table.sort(numbers) or numbers[1]
- end
- math.ceil=function(x)
- return (x+1-(x%1))
- end
- math.sinh=function(x)
- local P0 = -0.6307673640497716991184787251e+6
- local P1 = -0.8991272022039509355398013511e+5
- local P2 = -0.2894211355989563807284660366e+4
- local P3 = -0.2630563213397497062819489e+2
- local Q0 = -0.6307673640497716991212077277e+6
- local Q1 = 0.1521517378790019070696485176e+5
- local Q2 = -0.173678953558233699533450911e+3
- local sign = false
- if x < 0 then
- x = -x
- sign = true
- end
- local temp
- if x>21 then
- temp = math.exp(x)/2
- end
- if x>.5 then
- temp = (math.exp(x)-math.exp(-x))/2
- end
- local sq = x^2
- temp = (((P3*sq+P2)*sq+P1)*sq + P0) * x
- temp = temp / (((sq+Q2)*sq+Q1)*sq + Q0)
- if sign then
- temp = -temp
- end
- return temp
- end
- math.sqrt=function(x)
- return x^.5
- end
- math.huge = 1/0
- math.rad=function(x)
- return x*(math.pi/180)
- end
- math.randomseed = os.time()
- math.random = function(m,n)
- if not m then m,n = 0,1 elseif not n then m,n = 1,m end
- m = m - 1; n = n + 1;
- local seed = (1103515245 * math.randomseed + 12345) % (2^32)
- math.randomseed = seed + 1
- return math.floor(((seed%0x7FFF)/0x7FFF) * (m-n+1))+n
- end
- math.sin=function(x) --> Há bugs
- if x == 0 then return 0 end
- local _sin = {
- 1.58962301576546568060E-10,
- -2.50507477628578072866E-8,
- 2.75573136213857245213E-6,
- -1.98412698295895385996E-4,
- 8.33333333332211858878E-3,
- -1.66666666666666307295E-1,
- }
- local _cos = {
- -1.13585365213876817300E-11,
- 2.08757008419747316778E-9,
- -2.75573141792967388112E-7,
- 2.48015872888517045348E-5,
- -1.38888888888730564116E-3,
- 4.16666666666665929218E-2,
- }
- local PI4A = 7.85398125648498535156E-1
- local PI4B = 3.77489470793079817668E-8
- local PI4C = 2.69515142907905952645E-15
- local M4PI = 1.273239544735162542821171882678754627704620361328125
- local sign = false
- if x < 0 then x = -x end
- local j = x * M4PI
- local y = math.floor(j)
- if j%2==1 then
- j = j + 1
- y = y + 1
- end
- j = j and 7
- if j > 3 then
- j = j - 4
- sign = not sign
- end
- if j > 1 then
- sign = not sign
- end
- local z = ((x - y*PI4A) - y*PI4B) - y*PI4C
- local zz = z^2
- if j==1 or j==2 then
- y = 1 - .5*zz + zz*zz*((((((_cos[1]*zz)+_cos[2])*zz+_cos[3])*zz+_cos[4])*zz+_cos[5])*zz+_cos[6])
- else
- y = z + z*zz*((((((_sin[1]*zz)+_sin[2])*zz+_sin[3])*zz+_sin[4])*zz+_sin[5])*zz+_sin[6])
- end
- if sign then y = -y end
- return y
- end
- math.exp=function(x)
- return 2.718281828459045^x
- end
- math.cos=function(x) --> Há bugs
- if x == 0 then return 0 end
- local _sin = {
- 1.58962301576546568060E-10,
- -2.50507477628578072866E-8,
- 2.75573136213857245213E-6,
- -1.98412698295895385996E-4,
- 8.33333333332211858878E-3,
- -1.66666666666666307295E-1,
- }
- local _cos = {
- -1.13585365213876817300E-11,
- 2.08757008419747316778E-9,
- -2.75573141792967388112E-7,
- 2.48015872888517045348E-5,
- -1.38888888888730564116E-3,
- 4.16666666666665929218E-2,
- }
- local PI4A = 7.85398125648498535156E-1
- local PI4B = 3.77489470793079817668E-8
- local PI4C = 2.69515142907905952645E-15
- local M4PI = 1.273239544735162542821171882678754627704620361328125
- local sign = false
- if x < 0 then x = -x end
- local j = x * M4PI
- local y = math.floor(j)
- if j%2==1 then
- j = j + 1
- y = y + 1
- end
- j = j and 7
- if j > 3 then
- j = j - 4
- sign = not sign
- end
- if j > 1 then
- sign = not sign
- end
- local z = ((x - y*PI4A) - y*PI4B) - y*PI4C
- local zz = z^2
- if j==1 or j==2 then
- y = z + z*zz*((((((_sin[1]*zz)+_sin[2])*zz+_sin[3])*zz+_sin[4])*zz+_sin[5])*zz+_sin[6])
- else
- y = 1 - .5*zz + zz*zz*((((((_cos[1]*zz)+_cos[2])*zz+_cos[3])*zz+_cos[4])*zz+_cos[5])*zz+_cos[6])
- end
- if sign then y = -y end
- return y
- end
- math.atan=function(x)
- if x == 0 then return 0 end
- if x > 0 then return satan(x) end
- return -satan(-x)
- end
- math.pi = 3.1415927
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement