Hello, Win32 API(Lua) World!

Posted on 4月 30th, 2012 by cx20

Win32 API(Lua)

Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
以下は Lua にて alien ライブラリを用いた呼出し例である。

ソースコード

require "alien"
 
MessageBox = alien.User32.MessageBoxA
MessageBox:types{ ret = 'long', abi = 'stdcall', 'long', 'string', 'string', 'long' }
MessageBox( 0, "Hello, Win32 API(Lua) World!", "Hello, World!", 0 )

Win32 データ型に対応する Lua の型(alien ライブラリ)としては以下のようなものがある。

Win32 データ型 C/C++ データ型 Lua
VOID void void
INT int int
UINT unsigned int uint
DOUBLE double double
CHAR char char
LPCSTR const char * string
LPVOID void * pointer
PINT int * ref int
PUINT unsigned int * ref uint
DOUBLE * double * ref double
PCHAR char * ref char
PROC function pointer callback
SHORT short short
WORD unsigned short ushort
BYTE signed char byte
LONG long long
DWORD unsigned long ulong
FLOAT float float

実行方法

C:¥> lua hello.lua

実行結果

---------------------------
Hello, World!
---------------------------
Hello, Win32 API(Lua) World!
---------------------------
OK   
---------------------------

Tags:

Categories: library, Lua, Win32 API

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing