/* table [key - value] string typename (or nil) */ static int _new_handle(lua_State * L) { struct atomdict *ad = atomdict_new(); int idx = _find_slot(L,ad); luaL_checktype(L,1,LUA_TTABLE); const char * typename = NULL; if (lua_gettop(L) > 1) { typename = luaL_checkstring(L,2); }
//unregisters an event with an object int awe_remove_object_event(AWE_OBJECT *src, const char *name, AWE_OBJECT *dst, void *proc) { _AWE_SIGNAL *signal; _AWE_SLOT *slot; //find signal signal = _awe_find_signal(src, name); if (!signal) return 0; //find slot slot = _find_slot(signal, dst, proc); if (!slot) return 0; //destroy the slot _destroy_slot(slot); //if the signal is empty, destroy it if (signal->slots.first == signal->slots.last == 0) { _destroy_signal(signal); } return 1; }
//registers an event with an object int awe_add_object_event(AWE_OBJECT *src, const char *name, AWE_OBJECT *dst, void *proc) { AWE_CLASS_EVENT *event; _AWE_SIGNAL *signal; _AWE_SLOT *slot; //find signal signal = _awe_find_signal(src, name); //if found, check if the slot already exists; if it exists, do nothing if (signal) { slot = _find_slot(signal, dst, proc); if (slot) return 1; } //if not found, install a new signal in the object (if the event exists) if (!signal) { event = _find_event(name, src->pclass); if (!event) return 0; signal = (_AWE_SIGNAL *)calloc(1, sizeof(_AWE_SIGNAL)); signal->name = event->name; awe_list_insert(&src->signals, &signal->node, 0); } //install a new slot in the src signal and in the dst object slot = (_AWE_SLOT *)calloc(1, sizeof(_AWE_SLOT)); slot->signal_node.data = slot; slot->slot_node.data = slot; slot->signal_list = &signal->slots; if (dst) slot->slot_list = &dst->slots; slot->object = dst; slot->proc = proc; awe_list_insert(&signal->slots, &slot->signal_node.node, 0); if (dst) awe_list_insert(&dst->slots, &slot->slot_node.node, 0); return 1; }