Python plugins
- clarahobbs
- Private First Class
- Posts: 272
- Joined: Thu Jan 10, 2008 1:45 am
- Location: The Fourth Dimension
Python plugins
It looks like a long time ago (the era of 1.10.x) there was a way to write plugins in Python. I wish this was possible now, as I have some ideas for plugins and I don't know C++ (nor do I have any desire to learn C++ in the near future). Python is, for many programs, a wonderful language for writing plugins (Blender, GIMP, etc.) and I think a lot more people (at least me) would make plugins for BZFlag if they could in Python. (p.s. I think this is in the wrong forum. If it is, please move it)
FKA Ratfink
- clarahobbs
- Private First Class
- Posts: 272
- Joined: Thu Jan 10, 2008 1:45 am
- Location: The Fourth Dimension
The API didn't exist untill 2.0.x.
The python plug-in is a fair amount of work to keep up to date, but it's mostly trivial work (just making mappings).
I don't think there is a lot of interest because the amount of C++ needed to make plug-ins is pretty simple. and python is very similar to C++ anyway so the leap to making them in C++ is not hard at all. This means there isn't much of a call for it, so no developers really have a need to keep it up to date.
The python plug-in is a fair amount of work to keep up to date, but it's mostly trivial work (just making mappings).
I don't think there is a lot of interest because the amount of C++ needed to make plug-ins is pretty simple. and python is very similar to C++ anyway so the leap to making them in C++ is not hard at all. This means there isn't much of a call for it, so no developers really have a need to keep it up to date.
JeffM
The Boost.Python library makes it easier to expose C++ libraries to python. I was going to try to expose the bzfsAPI, but the Boost.Python library generally requires the Boost build tools. I can use Boost.Build, but I am unfamiliar with configure and couldn't find out how to link to the plug-in API.
From the Boost website:
QuickStart
The Boost Python Library is a framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ classes functions and objects to Python, and vice-versa, using no special tools -- just your C++ compiler. It is designed to wrap C++ interfaces non-intrusively, so that you should not have to change the C++ code at all in order to wrap it, making Boost.Python ideal for exposing 3rd-party libraries to Python. The library's use of advanced metaprogramming techniques simplifies its syntax for users, so that wrapping code takes on the look of a kind of declarative interface definition language (IDL).
Hello World
Following C/C++ tradition, let's start with the "hello, world". A C++ Function:
char const* greet()
{
return "hello, world";
}
can be exposed to Python by writing a Boost.Python wrapper:
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:
>>> import hello_ext
>>> print hello.greet()
hello, world
From the Boost website:
QuickStart
The Boost Python Library is a framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ classes functions and objects to Python, and vice-versa, using no special tools -- just your C++ compiler. It is designed to wrap C++ interfaces non-intrusively, so that you should not have to change the C++ code at all in order to wrap it, making Boost.Python ideal for exposing 3rd-party libraries to Python. The library's use of advanced metaprogramming techniques simplifies its syntax for users, so that wrapping code takes on the look of a kind of declarative interface definition language (IDL).
Hello World
Following C/C++ tradition, let's start with the "hello, world". A C++ Function:
char const* greet()
{
return "hello, world";
}
can be exposed to Python by writing a Boost.Python wrapper:
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:
>>> import hello_ext
>>> print hello.greet()
hello, world