Commit: 7730391d7425a8581cf16b3a6510acc56108071c
Author: Porteries Tristan
Date:   Wed Apr 15 21:45:43 2015 +1000
Branches: master
https://developer.blender.org/rB7730391d7425a8581cf16b3a6510acc56108071c

BGE: subclass with more than 1 argument, D1237

In the BGE you can't create a subclass with more than 1 argument like : "player 
= Player(owner, 10)"
I have modified the py_base_new to check only the first argument of args tuple.
Now we can do :

    class Player(types.KX_GameObject):
        def __init__(self, gameobj, life):
            print("create new player :", self, ", life :", life)

    player = Player(own, 50)

===================================================================

M       source/gameengine/Expressions/PyObjectPlus.cpp

===================================================================

diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp 
b/source/gameengine/Expressions/PyObjectPlus.cpp
index a65d61b..d475152 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -148,10 +148,15 @@ PyObject *PyObjectPlus::py_base_repr(PyObject *self)      
                // This should be the ent
 PyObject *PyObjectPlus::py_base_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds)
 {
        PyTypeObject *base_type;
-       PyObjectPlus_Proxy *base = NULL;
 
-       if (!PyArg_ParseTuple(args, "O:Base PyObjectPlus", &base))
+       /* one or more args is needed */
+       if (!PyTuple_GET_SIZE(args)) {
+               PyErr_SetString(PyExc_TypeError,
+                               "Expected at least one argument");
                return NULL;
+       }
+
+       PyObjectPlus_Proxy *base = (PyObjectPlus_Proxy *)PyTuple_GET_ITEM(args, 
0);
 
        /* the 'base' PyObject may be subclassed (multiple times even)
         * we need to find the first C++ defined class to check 'type'

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to