Call Python from BlitzMax?
BlitzMax Forums/BlitzMax Programming/Call Python from BlitzMax?
| ||
I really, really like the Python bindings for certain libraries, so I came up with some extra features possible with Python to justify such a ridiculous move, and now I want to access Python scripts from BlitzMax! I don't need Python functions to talk back to BlitzMax (except sending simple things in return values), but I would like to access Python somehow... Even creating a shared library with Python would do, but Googling hasn't given me much. Is that possible? Standard input and output spring to mind, but I am hoping for something more elegant. Does a Python integration module exist? What would such a system entail? |
| ||
I started one, can't find the crossplatform version I got up to but this win32 version which links to static lib libpython24.a seems to still work: mod/axe.mod/python.mod/python.bmx: Rem bbdoc: Python Programming Language about: Python is an interpreted object-oriented programming language. End Rem Module axe.python ModuleInfo "Version: 2.4" ModuleInfo "Authors: Guido van Rossum" ModuleInfo "License: Python Software Foundation License Version 2" ModuleInfo "Modserver: BRL" Import "libs/libpython24.a" Extern "C" Function Py_Initialize() Function PyRun_SimpleString(script$z) Function Py_InitModule4:Byte Ptr(name$z,methods:Byte Ptr,doc:Byte Ptr,PyObject:Byte Ptr,apiver) Function Py_Finalize() Function PyArg_ParseTuple(PyObject:Byte Ptr,name$z) Function Py_BuildValue:Byte Ptr(numtype$z,value) End Extern Const PYTHON_API_VERSION=1012 Const METH_OLDARGS=0 Const METH_VARARGS=1 Const METH_KEYWORDS=2 Const METH_NOARGS=4 Const METH_O=8 OnEnd Py_Finalize Py_Initialize Function Py_InitModule:Byte Ptr(name$,methods:Byte Ptr) Return Py_InitModule4(name,methods,Null,Null,PYTHON_API_VERSION) End Function test.bmx: Import axe.python PyRun_SimpleString("print~qpython thays hello!~q") Print "hello!" |
| ||
Skid - have you had any joy getting PyRun_SimpleFile() to work? or any other call to run blocks of python code? |
| ||
I tried this (writing a module) a while back, and honestly I have to say that Python's C interface is horrifying. It's a real messy system, and it's not that surprising since it's a very complex program behind the simple language. Anyway, I might give this a shot again later, although there might be some handy libraries out there to simplify the process. I'll take a look, I suppose. |
| ||
I almost got PyRun_SimpleFile() to work but it looks like the code it tries to compile is a garble of non-readable characters. Can't really see why. |