/* vi: set ts=2: +-------------------+ | | Christian Schlittchen | Eressea PBEM host | Enno Rehling | (c) 1998 - 2004 | Katja Zedel | | +-------------------+ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ #include #include "eressea.h" #include "script.h" #include #include #include #include #include #include #include static void free_script(attrib * a) { if (a->data.v!=NULL) { luabind::functor * f = (luabind::functor *)a->data.v; delete f; } } attrib_type at_script = { "script", NULL, free_script, NULL, NULL, NULL, ATF_UNIQUE }; int call_script(struct unit * u) { const attrib * a = a_findc(u->attribs, &at_script); if (a==NULL) a = a_findc(u->race->attribs, &at_script); if (a!=NULL && a->data.v!=NULL) { luabind::functor * func = (luabind::functor *)a->data.v; try { func->operator()(u); } catch (luabind::error& e) { lua_State* L = e.state(); const char* error = lua_tostring(L, -1); log_error((error)); lua_pop(L, 1); std::terminate(); } } return -1; } void setscript(struct attrib ** ap, void * fptr) { attrib * a = a_find(*ap, &at_script); if (a == NULL) { a = a_add(ap, a_new(&at_script)); } else if (a->data.v!=NULL) { luabind::functor * f = (luabind::functor *)a->data.v; delete f; } a->data.v = fptr; }