1 /*
2    This file is part of darktable,
3    Copyright (C) 2013-2021 darktable developers.
4 
5    darktable is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9 
10    darktable is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "lua/glist.h"
20 #include <lauxlib.h>
21 #include <stdlib.h>
22 
dt_lua_push_glist_type(lua_State * L,GList * list,luaA_Type elt_type)23 void dt_lua_push_glist_type(lua_State *L, GList *list, luaA_Type elt_type)
24 {
25   lua_newtable(L);
26   int index_table = 1;
27   for(const GList *elt = list; elt; elt = g_list_next(elt))
28   {
29     luaA_push_type(L, elt_type, elt->data);
30     lua_seti(L, -2, index_table);
31     index_table++;
32   }
33 }
34 
dt_lua_to_glist_type(lua_State * L,luaA_Type elt_type,int index)35 GList *dt_lua_to_glist_type(lua_State *L, luaA_Type elt_type, int index)
36 {
37   // recreate list of images
38   GList *list = NULL;
39   size_t type_size = luaA_typesize(L, elt_type);
40   lua_pushnil(L); /* first key */
41   while(lua_next(L, index - 1) != 0)
42   {
43     /* uses 'key' (at index -2) and 'value' (at index -1) */
44     void *obj = malloc(type_size);
45     luaA_to_type(L, elt_type, obj, -1);
46     lua_pop(L, 1);
47     list = g_list_prepend(list, (gpointer)obj);
48   }
49   list = g_list_reverse(list);
50   return list;
51 }
52 
dt_lua_init_glist(lua_State * L)53 int dt_lua_init_glist(lua_State *L)
54 {
55   return 0;
56 }
57 
58 
59 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
60 // vim: shiftwidth=2 expandtab tabstop=2 cindent
61 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
62