(Original Message Posted At : 
http://www.gamedev.net/topic/667952-boostpython-as-engines-scripting-language/
<http://www.gamedev.net/topic/667952-boostpython-as-engines-scripting-language/>
 
)

Am I thinking about this the right way? 

I'm currently working with some Boost and Boost.Python in my C++ project, in
attempts to get my project's library to utilize Python as it's game
scripting language. Similarly I suppose to how Unity utilizes C# as one of
it's game scripting languages. 

So let's say I have an abstract class that contains the virtual methods for
overriding the specific behaviors of each particular event, such as Unity's
MonoBehavior, but BaseBehavior in my case.

This is what I'm trying to do and what I'm thinking the right way to do this
is :

    1) I have a project that is dedicated to just the library portion of the
framework (Contains the BaseBehavior abstract class)

        class BaseBehavior()
        {
          public:
            virtual void OnUpdate() = 0;  
        };

    2) Export this library portion classes / functions / etc using
Boost.Python

        class BaseBehaviorWrap : public BaseBehavior, public
boost::python::wrapper<BaseBehavior>
        {
          public:
            void OnUpdate()
            {
              this->get_override("OnUpdate")();
            }
        };

        BOOST_PYTHON_MODULE(ModuleName)
        {
          boost::python::class_<BaseBehaviorWrap,
boost::noncopyable>("BaseBehavior")
            .def("OnUpdate",
boost::python::pure_virtual(&BaseBehavior::OnUpdate));
        }

    3) Within Python, in for example: ObjectBehavior.py I import my library
module inheriting from a new class from the BaseBehavior and utilizing the
particular override behaviors, such as OnUpdate()

        import ModuleName

        class NewObjectBehavior(BaseBehavior):
          def OnUpdate(self):
            # Game Behavior
            # ...

    4) Back within the C++ side I'll have a list/vector of all the objects
that contain scriptable behavior and their associated attached scripts that
contain this BaseBehavior script
    5) I'll collect each script per object and call the [ object
exec_file(str filename, object globals = object(), object locals = object())
] function within the Boost.Python on my C++ engine side
    6) From here I will utilize the boost::python::extract object to collect
my particular overridden functions and call them accordingly per object

I'm concerned with my fascination to go back to the C++ side to execute each
file and then extract each function I need per object that contains
behavior. Is this the right way to do this, or should everything be done on
the Python side? I'm really trying to keep the ideal that the GameApp is
utilized within C++, such as the window creation, event handling, frame
calculations, etc, just the engine specific pieces. While the Python side is
dedicated specifically to just Game Behaviors.



--
View this message in context: 
http://boost.2283326.n4.nabble.com/Boost-Python-As-Engine-s-Scripting-Language-tp4674850.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to