2008-11-30 Al Riddoch <alriddoch@googlemail.com>

* rulesets/mason/world/statistics/Statistics.py: Make this a new
	  style class so properties work right, and implement it all
	  as properties.


	* rulesets/StatisticsProperty.cpp: Move the setup of the script
	  instance into apply rather than install, otherwise it doesn't get
	  called in the right place.

	* rulesets/ArithmeticScript.h: Add a set method to the interface.

	* rulesets/PythonArithmeticScript.cpp,
	  rulesets/PythonArithmeticScript.h: Implement getting using
	  PyObject_GenericGetAttr() as it works. Add a completely new set
	  function.

	* rulesets/Entity.cpp: When a new property is installed it needs
	  to be applied.
This commit is contained in:
Al Riddoch 2008-11-30 03:53:11 +00:00
parent 8f89c49499
commit 93df97a92b
7 changed files with 115 additions and 32 deletions

View file

@ -40,11 +40,9 @@ PythonArithmeticScript::~PythonArithmeticScript()
int PythonArithmeticScript::attribute(const std::string & name, float & val)
{
PyObject * py_name = PyString_FromString(name.c_str());
PyObject * ret = PyObject_CallMethod(m_script,
(char *)"attribute",
(char *)"(O)", py_name);
Py_DECREF(py_name);
PyObject * pn = PyString_FromString(name.c_str());
PyObject * ret = PyObject_GenericGetAttr(m_script, pn);
Py_DECREF(pn);
if (ret == NULL) {
if (PyErr_Occurred() == NULL) {
// std::cout << "No attribute method" << std::endl << std::flush;
@ -66,3 +64,13 @@ int PythonArithmeticScript::attribute(const std::string & name, float & val)
}
return 0;
}
int PythonArithmeticScript::set(const std::string & name, const float & val)
{
std::cout << "Setting " << name << std::endl << std::flush;
PyObject * pn = PyString_FromString(name.c_str());
PyObject * py_val = PyFloat_FromDouble(val);
PyObject_GenericSetAttr(m_script, pn, py_val);
Py_DECREF(pn);
Py_DECREF(py_val);
}