added elementary layout, clock. prototyped plugin configuration
[ego.git] / src / lib / ego.c
blobd5605f37066dc372ae4e5614831327135aa73ffc
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 "elementary.h"
23 #include "transform.h"
25 void
26 luaopen_ego (lua_State *L)
28 // register classes
29 luaobj_new_class (L, "cEgo", cEgo);
30 luaobj_new_class (L, "cObject", cObject);
31 luaobj_new_class (L, "cRect", cRect);
32 luaobj_new_class (L, "cImage", cImage);
33 luaobj_new_class (L, "cAnimator", cAnimator);
34 luaobj_new_class (L, "cSmart", cSmart);
35 luaobj_new_class (L, "cEdje", cEdje);
36 luaobj_new_class (L, "cPart", cPart);
37 luaobj_new_class (L, "cLine", cLine);
38 luaobj_new_class (L, "cPolygon", cPolygon);
39 luaobj_new_class (L, "cGradient", cGradient);
40 luaobj_new_class (L, "cGradient2_Linear", cGradient2_Linear);
41 luaobj_new_class (L, "cGradient2_Radial", cGradient2_Radial);
42 luaobj_new_class (L, "cText", cText);
43 luaobj_new_class (L, "cTextblock", cTextblock);
44 luaobj_new_class (L, "cStyle", cStyle);
45 luaobj_new_class (L, "cTransform", cTransform);
47 luaobj_new_class (L, "cIcon", cIcon);
48 luaobj_new_class (L, "cBox", cBox);
49 luaobj_new_class (L, "cButton", cButton);
50 luaobj_new_class (L, "cScroller", cScroller);
51 luaobj_new_class (L, "cLabel", cLabel);
52 luaobj_new_class (L, "cToggle", cToggle);
53 luaobj_new_class (L, "cFrame", cFrame);
54 luaobj_new_class (L, "cTable", cTable);
55 luaobj_new_class (L, "cEntry", cEntry);
56 luaobj_new_class (L, "cBubble", cBubble);
57 luaobj_new_class (L, "cHover", cHover);
58 luaobj_new_class (L, "cLayout", cLayout);
59 luaobj_new_class (L, "cClock", cClock);
62 void
63 ego_sandbox (lua_State *L, int level)
65 switch (level)
67 case 0:
69 *access to io and os routines
71 luaL_openlibs (L);
72 break;
73 case 1:
75 * no access to io and os routines
77 luaopen_base (L);
78 luaopen_table (L);
79 luaopen_string (L);
80 luaopen_math (L);
81 break;
82 case 2:
84 * no access to io and os routines
85 * no loading and execution of script files
87 luaopen_base (L);
88 luaopen_table (L);
89 luaopen_string (L);
90 luaopen_math (L);
91 lua_pushnil (L);
92 lua_setglobal (L, "loadfile");
93 lua_pushnil (L);
94 lua_setglobal (L, "dofile");
95 break;
96 case 3:
98 * no access to io and os routines
99 * no loading and execution of script files
100 * no loading and execution of script strings
102 luaopen_base (L);
103 luaopen_table (L);
104 luaopen_string (L);
105 luaopen_math (L);
106 lua_pushnil (L);
107 lua_setglobal (L, "loadfile");
108 lua_pushnil (L);
109 lua_setglobal (L, "dofile");
110 lua_pushnil (L);
111 lua_setglobal (L, "loadstring");
112 lua_pushnil (L);
113 lua_setglobal (L, "dostring");
114 break;
115 case 4:
117 * no access to io and os routines
118 * no loading and execution of script files
119 * no loading and execution of script strings
120 * no manipulation of environmental variables
122 luaopen_base (L);
123 luaopen_table (L);
124 luaopen_string (L);
125 luaopen_math (L);
126 lua_pushnil (L);
127 lua_setglobal (L, "loadfile");
128 lua_pushnil (L);
129 lua_setglobal (L, "dofile");
130 lua_pushnil (L);
131 lua_setglobal (L, "loadstring");
132 lua_pushnil (L);
133 lua_setglobal (L, "dostring");
134 lua_pushnil (L);
135 lua_setglobal (L, "getfenv");
136 lua_pushnil (L);
137 lua_setglobal (L, "setfenv");
138 break;
143 * ego smart class implementatoin
145 static lua_State *glob_L = NULL;
146 static Evas_Smart_Class parent_sc = {NULL};
147 static Evas_Smart_Class sc = {NULL};
149 static void
150 ego_smart_class_add (Evas_Object *obj)
152 lua_State *L = glob_L;
153 parent_sc.add (obj);
155 // register main class
156 luaobj_Object *lobj = lua_newuserdata (L, sizeof (luaobj_Object));
157 luaobj_set_class (L, -1, lobj, "cEgo");
158 lobj->data = obj;
159 evas_object_data_set (lobj->data, "luaobj", luaobj_new_ref (L, -1));
160 lua_setglobal (L, "ego");
162 // read in buffer at index -1
163 if (lua_pcall (L, 0, LUA_MULTRET, 0))
165 fprintf (stderr, "ego parse error: %s\n", lua_tostring (L, -1));
166 exit (-1);
170 static Evas_Smart *
171 ego_smart_class_new (void)
173 if (!parent_sc.name)
175 parent_sc.name = "parent_ego";
176 parent_sc.version = EVAS_SMART_CLASS_VERSION;
177 evas_object_smart_clipped_smart_set (&parent_sc);
179 if (!sc.name)
181 sc.name = "ego";
182 sc.version = EVAS_SMART_CLASS_VERSION;
183 evas_object_smart_clipped_smart_set (&sc);
184 sc.add = ego_smart_class_add;
186 return evas_smart_class_new (&sc);
190 * ego smart class creation
192 Evas_Object *
193 ego_object_add (Evas *evas, lua_State *L)
195 // create smart object
196 glob_L = L;
198 return evas_object_smart_add (evas, ego_smart_class_new ());