#? *** Python: Embedded into Lush
{<author> Fu Jie Huang}

Python can be embedded. You can just take the library file (libpython), link it with your C program, and access the Python functionalities through its C API.
{<p>}
In our case, we dynamically load the libpython file into Lush, and then interactively access its API, like:
{<code>
(Py_Initialize)
(setq pdict (PyDict_New))
(PyDict_SetItemString pdict "__builtins__" (PyEval_GetBuiltins))
(PyDict_SetItemString pdict "Y" (PyInt_FromLong 2))
(PyDict_SetItemString pdict "X" (PyInt_FromLong 3))
(PyRun_String "X=X+Y" 257 pdict pdict)
(PyRun_String "print X" 257 pdict pdict)
(Py_DECREF pdict)
</code>} 
{<p>}
Before try anything, you need to browse through the <Python/C API Reference Manual> written by Guido van Rossum. This document can be found at:  {<hlink> http://www.python.org/doc/current/api/api.html}


#? ** Installation

The Lush interface requires the shared library <libpython2.x.so> and associated files. It's built and tested with <version 2.2.1>. 
{<p>}
Most of Linux distributions install Python by default. The only problem with version 2.x is that only the static library libpython2.x.a is available, not the shared library libpython2.x.so. Even if you compile from the source code, you won't get the shared library. It's a known problem, indicated by the <FAQ item 3.30> on Python's website. The FAQ item also gives out a workaround. Basically, you need to create a shared library yourself.
{<p>}
This interface does not work with Python version 2.3, yet.
{<p>}
Start Lush, and type:
{<code>
? (libload "python/python")
</code>}

#? ** << python/aux_arg.lsh
#? ** << python/aux_const.lsh
#? ** << python/aux_convert.lsh
#? ** << python/aux_globalvar.lsh
#? ** << python/aux_macro.lsh
#? ** << python/aux_structure.lsh
#? ** << python/pybuffer.lsh
#? ** << python/pycall.lsh
#? ** << python/pycobject.lsh
#? ** << python/pycomplex.lsh
#? ** << python/pydict.lsh
#? ** << python/pyerr.lsh
#? ** << python/pyeval.lsh
#? ** << python/pyfile.lsh
#? ** << python/pyfloat.lsh
#? ** << python/pyimport.lsh
#? ** << python/pyinterpreterstate.lsh
#? ** << python/pyint.lsh
#? ** << python/pylist.lsh
#? ** << python/pylong.lsh
#? ** << python/py.lsh
#? ** << python/pymapping.lsh
#? ** << python/pymem.lsh
#? ** << python/pymodule.lsh
#? ** << python/pynumber.lsh
#? ** << python/pyobject.lsh
#? ** << python/pyos.lsh
#? ** << python/pyothers.lsh
#? ** << python/pyparser.lsh
#? ** << python/pyrun.lsh
#? ** << python/pysequence.lsh
#? ** << python/pystring.lsh
#? ** << python/pysys.lsh
#? ** << python/pythreadstate.lsh
#? ** << python/pytraceback.lsh
#? ** << python/pytuple.lsh
#? ** << python/pytype.lsh
#? ** << python/pyunicode.lsh
#? ** << python/pyweakref.lsh
