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