Esempio n. 1
0
static int selection_cb(lua_State *L)
{
    GList *image = dt_collection_get_selected(darktable.collection, -1);
    if(lua_gettop(L) > 0)
    {
        GList * new_selection = NULL;
        luaL_checktype(L,-1,LUA_TTABLE);
        lua_pushnil(L);
        while (lua_next(L, -2) != 0)
        {
            /* uses 'key' (at index -2) and 'value' (at index -1) */
            int imgid;
            luaA_to(L,dt_lua_image_t,&imgid,-1);
            new_selection = g_list_prepend(new_selection,GINT_TO_POINTER(imgid));
            lua_pop(L,1);
        }
        new_selection = g_list_reverse(new_selection);
        dt_lua_unlock(true);// we need the gdk lock to update ui information
        dt_selection_clear(darktable.selection);
        dt_selection_select_list(darktable.selection,new_selection);
        dt_lua_lock();
        g_list_free(new_selection);
    }
    lua_newtable(L);
    while(image)
    {
        luaA_push(L,dt_lua_image_t,&image->data);
        luaL_ref(L,-2);
        image = g_list_delete_link(image, image);
    }
    return 1;
}
Esempio n. 2
0
static int lua_button_clicked_cb(lua_State* L)
{
  lua_callback_data * data = lua_touserdata(L,1);
  dt_lua_module_entry_push(L,"lib",data->self->plugin_name);
  lua_getuservalue(L,-1);
  lua_getfield(L,-1,"callbacks");
  lua_getfield(L,-1,data->key);
  lua_pushstring(L,data->key);

  GList *image = dt_collection_get_all(darktable.collection, -1);
  lua_newtable(L);
  while(image)
  {
    luaA_push(L, dt_lua_image_t, &image->data);
    luaL_ref(L, -2);
    image = g_list_delete_link(image, image);
  }

  lua_call(L,2,1);

  GList *new_selection = NULL;
  luaL_checktype(L, -1, LUA_TTABLE);
  lua_pushnil(L);
  while(lua_next(L, -2) != 0)
  {
    /* uses 'key' (at index -2) and 'value' (at index -1) */
    int imgid;
    luaA_to(L, dt_lua_image_t, &imgid, -1);
    new_selection = g_list_prepend(new_selection, GINT_TO_POINTER(imgid));
    lua_pop(L, 1);
  }
  new_selection = g_list_reverse(new_selection);
  dt_selection_clear(darktable.selection);
  dt_selection_select_list(darktable.selection, new_selection);
  g_list_free(new_selection);
  return 0;

}