static int generic_atfind (lua_State *L, int tfind) { int res; TArgExec argE; TPosix *ud; regaparams_t argP; regamatch_t res_match; checkarg_atfind (L, &argE, &ud, &argP); if (argE.startoffset > (int)argE.textlen) return lua_pushnil(L), 1; argE.text += argE.startoffset; res_match.nmatch = ALG_NSUB(ud) + 1; res_match.pmatch = ud->match; /* execute the search */ res = tre_reganexec (&ud->r, argE.text, argE.textlen - argE.startoffset, &res_match, argP, argE.eflags); if (ALG_ISMATCH (res)) { ALG_PUSHOFFSETS (L, ud, argE.startoffset, 0); if (tfind) push_substring_table (L, ud, argE.text); else push_offset_table (L, ud, argE.startoffset); /* set values in the dictionary part of the table */ set_int_field (L, "cost", res_match.cost); set_int_field (L, "num_ins", res_match.num_ins); set_int_field (L, "num_del", res_match.num_del); set_int_field (L, "num_subst", res_match.num_subst); return 3; } else if (ALG_NOMATCH (res)) return lua_pushnil (L), 1; else return generate_error (L, ud, res); }
static int push_package(lua_State *L, struct apk_package *pkg) { if (pkg == NULL) { lua_pushnil(L); return 1; } lua_newtable(L); set_string_field(L, -3, "name", pkg->name->name); set_string_field(L, -3, "version", apk_blob_cstr(*pkg->version)); set_string_field(L, -3, "url", pkg->url); set_string_field(L, -3, "license", apk_blob_cstr(*pkg->license)); set_string_field(L, -3, "description", pkg->description); set_string_field(L, -3, "filename", pkg->filename); set_int_field(L, -3, "size", pkg->size); return 1; }