]> git.decadent.org.uk Git - ion3.git/blob - ioncore/extlconv.c
Imported Upstream version 20090110
[ion3.git] / ioncore / extlconv.c
1 /*
2  * ion/ioncore/extlconv.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <string.h>
10
11 #include <libextl/extl.h>
12 #include "common.h"
13 #include "extlconv.h"
14
15
16 /*{{{ Object list */
17
18
19 bool extl_iter_objlist_(ExtlFn fn, ObjIterator *iter, void *st)
20 {
21     Obj *obj;
22     
23     while(1){
24         obj=iter(st);
25         if(obj==NULL)
26             break;
27         if(!extl_iter_obj(fn, obj))
28             return FALSE;
29     }
30     
31     return TRUE;
32 }
33
34
35 bool extl_iter_objlist(ExtlFn fn, ObjList *list)
36 {
37     ObjListIterTmp tmp;
38     
39     objlist_iter_init(&tmp, list);
40     
41     return extl_iter_objlist_(fn, (ObjIterator*)objlist_iter, &tmp);
42 }
43
44
45 bool extl_iter_obj(ExtlFn fn, Obj *obj)
46 {
47     bool ret1, ret2=FALSE;
48     
49     extl_protect(NULL);
50     
51     ret1=extl_call(fn, "o", "b", obj, &ret2);
52     
53     extl_unprotect(NULL);
54     
55     return (ret1 && ret2);
56 }
57
58
59 /*}}}*/
60
61
62 /*{{{ Booleans */
63
64
65 bool extl_table_is_bool_set(ExtlTab tab, const char *entry)
66 {
67     bool b;
68     
69     if(extl_table_gets_b(tab, entry, &b))
70         return b;
71     return FALSE;
72 }
73
74
75 /*}}}*/
76
77
78 /*{{{ Rectangles */
79
80
81 bool extl_table_to_rectangle(ExtlTab tab, WRectangle *rectret)
82 {
83     if(!extl_table_gets_i(tab, "x", &(rectret->x)) ||
84        !extl_table_gets_i(tab, "y", &(rectret->y)) ||
85        !extl_table_gets_i(tab, "w", &(rectret->w)) ||
86        !extl_table_gets_i(tab, "h", &(rectret->h)))
87        return FALSE;
88     
89     return TRUE;
90 }
91
92
93 ExtlTab extl_table_from_rectangle(const WRectangle *rect)
94 {
95     ExtlTab tab=extl_create_table();
96     
97     extl_table_sets_i(tab, "x", rect->x);
98     extl_table_sets_i(tab, "y", rect->y);
99     extl_table_sets_i(tab, "w", rect->w);
100     extl_table_sets_i(tab, "h", rect->h);
101     
102     return tab;
103 }
104
105
106 void extl_table_sets_rectangle(ExtlTab tab, const char *nam, 
107                                const WRectangle *rect)
108 {
109     ExtlTab g=extl_table_from_rectangle(rect);
110     extl_table_sets_t(tab, nam, g);
111     extl_unref_table(g);
112 }
113
114
115 bool extl_table_gets_rectangle(ExtlTab tab, const char *nam, 
116                                WRectangle *rect)
117 {
118     ExtlTab g;
119     bool ok;
120     
121     if(!extl_table_gets_t(tab, nam, &g))
122         return FALSE;
123     
124     ok=extl_table_to_rectangle(g, rect);
125     
126     extl_unref_table(g);
127     
128     return ok;
129 }
130
131
132 /*}}}*/
133
134