// Called from lua to get the metatable static int addon_pload_metatable(lua_State *L) { const char *key = luaL_checkstring(L, 2); struct analyzer_pload_instance **i = luaL_checkudata(L, 1, ADDON_PLOAD_METATABLE); struct analyzer_pload_buffer *p = analyzer_pload_instance_get_buffer(*i); if (!strcmp(key, "event")) { // Return the corresponding event addon_event_push(L, p->rel_event); } else if (!strcmp(key, "data")) { addon_data_push(L, p->data, p->type->analyzer->data_reg); } else if (!strcmp(key, "type") && p->type) { // Return the type table if any lua_newtable(L); // Add type name lua_pushliteral(L, "name"); lua_pushstring(L, p->type->name); lua_settable(L, -3); // Add type description lua_pushliteral(L, "description"); lua_pushstring(L, p->type->description); lua_settable(L, -3); // Add type extension lua_pushliteral(L, "extension"); lua_pushstring(L, p->type->extension); lua_settable(L, -3); // Add the class lua_pushliteral(L, "class"); switch (p->type->cls) { case analyzer_pload_class_unknown: lua_pushliteral(L, "unknown"); break; case analyzer_pload_class_application: lua_pushliteral(L, "application"); break; case analyzer_pload_class_audio: lua_pushliteral(L, "audio"); break; case analyzer_pload_class_image: lua_pushliteral(L, "image"); break; case analyzer_pload_class_video: lua_pushliteral(L, "video"); break; case analyzer_pload_class_document: lua_pushliteral(L, "document"); break; } lua_settable(L, -3); } else { return 0; } return 1; }
static int addon_event_get_field(lua_State *L) { struct addon_event *e = luaL_checkudata(L, 1, ADDON_EVENT_METATABLE); const char *key = luaL_checkstring(L, 2); if (!strcmp(key, "name")) { lua_pushstring(L, e->evt->reg->info->name); } else if (!strcmp(key, "data")) { addon_data_push(L, e->evt->data, e->evt->reg->info->data_reg); } else if (!strcmp(key, "timestamp")) { lua_pushinteger(L, e->evt->ts); } else { lua_pushnil(L); } return 1; }