Last active
August 29, 2015 14:05
-
-
Save czlc/130afdbd5be1ee4379ce to your computer and use it in GitHub Desktop.
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
local to_double , from_double | |
do | |
local s , e , d | |
-- Can't use with to_double as we can't strip debug info :( | |
d = string.dump ( loadstring ( [[return 523123.123145345]] ) ) | |
s , e = d:find ( "\3\54\208\25\126\204\237\31\65" ) | |
s = d:sub ( 1 , s ) | |
e = d:sub ( e+1 , -1 ) | |
function to_double ( n ) | |
-- Should be the 8 bytes following the second \3 (LUA_TSTRING == '\3') | |
local str = string.dump ( loadstring ( [[return ]] .. n ) ) | |
local loc , en , mat = str:find ( "\3(........)" , str:find ( "\3" ) + 1 ) | |
return mat | |
end | |
function from_double ( str ) | |
assert ( #str == 8 ) | |
str = s .. str .. e | |
return loadstring ( str ) ( ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment