Skip to content

Instantly share code, notes, and snippets.

@torque
Created October 17, 2014 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torque/25c8380e198daa22e00c to your computer and use it in GitHub Desktop.
Save torque/25c8380e198daa22e00c to your computer and use it in GitHub Desktop.
fuckWindows = ( logString ) ->
ffi.cdef [[int WideCharToMultiByte( unsigned int, unsigned int, const char*, int, char*, int, void*, void* );]]
CP_UTF8 = 65001
logLength = math.ceil #logString/2
buffSize = 1 + ffi.C.WideCharToMultiByte CP_UTF8, 0, logString, logLength, nil, 0, nil, nil
if 0 == buffSize
error "Shit's fucked i aint helping."
utf8String = ffi.new "char[?]", buffSize
status = ffi.C.WideCharToMultiByte CP_UTF8, 0, logString, logLength, utf8String, buffSize, nil, nil
if 0 == status
error "Shit's fucked bye."
return ffi.string utf8String, buffSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment