]> git.decadent.org.uk Git - ion3.git/blob - ioncore/extlconv.c
[svn-inject] Installing original source of ion3
[ion3.git] / ioncore / extlconv.c
1 /*
2  * ion/ioncore/extlconv.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <string.h>
13
14 #include <libextl/extl.h>
15 #include "common.h"
16 #include "extlconv.h"
17
18
19 /*{{{ Object list */
20
21
22 ExtlTab extl_obj_iterable_to_table(ObjIterator *iter, void *st)
23 {
24     ExtlTab tab=extl_create_table();
25     int i=1;
26     Obj *obj;
27     
28     while(1){
29         obj=iter(st);
30         if(obj==NULL)
31             break;
32         if(extl_table_seti_o(tab, i, obj))
33             i++;
34     }
35     
36     return tab;
37 }
38
39
40 /*}}}*/
41
42
43 /*{{{ Booleans */
44
45
46 bool extl_table_is_bool_set(ExtlTab tab, const char *entry)
47 {
48     bool b;
49     
50     if(extl_table_gets_b(tab, entry, &b))
51         return b;
52     return FALSE;
53 }
54
55
56 /*}}}*/
57
58
59 /*{{{ Rectangles */
60
61
62 bool extl_table_to_rectangle(ExtlTab tab, WRectangle *rectret)
63 {
64     if(!extl_table_gets_i(tab, "x", &(rectret->x)) ||
65        !extl_table_gets_i(tab, "y", &(rectret->y)) ||
66        !extl_table_gets_i(tab, "w", &(rectret->w)) ||
67        !extl_table_gets_i(tab, "h", &(rectret->h)))
68        return FALSE;
69     
70     return TRUE;
71 }
72
73
74 ExtlTab extl_table_from_rectangle(const WRectangle *rect)
75 {
76     ExtlTab tab=extl_create_table();
77     
78     extl_table_sets_i(tab, "x", rect->x);
79     extl_table_sets_i(tab, "y", rect->y);
80     extl_table_sets_i(tab, "w", rect->w);
81     extl_table_sets_i(tab, "h", rect->h);
82     
83     return tab;
84 }
85
86
87 void extl_table_sets_rectangle(ExtlTab tab, const char *nam, 
88                                const WRectangle *rect)
89 {
90     ExtlTab g=extl_table_from_rectangle(rect);
91     extl_table_sets_t(tab, nam, g);
92     extl_unref_table(g);
93 }
94
95
96 bool extl_table_gets_rectangle(ExtlTab tab, const char *nam, 
97                                WRectangle *rect)
98 {
99     ExtlTab g;
100     bool ok;
101     
102     if(!extl_table_gets_t(tab, nam, &g))
103         return FALSE;
104     
105     ok=extl_table_to_rectangle(g, rect);
106     
107     extl_unref_table(g);
108     
109     return ok;
110 }
111
112
113 /*}}}*/
114
115