Skip to content

Commit

Permalink
ADDED support for NULL tuple elements in python::*tuple methods
Browse files Browse the repository at this point in the history
ADDED some hooks required by mapedit
  • Loading branch information
ksterker committed Jul 25, 2010
1 parent 808a3f1 commit 389d961
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/python/method.h
Expand Up @@ -67,6 +67,12 @@ namespace python
*/
std::string name () const;

/**
* Return name of enclosing script.
* @return script name.
*/
std::string script () const { return Script->class_name(); }

/**
* Execute the connected %method with the given arguments.
* @param args a python tuple to be passed to the %method.
Expand Down
13 changes: 10 additions & 3 deletions src/python/python.cc
Expand Up @@ -127,8 +127,8 @@ namespace python
// copy remaining objects, if any
for (u_int16 i = len; i < size; i++)
{
PyObject *o = PyTuple_GET_ITEM (tuple, i - len);
Py_INCREF (o);
PyObject *o = PyTuple_GET_ITEM (tuple, i - len);
Py_XINCREF (o);
PyTuple_SET_ITEM (new_tuple, i, o);
}

Expand All @@ -146,6 +146,11 @@ namespace python
{
switch (int type = in.next (&value))
{
case base::flat::T_CHAR:
{
PyTuple_SetItem (tuple, i, Py_None);
break;
}
case base::flat::T_STRING:
{
// Stolen reference
Expand Down Expand Up @@ -180,10 +185,12 @@ namespace python
{
// Borrowed reference
PyObject *item = PyTuple_GetItem (tuple, i);
if (item == NULL)
out.put_char ("n", ' ');

// Check for the type of this object
// String?
if (PyString_Check (item))
else if (PyString_Check (item))
out.put_string ("s", PyString_AsString (item));

// Integer?
Expand Down
14 changes: 14 additions & 0 deletions src/world/action.h
Expand Up @@ -75,6 +75,20 @@ namespace world
* @param target the object acted on.
*/
void execute (world::character *actor, world::object *target);

/**
* Get the method that implements the action. Might be
* NULL if the action is not initialized yet.
*
* @return the method that implements the action.
*/
python::method *get_method () const { return Action; }

/**
* Get the arguments used to execute the action.
* @return the method arguments.
*/
PyObject *get_args () const { return Args; }
#endif

/**
Expand Down
8 changes: 1 addition & 7 deletions src/world/area.cc
Expand Up @@ -253,9 +253,7 @@ bool area::put_state (base::flat & file) const
if (!data.Anonymous.empty())
{
base::flat anonym;
j = data.Anonymous.begin();

for (; j != data.Anonymous.end(); j++)
for (j = data.Anonymous.begin(); j != data.Anonymous.end(); j++)
{
// save location action
if ((*j)->has_action ())
Expand Down Expand Up @@ -309,10 +307,6 @@ bool area::put_state (base::flat & file) const

file.put_flat ("states", record);

// reset
index = 0;
record.clear();

// save the zones
std::list <world::zone *>::const_iterator zone_i = Zones.begin();
base::flat zone_list;
Expand Down

0 comments on commit 389d961

Please sign in to comment.