- 394 名前:デフォルトの名無しさん mailto:sage [2008/07/01(火) 09:12:00 ]
- >>392
#include <Python.h> //--- Python API ヘッダの指定 // Python.h には既に stdio.h string.h errno.h stdlib.h のインクルード指定が含まれています // メソッドの実体 static PyObject* exec_do(PyObject* self, PyObject* args) { const char* command ; //--- command は PyArg_ParseTuple によって alloc される int status ; if (!PyArg_ParseTuple(args, "s", &command)) return NULL ; status = system(command) ; return Py_BuildValue("i", status) ; } // メソッドテーブル // メソッド名 / 関数へのポインタ / 呼び出し規則 / 説明書き(何を書いても良い) // python の help から参照することができます。 static PyMethodDef executerMethods [] = { { "do", exec_do, METH_VARARGS, "Execute command for Command-prompt in Windows." }, { NULL, NULL, 0, NULL } }; // モジュールの初期化関数 (Python にモジュール名とメソッドテーブルを渡します) PyMODINIT_FUNC initexecuter(void) // 初期化モジュール名は init + "DLL 名" にする必要があります。 { Py_InitModule("executer", executerMethods) ; // モジュール名は DLL 名と同じにする必要があります。 } dll -> pyd(2.5で変更) だからPython C APIで拡張を書いてあげればpython側で認識してくれると思われ
|

|