Created
March 18, 2020 05:10
-
-
Save GMMan/94361efdb2d14f8051add4ad022d22a3 to your computer and use it in GitHub Desktop.
Crash fix for Angelica Weaver - Catch Me When You Can
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------------------------------------------------------------------------- | |
-- | |
-- String Utils | |
-- | |
--------------------------------------------------------------------------------------------------- | |
function ArgToString( arg ) | |
if not arg then | |
return '' | |
end | |
local result = '' | |
for i = 1, arg.n do | |
if i > 1 then | |
result = result .. ', ' | |
end | |
local v | |
if type( arg[ i ] ) == 'string' then | |
v = '\'' .. arg[ i ] .. '\'' | |
else | |
v = tostring( arg[ i ] ) | |
end | |
result = result .. v | |
end | |
return result | |
end | |
function SplitString( line, patern ) | |
local strs = {} | |
for w in string.gmatch( line, patern or '[%a%d_]+' ) do | |
table.insert( strs, w ) | |
end | |
return strs | |
end | |
function ArrayToString( array ) | |
local s = '' | |
for i = 1, #array do | |
if i > 1 then | |
s = s .. ', ' | |
end | |
s = s .. tostring( array[ i ] ) | |
end | |
return s | |
end | |
function BasicSerialize( o ) | |
if type( o ) == 'string' then | |
return string.format( '%q', o ) | |
else | |
return tostring( o ) | |
end | |
end | |
function Serialize( writer, name, value, saved ) | |
writer( name, ' = ' ) | |
if type( value ) == 'table' then | |
if saved[ value ] then | |
writer( saved[ value ], '\n' ) | |
else | |
saved[ value ] = name | |
writer( '{}\n' ) | |
for k, v in pairs( value ) do | |
local fieldname = name .. '[ ' .. BasicSerialize( k ) .. ' ]' | |
Serialize( writer, fieldname, v, saved ) | |
end | |
end | |
else | |
writer( BasicSerialize( value ), '\n' ) | |
end | |
end | |
function IdxToStr( index ) | |
if not index and POST_RELEASE_WORKAROUNDS then | |
index = 1 | |
end | |
return string.format( '%02d', index ) | |
end | |
function TimeToStrMS( millisecond ) | |
local seconds = millisecond / 1000 | |
return IdxToStr( seconds / 60 ) .. ':' .. IdxToStr( seconds % 60 ); | |
end | |
function ObjectToString( name, object ) | |
local result = '' | |
local function Writer( ... ) | |
result = result .. table.concat( arg ) | |
end | |
Serialize( Writer, name, object, {} ) | |
return result | |
end | |
function StringToObject( value ) | |
local e = {} | |
local chunk = loadstring( value ) | |
if chunk then | |
setfenv( chunk, e ) | |
chunk() | |
else | |
error( 'Error in loadstring.\n' .. debug.traceback() ) | |
end | |
return e | |
end | |
function ZipObject( name, object ) | |
result = Hot.ZipToBase64( ObjectToString( name, object ) ) | |
return result | |
end | |
function UnzipObject( value ) | |
local unzipped = Hot.UnzipFromBase64( value ) | |
return StringToObject( unzipped ) | |
end | |
function string:mgsub( ... ) | |
local r = self | |
local args = { ... } | |
for i = 1, #args, 2 do | |
r = r:gsub( args[ i ], args[ i + 1 ] ) | |
end | |
return r | |
end | |
function printn( value ) | |
print( value ) | |
print( '\n' ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment