[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: luajit/ffi snippet to print the clipboard on windows
- From: malkia <malkia@...>
- Date: Wed, 2 Feb 2011 17:35:03 -0800
I kind of got used to Mac OS X's pbpaste, so decided to give luajit a
try with this operation, instead of going on writing whole ".c"
application:
The following winclip.lua would print the clipboard. There is not much
check going on, but it shows how quickly one can do the things without
recompiling.
-- pbpaste (Mac OS X) program for Windows
-- to run: luajit winclip.lua
-- it should print the clipboard (textual content)
local ffi = require( "ffi" )
local user32, kernel32 = ffi.load( "USER32" ), ffi.load( "KERNEL32" )
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 = user32.OpenClipboard(nil)
local handle = user32.GetClipboardData( user32.CF_TEXT )
local size = kernel32.GlobalSize( handle )
local mem = kernel32.GlobalLock( handle )
local text = ffi.string( mem, size )
local ok2 = kernel32.GlobalUnlock( handle )
local ok3 = user32.CloseClipboard()
print(text)
--
Dimiter "malkia" Stanev,
ICQ: 21875894
malkia@mac.com
malkia@gmail.com