added evas object box
[ego.git] / src / lib / ego.c
blob10f8be66cca018fbfb767c7c33b882cc59af26ba
1 #include "ego.h"
3 #include <lua.h>
4 #include <Evas.h>
6 #include "luaobj.h"
7 #include "class.h"
8 #include "evas.h"
9 #include "object.h"
10 #include "image.h"
11 #include "animator.h"
12 #include "smart.h"
13 #include "edje.h"
14 #include "part.h"
15 #include "line.h"
16 #include "polygon.h"
17 #include "gradient.h"
18 #include "gradient2.h"
19 #include "text.h"
20 #include "textblock.h"
21 #include "textblock_style.h"
22 #include "table.h"
23 #include "box.h"
24 #include "elementary.h"
25 #include "transform.h"
27 void
28 luaopen_ego (lua_State *L)
30 // register classes
31 luaobj_new_class (L, "cEgo", cEgo);
32 luaobj_new_class (L, "cObject", cObject);
33 luaobj_new_class (L, "cRect", cRect);
34 luaobj_new_class (L, "cImage", cImage);
35 luaobj_new_class (L, "cAnimator", cAnimator);
36 luaobj_new_class (L, "cSmart", cSmart);
37 luaobj_new_class (L, "cEdje", cEdje);
38 luaobj_new_class (L, "cPart", cPart);
39 luaobj_new_class (L, "cLine", cLine);
40 luaobj_new_class (L, "cPolygon", cPolygon);
41 luaobj_new_class (L, "cGradient", cGradient);
42 luaobj_new_class (L, "cGradient2_Linear", cGradient2_Linear);
43 luaobj_new_class (L, "cGradient2_Radial", cGradient2_Radial);
44 luaobj_new_class (L, "cText", cText);
45 luaobj_new_class (L, "cTextblock", cTextblock);
46 luaobj_new_class (L, "cStyle", cStyle);
47 luaobj_new_class (L, "cTransform", cTransform);
48 luaobj_new_class (L, "cTable", cTable);
49 luaobj_new_class (L, "cBox", cBox);
51 luaobj_new_class (L, "cIcon", cIcon);
52 luaobj_new_class (L, "cBox2", cBox2);
53 luaobj_new_class (L, "cButton", cButton);
54 luaobj_new_class (L, "cScroller", cScroller);
55 luaobj_new_class (L, "cLabel", cLabel);
56 luaobj_new_class (L, "cToggle", cToggle);
57 luaobj_new_class (L, "cFrame", cFrame);
58 luaobj_new_class (L, "cTable2", cTable2);
59 luaobj_new_class (L, "cEntry", cEntry);
60 luaobj_new_class (L, "cBubble", cBubble);
61 luaobj_new_class (L, "cHover", cHover);
62 luaobj_new_class (L, "cLayout", cLayout);
63 luaobj_new_class (L, "cClock", cClock);
66 void
67 ego_sandbox (lua_State *L, int level)
69 switch (level)
71 case 0:
73 *access to io and os routines
75 luaL_openlibs (L);
76 break;
77 case 1:
79 * no access to io and os routines
81 luaopen_base (L);
82 luaopen_table (L);
83 luaopen_string (L);
84 luaopen_math (L);
85 break;
86 case 2:
88 * no access to io and os routines
89 * no loading and execution of script files
91 luaopen_base (L);
92 luaopen_table (L);
93 luaopen_string (L);
94 luaopen_math (L);
95 lua_pushnil (L);
96 lua_setglobal (L, "loadfile");
97 lua_pushnil (L);
98 lua_setglobal (L, "dofile");
99 break;
100 case 3:
102 * no access to io and os routines
103 * no loading and execution of script files
104 * no loading and execution of script strings
106 luaopen_base (L);
107 luaopen_table (L);
108 luaopen_string (L);
109 luaopen_math (L);
110 lua_pushnil (L);
111 lua_setglobal (L, "loadfile");
112 lua_pushnil (L);
113 lua_setglobal (L, "dofile");
114 lua_pushnil (L);
115 lua_setglobal (L, "loadstring");
116 lua_pushnil (L);
117 lua_setglobal (L, "dostring");
118 break;
119 case 4:
121 * no access to io and os routines
122 * no loading and execution of script files
123 * no loading and execution of script strings
124 * no manipulation of environmental variables
126 luaopen_base (L);
127 luaopen_table (L);
128 luaopen_string (L);
129 luaopen_math (L);
130 lua_pushnil (L);
131 lua_setglobal (L, "loadfile");
132 lua_pushnil (L);
133 lua_setglobal (L, "dofile");
134 lua_pushnil (L);
135 lua_setglobal (L, "loadstring");
136 lua_pushnil (L);
137 lua_setglobal (L, "dostring");
138 lua_pushnil (L);
139 lua_setglobal (L, "getfenv");
140 lua_pushnil (L);
141 lua_setglobal (L, "setfenv");
142 break;
147 * ego smart class implementatoin
149 static lua_State *glob_L = NULL;
150 static Evas_Smart_Class parent_sc = {NULL};
151 static Evas_Smart_Class sc = {NULL};
153 static void
154 ego_smart_class_add (Evas_Object *obj)
156 lua_State *L = glob_L;
157 parent_sc.add (obj);
159 // register main class
160 luaobj_Object *lobj = lua_newuserdata (L, sizeof (luaobj_Object));
161 luaobj_set_class (L, -1, lobj, "cEgo");
162 lobj->data = obj;
163 evas_object_data_set (lobj->data, "luaobj", luaobj_new_ref (L, -1));
164 lua_setglobal (L, "ego");
166 // read in buffer at index -1
167 if (lua_pcall (L, 0, LUA_MULTRET, 0))
169 fprintf (stderr, "ego parse error: %s\n", lua_tostring (L, -1));
170 exit (-1);
174 static Evas_Smart *
175 ego_smart_class_new (void)
177 if (!parent_sc.name)
179 parent_sc.name = "parent_ego";
180 parent_sc.version = EVAS_SMART_CLASS_VERSION;
181 evas_object_smart_clipped_smart_set (&parent_sc);
183 if (!sc.name)
185 sc.name = "ego";
186 sc.version = EVAS_SMART_CLASS_VERSION;
187 evas_object_smart_clipped_smart_set (&sc);
188 sc.add = ego_smart_class_add;
190 return evas_smart_class_new (&sc);
194 * ego smart class creation
196 Evas_Object *
197 ego_object_add (Evas *evas, lua_State *L)
199 // create smart object
200 glob_L = L;
202 return evas_object_smart_add (evas, ego_smart_class_new ());