The pyffi extension uses the Python C interface to invoke Python procedures and methods from within Scheme and to convert data objects between their Python and Scheme representation.
Currently, pyffi supports the Python data types listed in the table below. All other Python data types are represented as pointers.
int, float | numeric types, converted to and from the corresponding Scheme numeric values. |
list | list type, converted to and from Scheme list value |
str | string type, converted to and from Scheme string value |
unicode | Unicode string type, converted to and from Scheme utf8 string |
dict | dictionary type, converted to and from Scheme alist value |
instance | class instance type, converted to Scheme alist value |
tuple | tuple type, converted to and from Scheme vector value |
Initializes the Python interpreter, and creates an evaluation environment. This procedure must be called before all other procedures in the extension.
Deallocates the memory reserved by the Python interpreter, and frees all internal structures of the extension.
Imports Python module NAME. If the import was unsuccessful, raises an exception of type 'pyerror.
Evaluates the Python expression contained in the string EXPR and returns the resulting value, either converted to Scheme representation, or as a pointer to a Python value.
Applies the given arguments to the Python object FUNC and returns the resulting value, either converted to Scheme representation, or as a pointer to a Python value. The arguments must be either Scheme values of types listed in the type conversion table above, or pointers to Python values.
Defines a Scheme procedure named when called, invokes the Python procedure of the same name. EXPR is either a string that contains the procedure name, or a pair of the form (FORM . NAME) where FORM is a Python expression that when evaluated returns a Python procedure, and NAME is a string that contains the name of the Scheme procedure. The arguments must be all symbols.
Defines an accessor/modifier for the Python object attribute NAME. The optional argument SCHEME-NAME is an alternate name for the Scheme procedure. The returned procedure takes in a Python object and returns the value of attribute NAME contained in that object. If the object has no such attribute, #f is returned. If a value is supplied after the name of the object, the procedure acts as a modifier for that slot.
Defines an accessor for the Python method NAME. The optional argument SCHEME-NAME is an alternate name for the Scheme procedure. The accessor is a procedure of the form LAMBDA OBJ ARG1 ... that takes in a Python object OBJ and invokes the method NAME contained in that object, with the supplied arguments, which must be either Scheme values of types listed in the type conversion table above, or pointers to Python values. If the object has no such method, #f is returned.
;; ;; Python-UNO example from pyffi.lisp by Dmitri Hrapof. ;; ;; Before running the following code, you must make sure OpenOffice is ;; running as a server: ;; ;; soffice "-accept=socket,host=localhost,port=2002;urp;" ;; (require-extension pyffi) (py-start) (py-import "uno") (define-pyfun "uno.getComponentContext") (define-pyslot "ServiceManager") (define-pyslot "Text") ;; Can't yet find out appropriate class, the following is lame (define-pymethod "createInstanceWithContext") (define-pymethod "resolve") (define-pymethod "getCurrentComponent") (define-pymethod "createTextCursor") (define-pymethod "insertString") (define (message-uno str) (let* ((lc (uno.getcomponentcontext)) (resolver (createInstanceWithContext (ServiceManager lc) "com.sun.star.bridge.UnoUrlResolver" lc)) (ctx (resolve resolver "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")) (desktop (CreateInstanceWithContext (ServiceManager ctx) "com.sun.star.frame.Desktop" ctx)) (model (getCurrentComponent desktop)) (text (text model)) (cursor (createTextCursor text))) (insertString text cursor str 0))) (message-uno "Hello, world!")
Copyright 2007 Ivan Raikov. Based on pyffi.lisp by Dmitri Hrapof. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.