source: project/release/3/pyffi/trunk/pyffi-eggdoc.scm @ 10773

Last change on this file since 10773 was 10773, checked in by Ivan Raikov, 12 years ago

Updated documentation about define-pyslot.

File size: 6.6 KB
Line 
1
2(use eggdoc)
3
4(define doc
5  `((eggdoc:begin
6     (name "pyffi")
7
8     (description "An interface to the Python programming language.")
9
10     (author (url "http://chicken.wiki.br/ivan raikov" "Ivan Raikov"))
11
12     (history 
13      (version "2.5" "Added definitions for Py_IncRef and Py_DecRef when using Python 2.3")
14      (version "2.4" "Fixed a bug in the wrapper of PyRun_String")
15      (version "2.3" "Added support for the boolean type")
16      (version "2.2" "Some fixes to ensure compatibility with Python 2.3 and 2.5")
17      (version "2.1" "Build script updated for better cross-platform compatibility")
18      (version "2.0" "Change to use utf8 extension")
19      (version "1.1" "Metafile fix")
20      (version "1.0" "Initial release"))
21
22     (requires (url "utf8.html"   "utf8")
23               (url "easyffi.html"  "easyffi"))
24
25     (usage "(require-extension pyffi)")
26
27     (download "pyffi.egg")
28
29     (documentation
30     
31      (p "The " (tt "pyffi") " extension uses the " 
32         (url "http://www.python.org" "Python") " C interface "
33         " to invoke Python procedures and methods from within Scheme "
34         " and to convert data objects between their Python and Scheme "
35         "representation. ")
36
37      (p "Currently, " (tt "pyffi") " supports the Python data "
38         "types listed in the table below. All other Python data types "
39         "are represented as pointers. ")
40
41      (symbol-table 
42       (describe "int, float" 
43                 ("numeric types, converted to and from the corresponding Scheme numeric values."))
44
45       (describe "list" 
46                 ("list type, converted to and from Scheme list value"))
47
48       (describe "str" 
49                 ("string type, converted to and from Scheme string value"))
50
51       (describe "unicode" 
52                 ("Unicode string type, converted to and from Scheme " (url "utf8.html"   "utf8") " string"))
53
54       (describe "dict" 
55                 ("dictionary type, converted to and from Scheme alist value"))
56
57       (describe "tuple" 
58                 ("tuple type, converted to and from Scheme vector value")))
59
60      (subsection "Procedures"
61                 
62          (procedure "(py-start)"
63                     (p "Initializes the Python interpreter, and creates an evaluation environment. "
64                        "This procedure must be called before all other procedures in the extension. "))
65                       
66          (procedure "(py-stop)"
67                     (p "Deallocates the memory reserved by the Python interpreter, and frees all "
68                        "internal structures of the extension. "))
69
70          (procedure "(py-import name)"
71                     (p "Imports Python module " (tt "NAME") ". If the import was unsuccessful, "
72                        "raises an exception of type " (tt "'pyerror") ". "))
73
74         
75          (procedure "(py-eval expr)"
76                     (p "Evaluates the Python expression contained in the string " (tt "EXPR") 
77                        " and returns the resulting value, either converted to Scheme "
78                        "representation, or as a pointer to a Python value. "))
79
80          (procedure "(py-apply func arg1 ...)"
81                     (p "Applies the given arguments to the Python object " (tt "FUNC") 
82                        " and returns the resulting value, either converted to Scheme "
83                        "representation, or as a pointer to a Python value. "
84                        "The arguments must be either Scheme values of types listed "
85                        "in the type conversion table above, or pointers to Python values.")))
86
87      (subsection "Macros"
88
89          (macro "(define-pyfun expr arg1 ...)"
90             (p "Defines a Scheme procedure named when called, "
91                "invokes the Python procedure of the same name. " 
92                (tt "EXPR") " is either a string that contains the procedure name, "
93                "or a pair of the form " (tt "(FORM . NAME)") " where " (tt "FORM")
94                " is a Python expression that when evaluated returns a Python procedure, "
95                "and " (tt "NAME") " is a string that contains the name of the Scheme procedure. "
96                "The arguments must be all symbols. "))
97
98          (macro "(define-pyslot NAME [SCHEME-NAME])"
99             (p "Defines an accessor/modifier for the Python object attribute " (tt "NAME") ". "
100                "The optional argument " (tt "SCHEME-NAME") " is an alternate name for the "
101                "Scheme procedure. The returned procedure takes in a Python object "
102                "and returns the value of attribute " (tt "NAME") " contained in that object. "
103                "If the object has no such attribute, #f is returned. "
104                "If a value is supplied after the name of the object, the procedure acts as a modifier for that slot. "
105                ))
106
107          (macro "(define-pymethod NAME [SCHEME-NAME])"
108             (p "Defines an accessor for the Python method " (tt "NAME") ". "
109                "The optional argument " (tt "SCHEME-NAME") " is an alternate name for the "
110                "Scheme procedure. The accessor is a procedure of the form " 
111                (tt "LAMBDA OBJ ARG1 ...") " that takes in a Python object " (tt "OBJ")
112                " and invokes the method " (tt "NAME") " contained in that object, "
113                "with the supplied arguments, which must be either Scheme values of types "
114                "listed in the type conversion table above, or pointers to Python values. "
115                "If the object has no such method, #f is returned. "))))
116
117
118
119     (examples (pre #<<EOF
120;;
121;; Python-UNO example from pyffi.lisp by Dmitri Hrapof.
122;;
123;; Before running the following code, you must make sure OpenOffice is
124;; running as a server:
125;;
126;;  soffice "-accept=socket,host=localhost,port=2002;urp;"
127;;
128(require-extension pyffi)
129
130(py-start)
131
132(py-import "uno")
133
134(define-pyfun "uno.getComponentContext")
135
136(define-pyslot "ServiceManager")
137(define-pyslot "Text")
138
139;; Can't yet find out appropriate class, the following is lame
140(define-pymethod "createInstanceWithContext")
141(define-pymethod "resolve")
142(define-pymethod "getCurrentComponent")
143(define-pymethod "createTextCursor")
144(define-pymethod "insertString")
145
146(define (message-uno str)
147  (let* ((lc (uno.getcomponentcontext))
148         (resolver (createInstanceWithContext 
149                    (ServiceManager lc)
150                    "com.sun.star.bridge.UnoUrlResolver" lc))
151         (ctx (resolve resolver "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"))
152         (desktop (CreateInstanceWithContext 
153                   (ServiceManager ctx)
154                   "com.sun.star.frame.Desktop" ctx))
155         (model   (getCurrentComponent desktop))
156         (text    (text model))
157         (cursor  (createTextCursor text)))
158    (insertString text cursor str 0)))
159
160
161(message-uno "Hello, world!")
162
163EOF
164))
165     (license
166      "Copyright 2007 Ivan Raikov. Based on pyffi.lisp by Dmitri Hrapof.
167
168This program is free software: you can redistribute it and/or modify
169it under the terms of the GNU General Public License as published by
170the Free Software Foundation, either version 3 of the License, or (at
171your option) any later version.
172
173This program is distributed in the hope that it will be useful, but
174WITHOUT ANY WARRANTY; without even the implied warranty of
175MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
176General Public License for more details.
177
178A full copy of the GPL license can be found at
179<http://www.gnu.org/licenses/>."))))
180
181(if (eggdoc->html doc) (void))
Note: See TracBrowser for help on using the repository browser.