static int _pattern_delete(lua_State *L) { struct pbc_pattern * pat = (struct pbc_pattern *)lua_touserdata(L,1); pbc_pattern_delete(pat); return 0; }
int main() { struct pbc_slice slice; read_file("addressbook.pb", &slice); if (slice.buffer == NULL) return 1; struct pbc_env * env = pbc_new(); pbc_register(env, &slice); free(slice.buffer); pat = pbc_pattern_new(env, "tutorial.Person" , "name %s id %d email %s phone %a test %a", offsetof(struct person, name) , offsetof(struct person, id) , offsetof(struct person, email) , offsetof(struct person, phone) , offsetof(struct person, test)); pat_phone = pbc_pattern_new(env, "tutorial.Person.PhoneNumber", "number %s type %d", offsetof(struct person_phone, number), offsetof(struct person_phone, type)); char buffer[4096]; struct pbc_slice message = { buffer, sizeof(buffer) }; test_pattern_pack(env, &message); dump((uint8_t*)message.buffer, message.len); test_pattern_unpack(env, &message); pbc_pattern_delete(pat); pbc_pattern_delete(pat_phone); pbc_delete(env); return 0; }
static int _clear_gcobj(lua_State *L) { struct gcobj * obj = (struct gcobj *)lua_touserdata(L,1); int i; for (i=0;i<obj->size_pat;i++) { pbc_pattern_delete(obj->pat[i]); } for (i=0;i<obj->size_msg;i++) { pbc_rmessage_delete(obj->msg[i]); } free(obj->pat); free(obj->msg); obj->pat = NULL; obj->msg = NULL; pbc_delete(obj->env); obj->env = NULL; return 0; }