All pastes #266445 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-04 03:39 UTC
rendered paste body
void node_script_parse_cb(struct bNodeTree *ntree, struct bNode *node)
{printf("node_script_parse_cb\n");
	BPy_Node *pynode= NULL;
	BPy_ShadeInput *myshi = NULL;
	PyObject *outputdef= NULL;
	PyObject *inputdef= NULL;
	PyObject *key= NULL;
	PyObject *value= NULL;
	PyObject *testinst= NULL;
	PyObject *args= NULL;
	int pos = 0;
	NodeScriptDict *nsd;
	void *shi; /* for BPy_ShadeInput *shi */
	void *node1; /* for BPy_Node *node */

	PyObject *pyresult = NULL;
	Text *txt = 0;
	char *buf;

	if(! node->id) {
		return;
	}

	if(node->custom1!=SH_NODE_SCRIPT_READY) {
		txt = (Text *)node->id;
		//nsd = (NodeScriptDict *)node->storage;
		PyObject *dict=init_scriptdict();
		buf = txt_to_buf( txt );

		pyresult = PyRun_String(buf, Py_file_input, dict, dict);

		MEM_freeN(buf);

		if(!pyresult) {
			if(PyErr_Occurred()) {
				PyErr_Print();
			}
			Py_XDECREF(pyresult);
			return;
		}
		Py_DECREF(pyresult);
		//PyObject_Del(pyresult);

		myshi=(BPy_ShadeInput *)ShadeInput_CreatePyObject(NULL);
		
		while(PyDict_Next( dict, &pos, &key, &value) ) {
			if(PyObject_TypeCheck(value, &PyType_Type)) {
				pynode = (BPy_Node *)Node_CreatePyObject(node);
				outputdef= Node_CreateOutputDefMap(pynode);
				inputdef= Node_CreateInputDefMap(pynode);
				args= Py_BuildValue("(NN)", inputdef, outputdef);
				testinst= PyObject_Call(value, args, NULL);
				if(testinst && PyObject_TypeCheck(testinst, &Node_Type)==1) {
					node1= testinst;
					nsd->node=node1;
					nsd->shi= myshi;
					nsd->dict=dict;
					free_scriptdict((PyObject *)(nsd->dict));
					node->typeinfo->execfunc= node_script_exec;
					if(node->custom1== SH_NODE_SCRIPT_NEW) {
						node->typeinfo->pynode= testinst;
						node->typeinfo->id= node->id;
						nodeRegisterType(ntree, node->typeinfo);
						node->custom1= SH_NODE_SCRIPT_CREATED;
					} else if(node->custom1== SH_NODE_SCRIPT_REPARSE) {
						node->typeinfo->pynode= testinst;
						node->typeinfo->id= node->id;
						ntreeUpdateType(ntree, node->typeinfo);
						node->custom1= SH_NODE_SCRIPT_UPDATED;
					} else if(node->custom1== SH_NODE_SCRIPT_LOADED) {
						node->typeinfo->pynode= testinst;
						node->typeinfo->id= node->id;
						nodeRegisterType(ntree, node->typeinfo);
						node->custom1= SH_NODE_SCRIPT_READY;
					} else if(node->custom1== SH_NODE_SCRIPT_ADDEXIST) {
						node->custom1= SH_NODE_SCRIPT_READY;
					}
					break;
				}
			}
		}
	}
}