Created
May 3, 2013 10:23
-
-
Save mrluanma/5508378 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| -- pbpaste (Mac OS X) program for Windows | |
| -- to run: luajit clip.lua | |
| -- it should print the clipboard (textual content) | |
| local ffi = require( "ffi" ) | |
| ffi.cdef[[ | |
| enum { CF_TEXT = 1 }; | |
| int OpenClipboard(void*); | |
| void* GetClipboardData(unsigned); | |
| int CloseClipboard(); | |
| void* GlobalLock(void*); | |
| int GlobalUnlock(void*); | |
| size_t GlobalSize(void*); | |
| ]] | |
| local ok1 = ffi.C.OpenClipboard(nil) | |
| local handle = ffi.C.GetClipboardData( ffi.C.CF_TEXT ) | |
| local size = ffi.C.GlobalSize( handle ) | |
| local mem = ffi.C.GlobalLock( handle ) | |
| local text = ffi.string( mem, size ) | |
| local ok = ffi.C.GlobalUnlock( handle ) | |
| local ok3 = ffi.C.CloseClipboard() | |
| print(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment