int luax_table_insert(lua_State *L, int tindex, int vindex, int pos) { if (tindex < 0) tindex = lua_gettop(L)+1+tindex; if (vindex < 0) vindex = lua_gettop(L)+1+vindex; if (pos == -1) { lua_pushvalue(L, vindex); lua_rawseti(L, tindex, (int) luax_objlen(L, tindex)+1); return 0; } else if (pos < 0) pos = (int) luax_objlen(L, tindex)+1+pos; for (int i = (int) luax_objlen(L, tindex)+1; i > pos; i--) { lua_rawgeti(L, tindex, i-1); lua_rawseti(L, tindex, i); } lua_pushvalue(L, vindex); lua_rawseti(L, tindex, pos); return 0; }
int w_newBMFontRasterizer(lua_State *L) { Rasterizer *t = nullptr; filesystem::FileData *d = filesystem::luax_getfiledata(L, 1); std::vector<image::ImageData *> images; if (lua_istable(L, 2)) { for (int i = 1; i <= (int) luax_objlen(L, 2); i++) { lua_rawgeti(L, 2, i); convimagedata(L, -1); image::ImageData *id = luax_checktype<image::ImageData>(L, -1, IMAGE_IMAGE_DATA_ID); images.push_back(id); id->retain(); lua_pop(L, 1); } } else { for (int i = 2; i <= lua_gettop(L); i++) { convimagedata(L, i); image::ImageData *id = luax_checktype<image::ImageData>(L, i, IMAGE_IMAGE_DATA_ID); images.push_back(id); id->retain(); } } luax_catchexcept(L, [&]() { t = instance()->newBMFontRasterizer(d, images); }, [&](bool) { d->release(); for (auto id : images) id->release(); } ); luax_pushtype(L, FONT_RASTERIZER_ID, t); t->release(); return 1; }