static int write_image(lua_State *L) { /* check that param 1 is a module_format_t */ luaL_argcheck(L,dt_lua_isa(L,1,dt_imageio_module_format_t),-1,"dt_imageio_module_format_t expected"); lua_getmetatable(L,1); lua_getfield(L,-1,"__luaA_Type"); luaA_Type format_type = luaL_checkint(L,-1); lua_pop(L,1); lua_getfield(L,-1,"__associated_object"); dt_imageio_module_format_t * format = lua_touserdata(L,-1); lua_pop(L,2); dt_imageio_module_data_t* fdata = format->get_params(format); luaA_to_type(L,format_type,fdata,1); /* check that param 2 is an image */ dt_lua_image_t imgid; luaA_to(L,dt_lua_image_t,&imgid,2); /* check that param 3 is a string (filename) */ const char * filename = luaL_checkstring(L,3); dt_lua_unlock(false); gboolean high_quality = dt_conf_get_bool("plugins/lighttable/export/high_quality_processing"); gboolean result = dt_imageio_export(imgid,filename,format,fdata,high_quality,FALSE,NULL,NULL); dt_lua_lock(); lua_pushboolean(L,result); format->free_params(format,fdata); return 1; }
GList *dt_lua_to_glist_type(lua_State *L, luaA_Type elt_type, int index) { // recreate list of images GList *list = NULL; size_t type_size = luaA_typesize(L, elt_type); lua_pushnil(L); /* first key */ while(lua_next(L, index - 1) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ void *obj = malloc(type_size); luaA_to_type(L, elt_type, obj, -1); lua_pop(L, 1); list = g_list_prepend(list, (gpointer)obj); } list = g_list_reverse(list); return list; }