Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-08-05 13:35:46 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-08-05 13:35:46 +0400
commitcd1d46c61d937f63684216f284777f75038f5ed3 (patch)
treea0b4c2e81d908a08952872d1811af9da179c721f /source/blender
parent9e968cea4743640848a6e878de7fc1de47dc69b3 (diff)
Added GameLogic.Mathutils so Mathutils and its types can be accessed from blenderplayer.
also changed importText so it dosnt do a malloc
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/bad_level_call_stubs/stubs.c4
-rw-r--r--source/blender/python/BPY_interface.c38
-rw-r--r--source/blender/python/api2_2x/Blender.c2
-rw-r--r--source/blender/python/api2_2x/Mathutils.c8
-rw-r--r--source/blender/python/api2_2x/Mathutils.h2
5 files changed, 23 insertions, 31 deletions
diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
index 3ad11a61de3..561d8d7c2a6 100644
--- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c
+++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c
@@ -117,10 +117,14 @@ float BPY_pydriver_eval(struct IpoDriver *driver)
{
return 0;
}
+
+/*
int EXPP_dict_set_item_str(struct PyObject *dict, char *key, struct PyObject *value)
{
return 0;
}
+*/
+
void Node_SetStack(struct BPy_Node *self, struct bNodeStack **stack, int type){}
void InitNode(struct BPy_Node *self, struct bNode *node){}
void Node_SetShi(struct BPy_Node *self, struct ShadeInput *shi){}
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index 06e8c564ef0..69bff059356 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -163,7 +163,7 @@ PyObject *RunPython( Text * text, PyObject * globaldict );
PyObject *CreateGlobalDictionary( void );
void ReleaseGlobalDictionary( PyObject * dict );
void DoAllScriptsFromList( ListBase * list, short event );
-PyObject *importText( char *name );
+static PyObject *importText( char *name );
void init_ourImport( void );
void init_ourReload( void );
PyObject *blender_import( PyObject * self, PyObject * args );
@@ -1104,12 +1104,10 @@ int BPY_menu_do_python( short menutype, int event )
*****************************************************************************/
void BPY_free_compiled_text( struct Text *text )
{
- if( !text->compiled )
- return;
- Py_DECREF( ( PyObject * ) text->compiled );
- text->compiled = NULL;
-
- return;
+ if( text->compiled ) {
+ Py_DECREF( ( PyObject * ) text->compiled );
+ text->compiled = NULL;
+ }
}
/*****************************************************************************
@@ -2780,48 +2778,38 @@ void DoAllScriptsFromList( ListBase * list, short event )
return;
}
-PyObject *importText( char *name )
+static PyObject *importText( char *name )
{
Text *text;
- char *txtname;
+ char txtname[22]; /* 21+NULL */
char *buf = NULL;
int namelen = strlen( name );
-
- txtname = malloc( namelen + 3 + 1 );
- if( !txtname )
- return NULL;
-
+
+ if (namelen>21-3) return NULL; /* we know this cant be importable, the name is too long for blender! */
+
memcpy( txtname, name, namelen );
memcpy( &txtname[namelen], ".py", 4 );
- text = ( Text * ) & ( G.main->text.first );
-
- while( text ) {
+ for(text = G.main->text.first; text; text = text->id.next) {
if( !strcmp( txtname, text->id.name+2 ) )
break;
- text = text->id.next;
}
- if( !text ) {
- free( txtname );
+ if( !text )
return NULL;
- }
if( !text->compiled ) {
buf = txt_to_buf( text );
- text->compiled =
- Py_CompileString( buf, text->id.name+2, Py_file_input );
+ text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
MEM_freeN( buf );
if( PyErr_Occurred( ) ) {
PyErr_Print( );
BPY_free_compiled_text( text );
- free( txtname );
return NULL;
}
}
- free( txtname );
return PyImport_ExecCodeModule( name, text->compiled );
}
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index 420d292cdce..2b190a6c828 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -1074,7 +1074,7 @@ void M_Blender_Init(void)
PyDict_SetItemString(dict, "Material", Material_Init());
PyDict_SetItemString(dict, "Mesh", Mesh_Init());
PyDict_SetItemString(dict, "Metaball", Metaball_Init());
- PyDict_SetItemString(dict, "Mathutils", Mathutils_Init());
+ PyDict_SetItemString(dict, "Mathutils", Mathutils_Init("Blender.Mathutils"));
PyDict_SetItemString(dict, "Geometry", Geometry_Init());
PyDict_SetItemString(dict, "Modifier", Modifier_Init());
PyDict_SetItemString(dict, "NMesh", NMesh_Init());
diff --git a/source/blender/python/api2_2x/Mathutils.c b/source/blender/python/api2_2x/Mathutils.c
index 85c56a61628..217e096060f 100644
--- a/source/blender/python/api2_2x/Mathutils.c
+++ b/source/blender/python/api2_2x/Mathutils.c
@@ -106,8 +106,9 @@ struct PyMethodDef M_Mathutils_methods[] = {
{"Point", (PyCFunction) M_Mathutils_Point, METH_VARARGS, M_Mathutils_Point_doc},
{NULL, NULL, 0, NULL}
};
-//----------------------------MODULE INIT-------------------------
-PyObject *Mathutils_Init(void)
+/*----------------------------MODULE INIT-------------------------*/
+/* from can be Blender.Mathutils or GameLogic.Mathutils for the BGE */
+PyObject *Mathutils_Init(char *from)
{
PyObject *submodule;
@@ -125,8 +126,7 @@ PyObject *Mathutils_Init(void)
if( PyType_Ready( &quaternion_Type ) < 0 )
return NULL;
- submodule = Py_InitModule3("Blender.Mathutils",
- M_Mathutils_methods, M_Mathutils_doc);
+ submodule = Py_InitModule3(from, M_Mathutils_methods, M_Mathutils_doc);
return (submodule);
}
//-----------------------------METHODS----------------------------
diff --git a/source/blender/python/api2_2x/Mathutils.h b/source/blender/python/api2_2x/Mathutils.h
index dd9aae2abed..76d53cb6c4c 100644
--- a/source/blender/python/api2_2x/Mathutils.h
+++ b/source/blender/python/api2_2x/Mathutils.h
@@ -38,7 +38,7 @@
#include "euler.h"
#include "point.h"
-PyObject *Mathutils_Init( void );
+PyObject *Mathutils_Init( char * from );
PyObject *row_vector_multiplication(VectorObject* vec, MatrixObject * mat);
PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* vec);
PyObject *row_point_multiplication(PointObject* pt, MatrixObject * mat);