efl

Форк
0
/
edje_lua2.c 
4468 строк · 139.3 Кб
1
// FIXME: Some error checking would be nice.
2

3
#include "edje_private.h"
4
#include <ctype.h>
5

6
#define RASTER_FORGOT_WHY "this is here."
7

8
//--------------------------------------------------------------------------//
9
#define MAX_LUA_MEM       (4 * (1024 * 1024))
10
#define ELO               "|-ELO"
11

12
#define LC(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__)
13
#define LE(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__)
14
#define LW(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__)
15
#define LI(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
16
#define LD(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
17

18
/**
19
   @page luaref Edje Lua scripting
20

21
   @section edje_lua_intro Introduction
22

23
   Lua is intended for script-only objects at this point (with embryo left
24
   for augmenting standard programs). Since script-only objects effectively
25
   define objects entirely via Lua script (resize handling, event handling
26
   etc. etc.) this places many more demands on them, and thus a more powerful
27
   language is in order. Lua is that language.
28

29
   To get you started, here's an example that uses most of this lua API:
30
   @ref lua_script.edc
31

32
   Most of these lua functions are wrappers around various evas, ecore, and edje C
33
   functions.  Refer to their documentation for more in depth details and up to
34
   date documentation.  A lot of this documentation is simple copied from the C
35
   functions it wraps.
36

37
   @section args Lua function argument and return syntax
38

39
   Some of the lua functions can accept a table as well as separate arguments.
40
   Some of them return tables.
41

42
   @section classes Lua classes
43

44
 */
45

46
/*
47
   Lua functions stack usage.
48

49
   In the definition of the lua functions provided, always mention the stack usage,
50
   using the same notation that is used in the Lua 5.1 Reference Manual.
51
   http://www.lua.org/manual/5.1/manual.html#3.7 describes that notation.
52

53
   On the other hand, lua discards excess stack entries when control passes back to
54
   it, but it's good to maintain proper discipline.
55

56
   Should do the same for the support functions.  These ARE more important to check.
57
 */
58

59
//--------------------------------------------------------------------------//
60
typedef struct _Edje_Lua_Alloc       Edje_Lua_Alloc;
61
typedef struct _Edje_Lua_Allocator   Edje_Lua_Allocator;
62
typedef struct _Edje_Lua_Obj         Edje_Lua_Obj;
63
typedef struct _Edje_Lua_Animator    Edje_Lua_Animator;
64
typedef struct _Edje_Lua_Timer       Edje_Lua_Timer;
65
typedef struct _Edje_Lua_Transition  Edje_Lua_Transition;
66
typedef struct _Edje_Lua_Evas_Object Edje_Lua_Evas_Object;
67
typedef struct _Edje_Lua_Map         Edje_Lua_Map;
68

69
struct _Edje_Lua_Alloc
70
{
71
   size_t max, cur;
72
};
73

74
struct _Edje_Lua_Allocator
75
{
76
   Edje_Lua_Alloc *ela;
77
   void           *(*func)(void *ud, void *ptr, size_t osize, size_t nsize);
78
   void           *ud;
79
   int             ref;
80
};
81

82
struct _Edje_Lua_Obj
83
{
84
   EINA_INLIST;
85

86
   Edje       *ed;
87
   void        (*free_func)(void *obj);
88
   const char *meta;
89
};
90

91
struct _Edje_Lua_Animator
92
{
93
   Edje_Lua_Obj    obj;
94
   Ecore_Animator *animator;
95
   int             fn_ref;
96
};
97

98
struct _Edje_Lua_Timer
99
{
100
   Edje_Lua_Obj obj;
101
   Ecore_Timer *timer;
102
   int          fn_ref;
103
};
104

105
struct _Edje_Lua_Transition
106
{
107
   Edje_Lua_Obj    obj;
108
   Ecore_Animator *animator;
109
   double          transition, start;
110
   int             fn_ref;
111
};
112

113
struct _Edje_Lua_Evas_Object
114
{
115
   Edje_Lua_Obj obj;
116
   Evas_Object *evas_obj;
117
   int          x, y;
118
};
119

120
struct _Edje_Lua_Map
121
{
122
   Edje_Lua_Obj obj;
123
   Evas_Map    *map;
124
};
125

126
static void      _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base);
127
static Eina_Bool _elua_isa(Edje_Lua_Obj *obj, const char *type);
128

129
//--------------------------------------------------------------------------//
130
#ifndef RASTER_FORGOT_WHY
131
static lua_State *lstate = NULL;
132
#endif
133
static const char *_elua_key = "key";
134
static const char *_elua_objs = "objs";
135
/* This is not needed, pcalls don't longjmp(), that's why they are protected.
136
   static jmp_buf panic_jmp;
137
 */
138
static int panics = 0;
139
static int _log_domain = -1;
140
static int _log_count = 0;
141

142
// FIXME: methods lua script can provide that edje will call (not done yet):
143
// // scale set
144
// // key down
145
// // key up
146
// // get dragable pos
147
// // set dragable pos
148
// // set drag size, step, page
149
// // get drag size, step, page
150
// // dragable step
151
// // dragable page
152
// // get part text
153
// // set part text
154
// // get swallow part
155
// // set swallow part
156
// // unswallow part
157
// // textclass change
158
// // colorclass change
159
// // min size get <- ?? maybe set fn
160
// // max size get <- ?? maybe set fn
161
// // min size caclc (min/max restriction)
162
// // preload
163
// // preload cancel
164
// // play set
165
// // animation set
166
// // parts extends calc
167
// // part object get
168
// // part geometry get
169
//
170
// // LATER: all the entry calls
171
// // LATER: box and table calls
172
// // LATER: perspective stuff change
173
//
174

175
// Grumble, pre-declare these.
176
static const char *_elua_edje_meta = "edje_meta";
177
static const char *_elua_evas_meta = "evas_meta";
178
static const char *_elua_evas_edje_meta = "evas_edje_meta";
179
static const char *_elua_evas_image_meta = "evas_image_meta";
180
static const char *_elua_evas_line_meta = "evas_line_meta";
181
static const char *_elua_evas_map_meta = "evas_map_meta";
182
static const char *_elua_evas_polygon_meta = "evas_polygon_meta";
183
static const char *_elua_evas_text_meta = "evas_text_meta";
184
static const char *_elua_ecore_animator_meta = "ecore_animator_meta";
185
static const char *_elua_ecore_timer_meta = "ecore_timer_meta";
186

187
static int _elua_obj_gc(lua_State *L);
188

189
static const struct luaL_Reg _elua_edje_gc_funcs [] =
190
{
191
   {"__gc", _elua_obj_gc},   // garbage collector func for edje objects
192

193
   {NULL, NULL}   // end
194
};
195

196
static const luaL_Reg _elua_libs[] =
197
{
198
   {"", luaopen_base},
199
//     {LUA_LOADLIBNAME, luaopen_package}, // disable this lib - don't want
200
   {LUA_TABLIBNAME, luaopen_table},
201
//     {LUA_IOLIBNAME, luaopen_io}, // disable this lib - don't want
202
//     {LUA_OSLIBNAME, luaopen_os}, // FIXME: audit os lib - maybe not provide or only provide specific calls
203
   {LUA_STRLIBNAME, luaopen_string},
204
   {LUA_MATHLIBNAME, luaopen_math},
205
//     {LUA_DBLIBNAME, luaopen_debug}, // disable this lib - don't want
206

207
   {NULL, NULL}   // end
208
};
209

210
//--------------------------------------------------------------------------//
211
static void *
212
_elua_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
213
{
214
   size_t dif;
215
   Edje_Lua_Allocator *al = ud;
216
   Edje_Lua_Alloc *ela = al->ela;
217

218
   // in lua 5.2 osize encodes the type of data allocted if ptr is NULL
219
   // LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, or LUA_TTHREAD
220
   if (ptr == NULL) osize = 0;
221

222
   if (nsize > osize)
223
     {
224
        dif = nsize - osize;
225
        ela->cur += dif;
226
     }
227
   else
228
     {
229
        dif = osize - nsize;
230
        if (ela->cur < dif)
231
          {
232
             ERR("Lua allloc cur size %i < diff %i\n", (int)ela->cur, (int)dif);
233
             dif = ela->cur;
234
          }
235
        ela->cur -= dif;
236
     }
237

238
   if (ela->cur > ela->max)
239
     {
240
        ERR("Lua memory limit of %i bytes reached (%i allocated)",
241
            (int)ela->max, (int)ela->cur);
242
        return NULL;
243
     }
244

245
   ptr = al->func(al->ud, ptr, osize, nsize);
246
   if (nsize == 0 || ptr) return ptr;
247

248
   ERR("Lua cannot re-allocate %i bytes", (int)nsize);
249
   return NULL;
250
}
251

252
static int
253
_elua_custom_panic(lua_State *L) // Stack usage [-0, +0, m]
254
{
255
   // If we somehow manage to have multiple panics, it's likely due to being out
256
   // of memory in the following lua_tostring() call.
257
   panics++;
258
   if (panics)
259
     {
260
        EINA_LOG_DOM_CRIT(_edje_default_log_dom, "Lua PANICS!!!!!");
261
     }
262
   else
263
     {
264
        EINA_LOG_DOM_CRIT(_edje_default_log_dom,
265
                          "Lua PANIC!!!!!: %s", lua_tostring(L, -1)); // Stack usage [-0, +0, m]
266
     }
267
   // The docs say that this will cause an exit(EXIT_FAILURE) if we return,
268
   // and that we we should long jump some where to avoid that.  This is only
269
   // called for things not called from a protected environment.  We always
270
   // use pcalls though, except for the library load calls.  If we can't load
271
   // the standard libraries, then perhaps a crash is the right thing.
272
   return 0;
273
}
274

275
// Really only used to manage the pointer to our edje.
276
static void
277
_elua_table_ptr_set(lua_State *L, const void *key, const void *val)  // Stack usage [-2, +2, e]
278
{
279
   lua_pushlightuserdata(L, (void *)key);  // Stack usage [-0, +1, -]
280
   lua_pushlightuserdata(L, (void *)val);  // Stack usage [-0, +1, -]
281
   lua_settable(L, LUA_REGISTRYINDEX);     // Stack usage [-2, +0, e]
282
}
283

284
static const void *
285
_elua_table_ptr_get(lua_State *L, const void *key)  // Stack usage [-2, +2, e]
286
{
287
   const void *ptr;
288
   lua_pushlightuserdata(L, (void *)key);  // Stack usage [-0, +1, -]
289
   lua_gettable(L, LUA_REGISTRYINDEX);     // Stack usage [-1, +1, e]
290
   ptr = lua_topointer(L, -1); // Stack usage [-0, +0, -]
291
   lua_pop(L, 1); // Stack usage [-n, +0, -]
292
   return ptr;
293
}
294

295
/* XXX: not used
296
   static void
297
   _elua_table_ptr_del(lua_State *L, const void *key)  // Stack usage [-2, +2, e]
298
   {
299
   lua_pushlightuserdata(L, (void *)key);  // Stack usage [-0, +1, -]
300
   lua_pushnil(L);                         // Stack usage [-0, +1, -]
301
   lua_settable(L, LUA_REGISTRYINDEX);     // Stack usage [-2, +0, e]
302
   }
303
 */
304

305
/*
306
 * Cori: Assumes object to be saved on top of stack
307
 */
308
static void
309
_elua_ref_set(lua_State *L, void *key)     // Stack usage [-4, +4, m]
310
{
311
   lua_pushlightuserdata(L, &_elua_objs);  // Stack usage [-0, +1, -]
312
   lua_rawget(L, LUA_REGISTRYINDEX); // Stack usage [-1, +1, -]
313
   lua_pushlightuserdata(L, key); // Stack usage [-0, +1, -]
314
   lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
315
   lua_rawset(L, -3); // Stack usage [-2, +0, m]
316
   lua_pop(L, 1); // Stack usage [-n, +0, -]
317
}
318

319
/*
320
 * Cori: Get an object from the object table
321
 */
322
static void *
323
_elua_ref_get(lua_State *L, void *key)     // Stack usage [-3, +4, -]
324
{
325
   lua_pushlightuserdata(L, &_elua_objs);  // Stack usage [-0, +1, -]
326
   lua_rawget(L, LUA_REGISTRYINDEX); // Stack usage [-1, +1, -]
327
   lua_pushlightuserdata(L, key); // Stack usage [-0, +1, -]
328
   lua_rawget(L, -2); // Stack usage [-1, +1, -]
329
   lua_remove(L, -2); // Stack usage [-1, +0, -]
330
   return lua_touserdata(L, -2); // Stack usage [-0, +0, -]
331
}
332

333
static Edje_Lua_Obj *
334
_elua_obj_new(lua_State *L, Edje *ed, int size, const char *metatable)  // Stack usage [-5, +6, m]
335
{
336
   Edje_Lua_Obj *obj;
337

338
   obj = (Edje_Lua_Obj *)lua_newuserdata(L, size);  // Stack usage [-0, +1, m]
339
   memset(obj, 0, size);
340
   ed->lua_objs = eina_inlist_append(ed->lua_objs, EINA_INLIST_GET(obj));
341

342
   luaL_getmetatable(L, metatable); // Stack usage [-0, +1, -]
343
   lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
344
   obj->ed = ed;
345
   obj->meta = metatable;
346

347
   _elua_ref_set(L, obj); // Stack usage [-4, +4, m]
348
   return obj;
349
}
350

351
static void
352
_elua_obj_free(lua_State *L, Edje_Lua_Obj *obj)
353
{
354
   if (!obj->free_func) return;
355
   // Free the reference, so it will actually get gc'd.
356
   // It seems that being a completely weak table isn't enough.
357
   lua_pushnil(L); // Stack usage [-0, +1, -]
358
   _elua_ref_set(L, obj); // Stack usage [-4, +4, m]
359
   obj->free_func(obj);
360
   obj->ed->lua_objs = eina_inlist_remove(obj->ed->lua_objs, EINA_INLIST_GET(obj));
361
   obj->free_func = NULL;
362
   obj->ed = NULL;
363
}
364

365
static int
366
_elua_obj_gc(lua_State *L)  // Stack usage [-0, +0, -]
367
{
368
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);  // Stack usage [-0, +0, -]
369
   if (!obj) return 0;
370
   _elua_obj_free(L, obj);
371
   return 0;
372
}
373

374
static int
375
_elua_obj_del(lua_State *L)  // Stack usage [-0, +0, -]
376
{
377
   return _elua_obj_gc(L);   // Stack usage [-0, +0, -]
378
}
379

380
static void
381
_elua_gc(lua_State *L)  // Stack usage [-0, +0, e]
382
{
383
   lua_gc(L, LUA_GCCOLLECT, 0);  // Stack usage [-0, +0, e]
384
}
385

386
// These are what the various symbols are for each type -
387
//  int      %
388
//  num      #
389
//  str      $
390
//  bool     !
391
// FIXME: Still to do, if we ever use them -
392
//  func     &
393
//  userdata +
394
//  lightuserdata *
395
//  table    @
396
//  thread   ^
397
//  nil      ~
398

399
static char *
400
_elua_push_name(lua_State *L, char *q, int idx)  // Stack usage [-0, +1, e or m]
401
{
402
   char *p = q;
403
   char temp = '\0';
404

405
   // A simplistic scan through an identifier, it's wrong, but it's quick,
406
   // and we don't mind that it's wrong, coz this is only internal.
407
   while (isalnum((int)*q))
408
     q++;
409
   temp = *q;
410
   *q = '\0';
411
   if (idx > 0)
412
     lua_getfield(L, idx, p);  // Stack usage [-0, +1, e]
413
   else
414
     lua_pushstring(L, p);  // Stack usage [-0, +1, m]
415
   *q = temp;
416

417
   return q;
418
}
419

420
static int
421
_elua_scan_params(lua_State *L, int i, char *params, ...) // Stack usage -
422
                                                                         // if i is a table
423
     //   [-n, +n, e]
424
                                                                         // else
425
     //   [-0, +0, -]
426
{
427
   va_list vl;
428
   char *f = strdup(params);
429
   char *p = f;
430
   int n = 0, j = i, count = 0;
431
   Eina_Bool table = EINA_FALSE;
432

433
   if (!f) return -1;
434
   va_start(vl, params);
435

436
   if (lua_istable(L, i)) // Stack usage [-0, +0, -]
437
     {
438
        j = -1;
439
        table = EINA_TRUE;
440
     }
441

442
   while (*p)
443
     {
444
        char *q;
445
        Eina_Bool get = EINA_TRUE;
446

447
        while (isspace((int)*p))
448
          p++;
449
        q = p + 1;
450
        switch (*p)
451
          {
452
           case '%':
453
           {
454
              if (table)
455
                {
456
                   q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
457
                }
458
              if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
459
                {
460
                   int *v = va_arg(vl, int *);
461
                   *v = lua_tointeger(L, j); // Stack usage [-0, +0, -]
462
                   n++;
463
                }
464
              break;
465
           }
466

467
           case '#':
468
           {
469
              if (table)
470
                {
471
                   q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
472
                }
473
              if (lua_isnumber(L, j)) // Stack usage [-0, +0, -]
474
                {
475
                   double *v = va_arg(vl, double *);
476
                   *v = lua_tonumber(L, j); // Stack usage [-0, +0, -]
477
                   n++;
478
                }
479
              break;
480
           }
481

482
           case '$':
483
           {
484
              if (table)
485
                {
486
                   q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
487
                }
488
              if (lua_isstring(L, j)) // Stack usage [-0, +0, -]
489
                {
490
                   char **v = va_arg(vl, char **);
491
                   size_t len;
492
                   char *temp = (char *)lua_tolstring(L, j, &len);       // Stack usage [-0, +0, m]
493

494
                   if (temp)
495
                     {
496
                       len++;      // Cater for the null at the end.
497
                       *v = malloc(len);
498
                       if (*v)
499
                         {
500
                            memcpy(*v, temp, len);
501
                            n++;
502
                         }
503
                     }
504
                }
505
              break;
506
           }
507

508
           case '!':
509
           {
510
              if (table)
511
                {
512
                   q = _elua_push_name(L, q, i); // Stack usage [-0, +1, e]
513
                }
514
              if (lua_isboolean(L, j)) // Stack usage [-0, +0, -]
515
                {
516
                   int *v = va_arg(vl, int *);
517
                   *v = lua_toboolean(L, j); // Stack usage [-0, +0, -]
518
                   n++;
519
                }
520
              break;
521
           }
522

523
           default:
524
           {
525
              get = EINA_FALSE;
526
              break;
527
           }
528
          }
529

530
        if (get)
531
          {
532
             if (table)
533
               {
534
                  // If this is a table, then we pushed a value on the stack, pop it off.
535
                  lua_pop(L, 1); // Stack usage [-n, +0, -]
536
               }
537
             else
538
               j++;
539
             count++;
540
          }
541
        p = q;
542
     }
543

544
   free(f);
545
   va_end(vl);
546
   if (count > n)
547
     n = 0;
548
   else if (table)
549
     n = 1;
550
   return n;
551
}
552

553
static int
554
_elua_ret(lua_State *L, char *params, ...) // Stack usage [-(2*n), +(2*n+1), em]
555
{
556
   va_list vl;
557
   char *f = strdup(params);
558
   char *p = f;
559
   int n = 0;
560

561
   if (!f) return -1;
562

563
   lua_newtable(L); // Stack usage [-0, +1, m]
564
   va_start(vl, params);
565

566
   while (*p)
567
     {
568
        char *q;
569
        Eina_Bool set = EINA_TRUE;
570

571
        while (isspace((int)*p))
572
          p++;
573
        q = p + 1;
574
        switch (*p)
575
          {
576
           case '%':
577
           {
578
              q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
579
              lua_pushinteger(L, va_arg(vl, int));        // Stack usage [-0, +1, -]
580
              break;
581
           }
582

583
           case '#':
584
           {
585
              q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
586
              lua_pushnumber(L, va_arg(vl, double));      // Stack usage [-0, +1, -]
587
              break;
588
           }
589

590
           case '$':
591
           {
592
              q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
593
              lua_pushstring(L, va_arg(vl, char *));      // Stack usage [-0, +1, m]
594
              break;
595
           }
596

597
           case '!':
598
           {
599
              q = _elua_push_name(L, q, -1); // Stack usage [-0, +1, m]
600
              lua_pushboolean(L, va_arg(vl, int));        // Stack usage [-0, +1, -]
601
              break;
602
           }
603

604
           default:
605
           {
606
              set = EINA_FALSE;
607
              break;
608
           }
609
          }
610

611
        if (set)
612
          {
613
             lua_settable(L, -3); // Stack usage [-2, +0, e]
614
             n++;
615
          }
616
        p = q;
617
     }
618

619
   free(f);
620
   va_end(vl);
621
   return n;
622
}
623

624
static void
625
_elua_color_fix(int *r, int *g, int *b, int *a)
626
{
627
   if (*r > *a) *r = *a;
628
   if (*g > *a) *g = *a;
629
   if (*b > *a) *b = *a;
630
}
631

632
//--------------------------------------------------------------------------//
633

634
/**
635
   @page luaref
636
   @subsection edje Edje class.
637

638
   The lua edje class includes functions for dealing with the lua script only group
639
   as an edje object, basic functions, and functions to create other objects.
640

641
   In the following, "edje" is the actual global table used to access these edje functions.
642
 */
643

644
static int _elua_echo(lua_State *L);
645

646
static int _elua_date(lua_State *L);
647
static int _elua_looptime(lua_State *L);
648
static int _elua_seconds(lua_State *L);
649
static int _elua_version(lua_State *L);
650

651
static int _elua_objgeom(lua_State *L);
652
static int _elua_objpos(lua_State *L);
653
static int _elua_objsize(lua_State *L);
654

655
static int _elua_emit(lua_State *L);
656
static int _elua_messagesend(lua_State *L);
657

658
static int _elua_animator(lua_State *L);
659
static int _elua_timer(lua_State *L);
660
static int _elua_transition(lua_State *L);
661

662
static int _elua_color_class(lua_State *L);
663
static int _elua_text_class(lua_State *L);
664

665
static int _elua_edje(lua_State *L);
666
static int _elua_image(lua_State *L);
667
static int _elua_line(lua_State *L);
668
static int _elua_map(lua_State *L);
669
static int _elua_polygon(lua_State *L);
670
static int _elua_rect(lua_State *L);
671
static int _elua_text(lua_State *L);
672
//static int _elua_textblock(lua_State *L);  /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
673

674
static const char *_elua_edje_api = "edje";
675
static const struct luaL_Reg _elua_edje_funcs [] =
676
{
677
   // add an echo too to make it more shelly
678
   {"echo", _elua_echo},           // test func - echo (i know we have print. test)
679
   // FIXME: add logging functions here, probably to it's own domain, or even a script defined domain.
680

681
   // system information (time, date blah blah)
682
   {"date", _elua_date},           // get date in a table
683
   {"looptime", _elua_looptime},       // get loop time
684
   {"seconds", _elua_seconds},        // get seconds
685
   {"version", _elua_version},        // edje version
686

687
   // query edje - size, pos
688
   {"geom", _elua_objgeom},           // get while edje object geometry in canvas
689
   {"pos", _elua_objpos},            // get while edje object pos in canvas
690
   {"size", _elua_objsize},           // get while edje object pos in canvas
691

692
   // talk to application/caller
693
   {"emit", _elua_emit},           // emit signal + src
694
   {"messagesend", _elua_messagesend},    // send a structured message
695

696
   // time based "callback" systems
697
   {"animator", _elua_animator},       // add animator
698
   {"timer", _elua_timer},          // add timer
699
   {"transition", _elua_transition},     // add transition
700
   // FIXME: need poller
701

702
   // set and query color / text class
703
   {"color_class", _elua_color_class},
704
   {"text_class", _elua_text_class},
705

706
   // create new objects
707
   {"edje", _elua_edje},
708
   {"image", _elua_image},           // defaults to a filled image.
709
   {"line", _elua_line},
710
   {"map", _elua_map},
711
   {"polygon", _elua_polygon},
712
   {"rect", _elua_rect},
713
   {"text", _elua_text},
714
//     {"textblock",    _elua_textblock},  /* XXX: disabled until there are enough textblock functions implemented to make it actually useful
715

716
   // FIXME: add the new sound stuff.
717

718
   {NULL, NULL}   // end
719
};
720

721
/**
722
   @page luaref
723
   @subsubsection edje_echo edje.echo(text)
724

725
   Make lua a bit shelly.  Prints a string to the console
726

727
   @param text The string to print.
728
 */
729
static int
730
_elua_echo(lua_State *L) // Stack usage [-0, +0, v]
731
{
732
   const char *string = luaL_checkstring(L, 1);  // Stack usage [-0, +0, v]
733
   LD("%s", string);
734
   return 0;
735
}
736

737
//-------------
738
/**
739
   @page luaref
740
   @subsubsection edje_date edje.date()
741

742
   Retrieves the current time and date.
743

744
   Wraps gettimeofday(), as passed through localtime().
745

746
   @return A table with these fields:
747
   - integer year: Year.
748
   - integer month: Month of the year.
749
   - integer day: Day of the month.
750
   - integer yearday: Day of the year.
751
   - integer weekday: Day of the week.
752
   - integer hour: Hour of the day (24 hour format).
753
   - integer min: Minute of the hour.
754
   - number sec: Seconds as a number.
755

756
 */
757
static int
758
_elua_date(lua_State *L)  // Stack usage [-16, +17, em]
759
{
760
   static time_t last_tzset = 0;
761
   struct timeval timev;
762
   struct tm *tm;
763
   time_t tt;
764

765
   gettimeofday(&timev, NULL);
766
   tt = (time_t)(timev.tv_sec);
767
   if ((tt > (last_tzset + 1)) || (tt < (last_tzset - 1)))
768
     {
769
        last_tzset = tt;
770
        tzset();
771
     }
772
   tm = localtime(&tt);
773
   if (tm) // Stack usage [-16, +17, em]
774
     {
775
        _elua_ret(L, "%year %month %day %yearday %weekday %hour %min #sec",
776
                  (int)(tm->tm_year + 1900),
777
                  (int)(tm->tm_mon + 1),
778
                  (int)(tm->tm_mday),
779
                  (int)(tm->tm_yday),
780
                  (int)((tm->tm_wday + 6) % 7),
781
                  (int)(tm->tm_hour),
782
                  (int)(tm->tm_min),
783
                  (double)((double)tm->tm_sec + (((double)timev.tv_usec) / 1000000))
784
                  );
785
     }
786
   return 1;
787
}
788

789
/**
790
   @page luaref
791
   @subsubsection edje_looptime edje.looptime()
792

793
   Retrieves the time at which the last loop stopped waiting for timeouts or events.
794

795
   This gets the time that the main loop ceased waiting for timouts and/or events
796
   to come in or for signals or any other interrupt source. This should be
797
   considered a reference point for all time based activity that should calculate
798
   its timepoint from the return of edje.looptime(). Use this UNLESS you absolutely
799
   must get the current actual timepoint - then use edje.seconds(). Note that this
800
   time is meant to be used as relative to other times obtained on this run.
801

802
   Wraps ecore_loop_time_get().
803

804
   @returns A number of seconds.
805
 */
806
static int
807
_elua_looptime(lua_State *L)  // Stack usage [-0, +1, -]
808
{
809
   double t = ecore_loop_time_get();
810
   lua_pushnumber(L, t); // Stack usage [-0, +1, -]
811
   return 1;
812
}
813

814
/**
815
   @page luaref
816
   @subsubsection edje_seconds edje.seconds()
817

818
   Retrieves the current system time as a floating point value in seconds.
819

820
   This uses a monotonic clock and thus never goes back in time while machine is
821
   live (even if user changes time or timezone changes, however it may be reset
822
   whenever the machine is restarted).
823

824
   Wraps ecore_time_get().
825

826
   @returns A number of seconds.
827
 */
828
static int
829
_elua_seconds(lua_State *L)  // Stack usage [-0, +1, -]
830
{
831
   double t = ecore_time_get();
832
   lua_pushnumber(L, t);     // Stack usage [-0, +1, -]
833
   return 1;
834
}
835

836
/**
837
   @page luaref
838
   @subsubsection edje_version edje.version()
839

840
   Retrieves the current edje version number.
841

842
   @returns A table with these fields:
843
    - integer major: The edje version major number.
844
    - integer minor: The edje version minor number.
845

846
   @since 1.2.0
847
 */
848
static int
849
_elua_version(lua_State *L) // Stack usage [-4, +5, em]
850
{
851
   _elua_ret(L, "%major %minor", EDJE_VERSION_MAJOR, EDJE_VERSION_MINOR);  // Stack usage [-4, +5, em]
852
   return 1;
853
}
854

855
//-------------
856
/**
857
   @page luaref
858
   @subsubsection edje_geom edje.geom()
859

860
   Retrieves the position and size of the edje object that this lua group is in.
861

862
   @returns A table with these fields:
863
   - integer x: The edjes X position.
864
   - integer y: The edjes Y position.
865
   - integer w: The edjes width.
866
   - integer h: The edjes height.
867
 */
868
static int
869
_elua_objgeom(lua_State *L) // Stack usage [-10, +11, em]
870
{
871
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
872
   _elua_ret(L, "%x %y %w %h", ed->x, ed->y, ed->w, ed->h);  // Stack usage [-8, +9, em]
873
   return 1;
874
}
875

876
/**
877
   @page luaref
878
   @subsubsection edje_pos edje.pos()
879

880

881
   Retrieves the position of the edje object that this lua group is in.
882

883
   @returns A table with these fields:
884
   - integer x: The edjes X position.
885
   - integer y: The edjes Y position.
886
 */
887
static int
888
_elua_objpos(lua_State *L) // Stack usage [-6, +7, em]
889
{
890
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
891
   _elua_ret(L, "%x %y", ed->x, ed->y); // Stack usage [-4, +5, em]
892
   return 1;
893
}
894

895
/**
896
   @page luaref
897
   @subsubsection edje_size edje.size()
898

899

900
   Retrieves the size of the edje object that this lua group is in.
901

902
   @returns A table with these fields:
903
   - integer w: The edjes width.
904
   - integer h: The edjes height.
905
 */
906
static int
907
_elua_objsize(lua_State *L) // Stack usage [-6, +7, em]
908
{
909
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
910
   _elua_ret(L, "%w %h", ed->w, ed->h); // Stack usage [-4, +5, em]
911
   return 1;
912
}
913

914
//-------------
915
/**
916
   @page luaref
917
   @subsubsection edje_emit edje.emit(signal, source)
918

919
   Emit a signal.
920

921
   Wraps edje_object_signal_emit().
922

923
   @param signal The signal string to send.
924
   @param source The source string of the signal.
925

926
   NOTE: The source string will have a name and a colon prepended to in when it is
927
   delivered to things that are not this edje, like C and other edje groups.
928
   If this edje is a top level edje, then it will be the name of the group (I think).
929
   If this edje is swallowed into some other part, then it will be the name of the
930
   part:
931

932
   group_name:source
933

934
   FIXME: I actually have no idea what happens if it's swallowed into another lua
935
   edje group.
936
 */
937
static int
938
_elua_emit(lua_State *L) // Stack usage [-2, +2, ev]
939
{
940
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
941
   const char *sig = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
942
   const char *src = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
943
   if ((!sig) || (!src)) return 0;
944
   _edje_emit(ed, sig, src);
945
   return 0;
946
}
947

948
/**
949
   @page luaref
950
   @subsubsection edje_message_send edje.messagesend(id, type, ...)
951

952
   Send a message to this edje, and all it's child objects.
953

954
   Wraps edje_object_message_send().
955

956
   @param id   An identification integer for the message.
957
   @param type The type of message to send.
958
   @param ...  Zero or more things to send as part of the message, depending on the type.
959

960
   The type can be one of:
961
   - none: No msg.
962
   - sig: The msg is two strings (signal, source), sent as a signal.
963
   - str: The msg is a C string.
964
   - int: The message is a C integer.
965
   - float: The message is a C float.
966
   - strset: The message is an array of C strings.
967
   - intset: The message is an array of C integers.
968
   - floatset: The message is an array of C floats.
969
   - strint: The message is a C stnring and a C integer.
970
   - strfloat: The message is a C string and a C float.
971
   - strintset: The message is a C string and an array of C integers.
972
   - strfloatset: The message is a G string and an array of C floats.
973

974
   For the array types, the lua caller passes a table.
975
 */
976
static int
977
_elua_messagesend(lua_State *L)  // Stack usage [-2, +2, ev] plus [-2, +2] for every element if it's an array message.
978
{
979
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
980
   int id = luaL_checkinteger(L, 1); // Stack usage [-0, +0, v]
981
   const char *type = luaL_checkstring(L, 2); // Stack usage [-0, +0, v]
982
   if (!type) return 0;
983
   if (!strcmp(type, "none"))
984
     {
985
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_NONE, id, NULL);
986
     }
987
   else if (!strcmp(type, "sig"))
988
     {
989
        const char *sig = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
990
        const char *src = luaL_checkstring(L, 4); // Stack usage [-0, +0, v]
991
        _edje_emit(ed, sig, src);
992
     }
993
   else if (!strcmp(type, "str"))
994
     {
995
        Edje_Message_String *emsg;
996
        const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
997
        emsg = alloca(sizeof(Edje_Message_String));
998
        emsg->str = (char *)str;
999
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING, id, emsg);
1000
     }
1001
   else if (!strcmp(type, "int"))
1002
     {
1003
        Edje_Message_Int *emsg;
1004
        int val = luaL_checkinteger(L, 3); // Stack usage [-0, +0, v]
1005
        emsg = alloca(sizeof(Edje_Message_Int));
1006
        emsg->val = val;
1007
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT, id, emsg);
1008
     }
1009
   else if (!strcmp(type, "float"))
1010
     {
1011
        Edje_Message_Float *emsg;
1012
        float val = luaL_checknumber(L, 3); // Stack usage [-0, +0, v]
1013
        emsg = alloca(sizeof(Edje_Message_Float));
1014
        emsg->val = val;
1015
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT, id, emsg);
1016
     }
1017
   else if (!strcmp(type, "strset"))
1018
     {
1019
        Edje_Message_String_Set *emsg;
1020
        int i, n;
1021
        const char *str;
1022
        luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1023
#if LUA_VERSION_NUM >= 502
1024
        n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
1025
#else
1026
        n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1027
#endif
1028
        emsg = alloca(sizeof(Edje_Message_String_Set) + ((n - 1) * sizeof(char *)));
1029
        emsg->count = n;
1030
        for (i = 1; i <= n; i++)
1031
          {
1032
             lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1033
             lua_gettable(L, 3); // Stack usage [-1, +1, e]
1034
             str = lua_tostring(L, -1); // Stack usage [-0, +0, m]
1035
             lua_pop(L, 1); // Stack usage [-n, +0, -]
1036
             emsg->str[i - 1] = (char *)str;
1037
          }
1038
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_SET, id, emsg);
1039
     }
1040
   else if (!strcmp(type, "intset"))
1041
     {
1042
        Edje_Message_Int_Set *emsg;
1043
        int i, n;
1044
        luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1045
#if LUA_VERSION_NUM >= 502
1046
        n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
1047
#else
1048
        n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1049
#endif
1050
        emsg = alloca(sizeof(Edje_Message_Int_Set) + ((n - 1) * sizeof(int)));
1051
        emsg->count = n;
1052
        for (i = 1; i <= n; i++)
1053
          {
1054
             lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1055
             lua_gettable(L, 3); // Stack usage [-1, +1, e]
1056
             emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -]
1057
             lua_pop(L, 1); // Stack usage [-n, +0, -]
1058
          }
1059
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_INT_SET, id, emsg);
1060
     }
1061
   else if (!strcmp(type, "floatset"))
1062
     {
1063
        Edje_Message_Float_Set *emsg;
1064
        int i, n;
1065
        luaL_checktype(L, 3, LUA_TTABLE); // Stack usage [-0, +0, v]
1066
#if LUA_VERSION_NUM >= 502
1067
        n = lua_rawlen(L, 3); // Stack usage [-0, +0, -]
1068
#else
1069
        n = lua_objlen(L, 3); // Stack usage [-0, +0, -]
1070
#endif
1071
        emsg = alloca(sizeof(Edje_Message_Float_Set) + ((n - 1) * sizeof(double)));
1072
        emsg->count = n;
1073
        for (i = 1; i <= n; i++)
1074
          {
1075
             lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1076
             lua_gettable(L, 3); // Stack usage [-1, +1, e]
1077
             emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1078
             lua_pop(L, 1); // Stack usage [-n, +0, -]
1079
          }
1080
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_FLOAT_SET, id, emsg);
1081
     }
1082
   else if (!strcmp(type, "strint"))
1083
     {
1084
        Edje_Message_String_Int *emsg;
1085
        const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1086
        emsg = alloca(sizeof(Edje_Message_String_Int));
1087
        emsg->str = (char *)str;
1088
        emsg->val = luaL_checkinteger(L, 4); // Stack usage [-0, +0, v]
1089
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT, id, emsg);
1090
     }
1091
   else if (!strcmp(type, "strfloat"))
1092
     {
1093
        Edje_Message_String_Float *emsg;
1094
        const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1095
        emsg = alloca(sizeof(Edje_Message_String_Float));
1096
        emsg->str = (char *)str;
1097
        emsg->val = luaL_checknumber(L, 4); // Stack usage [-0, +0, v]
1098
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT, id, emsg);
1099
     }
1100
   else if (!strcmp(type, "strintset"))
1101
     {
1102
        Edje_Message_String_Int_Set *emsg;
1103
        int i, n;
1104
        const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1105
        if (!str) return 0;
1106
        luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1107
#if LUA_VERSION_NUM >= 502
1108
        n = lua_rawlen(L, 4); // Stack usage [-0, +0, -]
1109
#else
1110
        n = lua_objlen(L, 4); // Stack usage [-0, +0, -]
1111
#endif
1112
        emsg = alloca(sizeof(Edje_Message_String_Int_Set) + ((n - 1) * sizeof(int)));
1113
        emsg->str = (char *)str;
1114
        emsg->count = n;
1115
        for (i = 1; i <= n; i++)
1116
          {
1117
             lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1118
             lua_gettable(L, 4); // Stack usage [-1, +1, e]
1119
             emsg->val[i - 1] = lua_tointeger(L, -1); // Stack usage [-0, +0, -]
1120
             lua_pop(L, 1); // Stack usage [-n, +0, -]
1121
          }
1122
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_INT_SET, id, emsg);
1123
     }
1124
   else if (!strcmp(type, "strfloatset"))
1125
     {
1126
        Edje_Message_String_Float_Set *emsg;
1127
        int i, n;
1128
        const char *str = luaL_checkstring(L, 3); // Stack usage [-0, +0, v]
1129
        if (!str) return 0;
1130
        luaL_checktype(L, 4, LUA_TTABLE); // Stack usage [-0, +0, v]
1131
#if LUA_VERSION_NUM >= 502
1132
        n = lua_rawlen(L, 4); // Stack usage [-0, +0, -]
1133
#else
1134
        n = lua_objlen(L, 4);
1135
#endif
1136
        emsg = alloca(sizeof(Edje_Message_String_Float_Set) + ((n - 1) * sizeof(double)));
1137
        emsg->str = (char *)str;
1138
        emsg->count = n;
1139
        for (i = 1; i <= n; i++)
1140
          {
1141
             lua_pushinteger(L, i); // Stack usage [-0, +1, -]
1142
             lua_gettable(L, 4); // Stack usage [-1, +1, e]
1143
             emsg->val[i - 1] = lua_tonumber(L, -1); // Stack usage [-0, +0, -]
1144
             lua_pop(L, 1); // Stack usage [-n, +0, -]
1145
          }
1146
        _edje_util_message_send(ed, EDJE_QUEUE_APP, EDJE_MESSAGE_STRING_FLOAT_SET, id, emsg);
1147
     }
1148
   return 0;
1149
}
1150

1151
//-------------
1152
static Eina_Bool
1153
_elua_animator_cb(void *data) // Stack usage [-2, +2, em]
1154
{
1155
   Edje_Lua_Animator *ela = data;
1156
   lua_State *L;
1157
   int ret = 0, err = 0;
1158

1159
   if (!ela->obj.ed) return 0;
1160
   L = ela->obj.ed->L;
1161
   if (!L) return 0;
1162
   /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1163
      if (setjmp(panic_jmp) == 1)
1164
      {
1165
        LE("Animator callback panic");
1166
        _edje_lua2_error(L, err);                            // Stack usage [-0, +0, m]
1167
        _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1168
        _elua_gc(L);                                         // Stack usage [-0, +0, e]
1169
        return 0;
1170
      }
1171
    */
1172
   lua_rawgeti(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +1, -]
1173
   if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1174
     {
1175
        _edje_lua2_error(L, err); // Stack usage [-0, +0, m]
1176
        _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1177
        _elua_gc(L); // Stack usage [-0, +0, e]
1178
        return 0;
1179
     }
1180
   ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1181
   lua_pop(L, 1); // Stack usage [-n, +0, -]
1182
   if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)ela);
1183
   _elua_gc(L); // Stack usage [-0, +0, e]
1184
   return ret;
1185
}
1186

1187
static void
1188
_elua_animator_free(void *obj) // Stack usage [-0, +0, -]
1189
{
1190
   Edje_Lua_Animator *ela = obj;
1191
   lua_State *L;
1192
   if (!ela->obj.ed) return;
1193
   L = ela->obj.ed->L;
1194
   luaL_unref(L, LUA_REGISTRYINDEX, ela->fn_ref); // Stack usage [-0, +0, -]
1195
   ela->fn_ref = 0;
1196
   ecore_animator_del(ela->animator);
1197
   ela->animator = NULL;
1198
}
1199

1200
/**
1201
   @page luaref
1202
   @subsubsection edje_animator edje.animator(func)
1203

1204
   This function adds an animator and returns its handle on success and NULL on
1205
   failure. The function func will be called every frame tick.  Note that setting
1206
   the frame tick is not available as a lua function, so has to be done from C.
1207
   The default tick is 1/30 second.
1208

1209
   When the animator func is called, it must return a value of either true or false.
1210
   If it returns true it will be called again at the next tick, or if it returns
1211
   false it will be deleted automatically making any references/handles for it
1212
   invalid.
1213

1214
   Wraps ecore_animator_add().
1215

1216
   @param func The function to call when the animator triggers.
1217

1218
   @returns A userdata that is an ecore animator.
1219
 */
1220
static int
1221
_elua_animator(lua_State *L) // Stack usage [-8, +9, emv]
1222
{
1223
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
1224
   Edje_Lua_Animator *ela;
1225

1226
   luaL_checkany(L, 1); // Stack usage [-0, +0, v]
1227

1228
   // FIXME: Allow lua to set a data to be sent back with the callback.
1229
   ela = (Edje_Lua_Animator *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Animator), _elua_ecore_animator_meta);
1230
   // Stack usage [-5, +6, m]
1231
   ela->obj.free_func = _elua_animator_free;
1232
   ela->animator = ecore_animator_add(_elua_animator_cb, ela);
1233
   lua_pushvalue(L, 1); // Stack usage [-0, +1, -]
1234
   ela->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1235
   _elua_gc(L); // Stack usage [-0, +0, e]
1236
   return 1;
1237
}
1238

1239
static Eina_Bool
1240
_elua_timer_cb(void *data) // Stack usage [-2, +2, em]
1241
{
1242
   Edje_Lua_Timer *elt = data;
1243
   lua_State *L;
1244
   int ret = 0, err = 0;
1245

1246
   if (!elt->obj.ed) return 0;
1247
   L = elt->obj.ed->L;
1248
   if (!L) return 0;
1249
   /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1250
      if (setjmp(panic_jmp) == 1)
1251
      {
1252
        LE("Timer callback panic");
1253
        _edje_lua2_error(L, err);                            // Stack usage [-0, +0, m]
1254
        _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1255
        _elua_gc(L);                                         // Stack usage [-0, +0, e]
1256
        return 0;
1257
      }
1258
    */
1259
   lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1260
   if ((err = lua_pcall(L, 0, 1, 0))) // Stack usage [-1, +1, -]
1261
     {
1262
        _edje_lua2_error(L, err);
1263
        _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1264
        _elua_gc(L); // Stack usage [-0, +0, e]
1265
        return 0;
1266
     }
1267
   ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1268
   lua_pop(L, 1); // Stack usage [-n, +0, -]
1269
   if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1270
   _elua_gc(L); // Stack usage [-0, +0, e]
1271
   return ret;
1272
}
1273

1274
static void
1275
_elua_timer_free(void *obj) // Stack usage [-0, +0, -]
1276
{
1277
   Edje_Lua_Timer *elt = obj;
1278
   lua_State *L;
1279
   if (!elt->obj.ed) return;
1280
   L = elt->obj.ed->L;
1281
   luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1282
   elt->fn_ref = 0;
1283
   ecore_timer_del(elt->timer);
1284
   elt->timer = NULL;
1285
}
1286

1287
/**
1288
   @page luaref
1289
   @subsubsection edje_timer edje.timer(tick, func)
1290

1291
   This function adds a timer and returns its handle on success and NULL on failure.
1292
   The function func will be called every tick seconds.
1293

1294
   When the timer func is called, it must return a value of either true or false.
1295
   If it returns true, it will be called again at the next tick, or if it returns
1296
   false it will be deleted automatically making any references/handles for it
1297
   invalid.
1298

1299
   Wraps ecore_timer_add().
1300

1301
   @param tick How often, in seconds, to call the function.
1302
   @param func The function to call when the timer triggers.
1303

1304
   @returns A userdata that is an ecore timer.
1305
 */
1306
static int
1307
_elua_timer(lua_State *L) // Stack usage [-8, +9, emv]
1308
{
1309
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
1310
   Edje_Lua_Timer *elt;
1311
   double val;
1312

1313
   val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1314
   luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1315

1316
   elt = (Edje_Lua_Timer *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Timer), _elua_ecore_timer_meta);
1317
   // Stack usage [-5, +6, m]
1318
   elt->obj.free_func = _elua_timer_free;
1319
   elt->timer = ecore_timer_add(val, _elua_timer_cb, elt);
1320
   lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1321
   elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1322
   _elua_gc(L); // Stack usage [-0, +0, e]
1323
   return 1;
1324
}
1325

1326
static Eina_Bool
1327
_elua_transition_cb(void *data) // Stack usage [-3, +3, em]
1328
{
1329
   Edje_Lua_Transition *elt = data;
1330
   lua_State *L;
1331
   int ret = 0, err = 0;
1332
   double t;
1333

1334
   if (!elt->obj.ed) return 0;
1335
   L = elt->obj.ed->L;
1336
   if (!L) return 0;
1337
   t = (ecore_loop_time_get() - elt->start) / elt->transition;
1338
   if (t > 1.0) t = 1.0;
1339
   /* This is not needed, pcalls don't longjmp(), that's why they are protected.
1340
      if (setjmp(panic_jmp) == 1)
1341
      {
1342
        LE("Transition callback panic");
1343
        _edje_lua2_error(L, err);                            // Stack usage [-0, +0, m]
1344
        _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1345
        _elua_gc(L);                                         // Stack usage [-0, +0, e]
1346
        return 0;
1347
      }
1348
    */
1349
   lua_rawgeti(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +1, -]
1350
   lua_pushnumber(L, t); // Stack usage [-0, +1, -]
1351
   if ((err = lua_pcall(L, 1, 1, 0))) // Stack usage [-2, +1, -]
1352
     {
1353
        _edje_lua2_error(L, err);
1354
        _elua_obj_free(L, (Edje_Lua_Obj *)elt); // Stack usage [-0, +0, m]
1355
        _elua_gc(L); // Stack usage [-0, +0, e]
1356
        return 0;
1357
     }
1358
   ret = lua_toboolean(L, -1); // Stack usage [-0, +0, -]
1359
   lua_pop(L, 1); // Stack usage [-n, +0, -]
1360
   if (t >= 1.0) ret = 0;
1361
   if (ret == 0) _elua_obj_free(L, (Edje_Lua_Obj *)elt);
1362
   _elua_gc(L); // Stack usage [-0, +0, e]
1363
   return ret;
1364
}
1365

1366
static void
1367
_elua_transition_free(void *obj) // Stack usage [-0, +0, -]
1368
{
1369
   Edje_Lua_Transition *elt = obj;
1370
   lua_State *L;
1371
   if (!elt->obj.ed) return;
1372
   L = elt->obj.ed->L;
1373
   luaL_unref(L, LUA_REGISTRYINDEX, elt->fn_ref); // Stack usage [-0, +0, -]
1374
   elt->fn_ref = 0;
1375
   ecore_animator_del(elt->animator);
1376
   elt->animator = NULL;
1377
}
1378

1379
/**
1380
   @page luaref
1381
   @subsubsection edje_transition edje.transition(div, func)
1382

1383
   Just like edje.animator(), except that the callback function gets called with an
1384
   argument.  The argument is the amount of time since the transition was created,
1385
   divided by the div parameter.
1386

1387
   @param div A number to divide the time since creation by.
1388
   @param func The function to call when the transition triggers.
1389

1390
   @returns A userdata that is a transition (ecore animator, plus other info).
1391
 */
1392
static int
1393
_elua_transition(lua_State *L) // Stack usage [-8, +9, emv]
1394
{
1395
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
1396
   Edje_Lua_Transition *elt;
1397
   double val;
1398

1399
   val = luaL_checknumber(L, 1); // Stack usage [-0, +0, v]
1400
   luaL_checkany(L, 2); // Stack usage [-0, +0, v]
1401

1402
   elt = (Edje_Lua_Transition *)_elua_obj_new(L, ed, sizeof(Edje_Lua_Transition), _elua_ecore_animator_meta);
1403
   // Stack usage [-5, +6, m]
1404
   elt->obj.free_func = _elua_transition_free;
1405
   elt->animator = ecore_animator_add(_elua_transition_cb, elt);
1406
   if (val < 0.0000001) val = 0.0000001;
1407
   elt->transition = val;
1408
   elt->start = ecore_loop_time_get();
1409
   lua_pushvalue(L, 2); // Stack usage [-0, +1, -]
1410
   elt->fn_ref = luaL_ref(L, LUA_REGISTRYINDEX); // Stack usage [-1, +0, m]
1411
   _elua_gc(L); // Stack usage [-0, +0, e]
1412
   return 1;
1413
}
1414

1415
//-------------
1416
/**
1417
   @page luaref
1418
   @subsubsection edje_colour_class edje.color_class(class, r, g, b, a)
1419

1420
   Gets, (and optionally sets) the colours for a color class.
1421

1422
   Wraps edje_object_color_class_set().
1423

1424
   @param class A color class name.
1425
   @param r The new red value.
1426
   @param g The new green value.
1427
   @param b The new blue value.
1428
   @param a The new alpha value.
1429

1430
   Note that the r, g, b, and a arguments are optional, without them this function
1431
   just queries the current values.  The r, g, b, and a arguments can be separate
1432
   values, or named fields in a table.
1433

1434
   @return A table with these fields:
1435
   - integer r: The red value.
1436
   - integer g: The green value.
1437
   - integer b: The blue value.
1438
   - integer a: The alpha value.
1439

1440
   @since 1.1.0
1441
 */
1442
static int
1443
_elua_color_class(lua_State *L) // Stack usage [-(10|14), +(11|15), ?]
1444
{
1445
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
1446
   Edje_Color_Class *c_class;
1447
   const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1448
   int r, g, b, a;
1449

1450
   if (!class) return 0;
1451

1452
   if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
1453
     {
1454
        _elua_color_fix(&r, &g, &b, &a);
1455
        // This is the way that embryo does it -
1456
        //edje_object_color_class_set(ed->obj, class, r, g, b, a, r, g, b, a, r, g, b, a);
1457
        // But that deals with object scope, which is currently useless in lua,
1458
        // since we have no objects that can use color_class yet.
1459
        // So we do it at global scope instead.
1460
        // LATER - Should do both?
1461
        edje_color_class_set(class, r, g, b, a, r, g, b, a, r, g, b, a);
1462
     }
1463

1464
   c_class = _edje_color_class_recursive_find(ed, class);
1465
   if (!c_class) return 0;
1466

1467
   _elua_ret(L, "%r %g %b %a", c_class->r, c_class->g, c_class->b, c_class->a);
1468
   // Stack usage [-8, +9, em]
1469
   return 1;
1470
}
1471

1472
/**
1473
   @page luaref
1474
   @subsubsection edje_text_class edje.text_class(class, font, size)
1475

1476
   Gets, (and optionally sets) the details for a text class.
1477

1478
   Wraps edje_object_text_class_set().
1479

1480
   @param class A text class name.
1481
   @param font The new font name.
1482
   @param size The new font size.
1483

1484
   Note that the font and size arguments are optional, without them this function
1485
   just queries the current values.  The font and size arguments can be separate
1486
   values, or named fields in a table.  The font name can refer to a font in the
1487
   edje file, or an external font.
1488

1489
   @return A table with these fields:
1490
   - string font: The font name.
1491
   - integer size: The font size.
1492

1493
   @since 1.1.0
1494
 */
1495
static int
1496
_elua_text_class(lua_State *L) // Stack usage [-(6|8), +(7|9), emv]
1497
{
1498
   Edje *ed = (Edje *)_elua_table_ptr_get(L, _elua_key);     // Stack usage [-2, +2, e]
1499
   Edje_Text_Class *t_class;
1500
   const char *class = luaL_checkstring(L, 1); // Stack usage [-0, +0, v]
1501
   char *font = NULL;
1502
   Evas_Font_Size size = 0;
1503

1504
   if (!class) return 0;
1505

1506
   // Just like color_class above, this does things differently from embryo,
1507
   // for the same reason.
1508
   if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0)
1509
     // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
1510
     edje_text_class_set(class, font, size);
1511

1512
   t_class = _edje_text_class_find(ed, class);
1513
   if (!t_class) return 0;
1514

1515
   _elua_ret(L, "$font %size", t_class->font, t_class->size);
1516
   // Stack usage [-4, +5, em]
1517
   return 1;
1518
}
1519

1520
//-------------
1521
static void
1522
_elua_efl_canvas_object_free(void *obj)
1523
{
1524
   Edje_Lua_Evas_Object *elo = obj;
1525

1526
   if (!elo->obj.ed) return;
1527
   evas_object_del(elo->evas_obj);
1528
   elo->evas_obj = NULL;
1529
}
1530

1531
// Stack usage [-7, +8, em]
1532
#define _ELUA_PLANT_EVAS_OBJECT(type, meta, free)         \
1533
  Edje * ed = (Edje *)_elua_table_ptr_get(L, _elua_key);  \
1534
  type *elo;                                              \
1535
  elo = (type *)_elua_obj_new(L, ed, sizeof(type), meta); \
1536
  elo->obj.free_func = free;
1537
// Stack usage [-2, +2, e]
1538
// Stack usage [-5, +6, m]
1539

1540
static void
1541
_elua_polish_evas_object(Edje *ed, Edje_Lua_Evas_Object *elo)
1542
{
1543
   evas_object_smart_member_add(elo->evas_obj, ed->obj);
1544
   evas_object_clip_set(elo->evas_obj, ed->base.clipper);
1545
   evas_object_move(elo->evas_obj, ed->x, ed->y);
1546
   evas_object_resize(elo->evas_obj, 0, 0);
1547
   evas_object_data_set(elo->evas_obj, ELO, elo);
1548
}
1549

1550
/**
1551
   @page luaref
1552
   @subsubsection edje_edje edje.edje()
1553

1554
   Create an edje object, and add it to the edje.
1555

1556
   Wraps edje_object_add().
1557

1558
   @returns A userdata that is an edje object.
1559

1560
   @since 1.1.0
1561
 */
1562
static int
1563
_elua_edje(lua_State *L) // Stack usage [-7, +8, em]
1564
{
1565
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_edje_meta, _elua_efl_canvas_object_free)
1566
   // Stack usage [-7, +8, em]
1567
   elo->evas_obj = edje_object_add(evas_object_evas_get(ed->obj));
1568
   _edje_subobj_register(ed, elo->evas_obj);
1569
   _elua_polish_evas_object(ed, elo);
1570
   return 1;
1571
}
1572

1573
/**
1574
   @page luaref
1575
   @subsubsection edje_image edje.image()
1576

1577
   Create an evas image, and add it to the edje.
1578

1579
   Wraps evas_object_image_add().
1580

1581
   @returns A userdata that is an evas image.
1582

1583
   @since 1.1.0
1584
 */
1585
static int
1586
_elua_image(lua_State *L) // Stack usage [-7, +8, em]
1587
{
1588
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_image_meta, _elua_efl_canvas_object_free)
1589
   // Stack usage [-7, +8, em]
1590
   elo->evas_obj = evas_object_image_filled_add(evas_object_evas_get(ed->obj));
1591
   _elua_polish_evas_object(ed, elo);
1592
   return 1;
1593
}
1594

1595
/**
1596
   @page luaref
1597
   @subsubsection edje_line edje.line()
1598

1599
   Create an evas line, and add it to the edje.
1600

1601
   Wraps evas_object_line_add().
1602

1603
   @returns A userdata that is an evas line.
1604

1605
   @since 1.1.0
1606
 */
1607
static int
1608
_elua_line(lua_State *L) // Stack usage [-7, +8, em]
1609
{
1610
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_line_meta, _elua_efl_canvas_object_free)
1611
   // Stack usage [-7, +8, em]
1612
   elo->evas_obj = evas_object_line_add(evas_object_evas_get(ed->obj));
1613
   _elua_polish_evas_object(ed, elo);
1614
   return 1;
1615
}
1616

1617
static void
1618
_elua_map_free(void *obj)
1619
{
1620
   Edje_Lua_Map *elm = obj;
1621
   if (!elm->obj.ed) return;
1622
   evas_map_free(elm->map);
1623
   elm->map = NULL;
1624
}
1625

1626
/**
1627
   @page luaref
1628
   @subsubsection edje_map edje.map()
1629

1630
   Create an evas map.
1631

1632
   Wraps evas_map_new().
1633

1634
   @returns A userdata that is an evas map.
1635

1636
   @since 1.1.0
1637
 */
1638
static int
1639
_elua_map(lua_State *L) // Stack usage [-7, +8, emv]
1640
{
1641
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Map, _elua_evas_map_meta, _elua_map_free)
1642
   // Stack usage [-7, +8, em]
1643
   elo->map = evas_map_new(luaL_checkinteger(L, 1)); // Stack usage [-0, +0, v]
1644
   return 1;
1645
}
1646

1647
/**
1648
   @page luaref
1649
   @subsubsection edje_polygon edje.polygon()
1650

1651
   Create an evas polygon, and add it to the edje.
1652

1653
   Wraps evas_object_polygon_add().
1654

1655
   @returns A userdata that is an evas polygon.
1656

1657
   @since 1.1.0
1658
 */
1659
static int
1660
_elua_polygon(lua_State *L) // Stack usage [-7, +8, em]
1661
{
1662
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_polygon_meta, _elua_efl_canvas_object_free)
1663
   // Stack usage [-7, +8, em]
1664
   elo->evas_obj = evas_object_polygon_add(evas_object_evas_get(ed->obj));
1665
   _elua_polish_evas_object(ed, elo);
1666
   return 1;
1667
}
1668

1669
/**
1670
   @page luaref
1671
   @subsubsection edje_rect edje.rect()
1672

1673
   Create an evas rectangle, and add it to the edje.
1674

1675
   Wraps evas_object_rectangle_add().
1676

1677
   @returns A userdata that is an evas rectangle.
1678
 */
1679
static int
1680
_elua_rect(lua_State *L) // Stack usage [-7, +8, em]
1681
{
1682
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_meta, _elua_efl_canvas_object_free)
1683
   // Stack usage [-7, +8, em]
1684
   elo->evas_obj = evas_object_rectangle_add(evas_object_evas_get(ed->obj));
1685
   _elua_polish_evas_object(ed, elo);
1686
   return 1;
1687
}
1688

1689
/**
1690
   @page luaref
1691
   @subsubsection edje_text edje.text()
1692

1693
   Create an evas text object, and add it to the edje.
1694

1695
   Wraps evas_object_text_add().
1696

1697
   @returns A userdata that is an evas text object.
1698

1699
   @since 1.1.0
1700
 */
1701
static int
1702
_elua_text(lua_State *L) // Stack usage [-7, +8, em]
1703
{
1704
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_text_meta, _elua_efl_canvas_object_free)
1705
   // Stack usage [-7, +8, em]
1706
   elo->evas_obj = evas_object_text_add(evas_object_evas_get(ed->obj));
1707
   _elua_polish_evas_object(ed, elo);
1708
   return 1;
1709
}
1710

1711
/* XXX: disabled until there are enough textblock functions implemented to make it actually useful
1712
   _elua_textblock(lua_State *L)                               // Stack usage [-7, +8, em]
1713
   {
1714
   _ELUA_PLANT_EVAS_OBJECT(Edje_Lua_Evas_Object, _elua_evas_textblock_meta, _elua_efl_canvas_object_free)
1715
                                                            // Stack usage [-7, +8, em]
1716
   elo->evas_obj = evas_object_textblock_add(evas_object_evas_get(ed->obj));
1717
   _elua_polish_evas_object(ed, elo);
1718
   return 1;
1719
   }
1720
 */
1721

1722
//-------------
1723
//-------------
1724

1725
/**
1726
   @page luaref
1727
   @subsection evas Evas class.
1728

1729
   The lua evas class includes functions for dealing with evas objects.  The evas
1730
   objects must have been previously created by lua using one of the lua evas
1731
   object creation functions from the lua edje class.
1732

1733
   In the following, "evas_object" is a place holder for any lua variable that
1734
   holds a reference to an evas object.
1735
 */
1736

1737
static int _elua_hide(lua_State *L);
1738
static int _elua_show(lua_State *L);
1739
static int _elua_visible(lua_State *L);
1740

1741
static int _elua_above(lua_State *L);
1742
static int _elua_below(lua_State *L);
1743
static int _elua_bottom(lua_State *L);
1744
static int _elua_lower(lua_State *L);
1745
static int _elua_raise(lua_State *L);
1746
static int _elua_top(lua_State *L);
1747

1748
static int _elua_geom(lua_State *L);
1749
static int _elua_move(lua_State *L);
1750
static int _elua_pos(lua_State *L);
1751
static int _elua_resize(lua_State *L);
1752
static int _elua_size(lua_State *L);
1753

1754
static int _elua_clip(lua_State *L);
1755
static int _elua_clipees(lua_State *L);
1756
static int _elua_unclip(lua_State *L);
1757

1758
static int _elua_type(lua_State *L);
1759

1760
static int _elua_pass(lua_State *L);
1761
static int _elua_precise(lua_State *L);
1762
static int _elua_repeat(lua_State *L);
1763

1764
static int _elua_color(lua_State *L);
1765

1766
static int _elua_obj_map(lua_State *L);
1767
static int _elua_obj_map_enable(lua_State *L);
1768

1769
static const char *_elua_evas_api = "evas";
1770
static const struct luaL_Reg _elua_evas_funcs [] =
1771
{
1772
   {"del", _elua_obj_del},            // generic del any object created for edje (evas objects, timers, animators, transitions... everything)
1773

1774
   {"hide", _elua_hide},           // hide, return current visibility
1775
   {"show", _elua_show},           // show, return current visibility
1776
   {"visible", _elua_visible},        // get object visibility
1777

1778
   {"above", _elua_above},          // get object above or stack obj above given obj
1779
   {"below", _elua_below},          // get object below or stack obj below given obj
1780
   {"bottom", _elua_bottom},         // get bottom
1781
   {"lower", _elua_lower},          // lower to bottom
1782
   {"raise", _elua_raise},          // raise to top
1783
   {"top", _elua_top},            // get top
1784

1785
   {"geom", _elua_geom},           // move and resize and return current geometry
1786
   {"move", _elua_move},           // move, return current position
1787
   {"pos", _elua_pos},            // move, return current position
1788
   {"resize", _elua_resize},         // resize, return current size
1789
   {"size", _elua_size},           // resize, return current size
1790

1791
   {"clip", _elua_clip},           // set clip obj, return clip object
1792
   {"clipees", _elua_clipees},        // get clip children
1793
   {"unclip", _elua_unclip},         // clear clip obj
1794

1795
   {"type", _elua_type},           // get object type
1796

1797
   {"pass", _elua_pass},           // set pass events, get pass events
1798
   {"precise", _elua_precise},        // set precise inside flag, get precise
1799
   {"repeat", _elua_repeat},         // set repeat events, get repeat events
1800

1801
   {"color", _elua_color},          // set color, return color
1802
//     {"color_class",  _elua_object_color_class}, // get or set object color class
1803

1804
   // FIXME: set callbacks (mouse down, up, blah blah blah)
1805
   //
1806
   // FIXME: set scale (explicit value)
1807
   // FIXME: need to set auto-scale (same as scale: 1)
1808

1809
   // FIXME: later - set render op, anti-alias, pointer mode (autograb, nograb)
1810

1811
   // map api here
1812
   {"map", _elua_obj_map},
1813
   {"map_enable", _elua_obj_map_enable},
1814

1815
   {NULL, NULL}   // end
1816
};
1817

1818
//-------------
1819
/**
1820
   @page luaref
1821
   @subsubsection evas_hide evas_object:hide()
1822

1823
   Hides the object.
1824

1825
   Wraps evas_object_hide().
1826

1827
   @returns A boolean representing the current visibility.
1828
 */
1829
static int
1830
_elua_hide(lua_State *L) // Stack usage [-0, +1, -]
1831
{
1832
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1833
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1834
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1835
   evas_object_hide(elo->evas_obj);
1836
   lua_pushboolean(L, evas_object_visible_get(elo->evas_obj));  // Stack usage [-0, +1, -]
1837
   return 1;
1838
}
1839

1840
/**
1841
   @page luaref
1842
   @subsubsection evas_show evas_object:show()
1843

1844
   Shows the object.
1845

1846
   Wraps evas_object_show().
1847

1848
   @returns A boolean representing the current visibility.
1849
 */
1850
static int
1851
_elua_show(lua_State *L) // Stack usage [-0, +1, -]
1852
{
1853
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1854
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1855
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1856
   evas_object_show(elo->evas_obj);
1857
   lua_pushboolean(L, evas_object_visible_get(elo->evas_obj));  // Stack usage [-0, +1, -]
1858
   return 1;
1859
}
1860

1861
/**
1862
   @page luaref
1863
   @subsubsection evas_visible evas_object:visible(visibility)
1864

1865
   Gets (and optionally sets) this objects visibility.
1866

1867
   Wraps evas_object_hide() or evas_object_show().
1868

1869
   @param visibility The new visibility you want to change it to.
1870

1871
   Note that the argument is optional, without it this function just queries the
1872
   current value.
1873

1874
   @returns A boolean representing the current visibility.
1875
 */
1876
static int
1877
_elua_visible(lua_State *L) // Stack usage [-0, +1, -]
1878
{
1879
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1880
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1881
   int n;
1882
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1883
   n = lua_gettop(L); // Stack usage [-0, +0, -]
1884
   if (n == 2)
1885
     {
1886
        if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
1887
          {
1888
             if (lua_toboolean(L, 2)) evas_object_show(elo->evas_obj);
1889
             // Stack usage [-0, +0, -]
1890
             else evas_object_hide(elo->evas_obj);
1891
          }
1892
     }
1893
   lua_pushboolean(L, evas_object_visible_get(elo->evas_obj));  // Stack usage [-0, +1, -]
1894
   return 1;
1895
}
1896

1897
//-------------
1898
/**
1899
   @page luaref
1900
   @subsubsection evas_above evas_object:above()
1901

1902
   Figure out what, if anything, is above us.
1903

1904
   Wraps evas_object_above_get().
1905

1906
   Note that it may not return any value.
1907

1908
   @returns A reference to the object above this one.
1909
 */
1910
static int
1911
_elua_above(lua_State *L) // Stack usage [-3, +4, -]
1912
{
1913
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1914
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1915
   Edje_Lua_Evas_Object *elo2;
1916
   Evas_Object *o;
1917
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1918
   if (!(o = evas_object_above_get(elo->evas_obj))) return 0;
1919
   if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1920
   _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1921
   return 1;
1922
}
1923

1924
/**
1925
   @page luaref
1926
   @subsubsection evas_below evas_object:below()
1927

1928
   Figure out what, if anything, is below us.
1929

1930
   Wraps evas_object_below_get().
1931

1932
   Note that it may not return any value.
1933

1934
   @returns A reference to the object below this one.
1935
 */
1936
static int
1937
_elua_below(lua_State *L) // Stack usage [-3, +4, -]
1938
{
1939
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1940
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1941
   Edje_Lua_Evas_Object *elo2;
1942
   Evas_Object *o;
1943
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1944
   if (!(o = evas_object_below_get(elo->evas_obj))) return 0;
1945
   if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
1946
   _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1947
   return 1;
1948
}
1949

1950
/**
1951
   @page luaref
1952
   @subsubsection evas_bottom evas_object:bottom()
1953

1954
   Figure out what, if anything, is waaaay below us.
1955

1956
   Note that it may not return any value.
1957

1958
   @returns A reference to the object at the bottom.
1959
 */
1960
static int
1961
_elua_bottom(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
1962
{
1963
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1964
   Edje_Lua_Evas_Object *elo2;
1965
   Evas_Object *o;
1966
   Eina_List *list, *l;
1967
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1968
   if (!(list = (Eina_List *)evas_object_smart_members_get(obj->ed->obj))) return 0;
1969
   for (l = list; l; l = l->next)
1970
     {
1971
        o = l->data;
1972
        if ((elo2 = evas_object_data_get(o, ELO)))
1973
          {
1974
             _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
1975
             return 1;
1976
          }
1977
     }
1978
   return 0;
1979
}
1980

1981
/**
1982
   @page luaref
1983
   @subsubsection evas_lower evas_object:lower()
1984

1985
   Lower this object to the bottom.
1986

1987
   Wraps evas_object_lower().
1988
 */
1989
static int
1990
_elua_lower(lua_State *L) // Stack usage [-0, +0, -]
1991
{
1992
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
1993
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
1994
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
1995
   evas_object_lower(elo->evas_obj);
1996
   return 0;
1997
}
1998

1999
/**
2000
   @page luaref
2001
   @subsubsection evas_raise evas_object:raise()
2002

2003
   Raise this object to the top.
2004

2005
   Wraps evas_object_raise().
2006
 */
2007
static int
2008
_elua_raise(lua_State *L) // Stack usage [-0, +0, -]
2009
{
2010
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2011
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2012
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2013
   evas_object_raise(elo->evas_obj);
2014
   return 0;
2015
}
2016

2017
/**
2018
   @page luaref
2019
   @subsubsection evas_top evas_object:top()
2020

2021
   Figure out what, if anything, is waaaay above us.
2022

2023
   Note that it may not return any value.
2024

2025
   @returns A reference to the object at the top.
2026
 */
2027
static int
2028
_elua_top(lua_State *L) // Stack usage [-(0|3), +(0|4), -]
2029
{
2030
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-(0, +0, -]
2031
   Edje_Lua_Evas_Object *elo2;
2032
   Evas_Object *o;
2033
   Eina_List *list, *l;
2034
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2035
   list = evas_object_smart_members_get(obj->ed->obj);
2036
   if (!list) return 0;
2037
   for (l = eina_list_last(list); l; l = l->prev)
2038
     {
2039
        o = l->data;
2040
        if ((elo2 = evas_object_data_get(o, ELO)))
2041
          {
2042
             _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2043
             return 1;
2044
          }
2045
     }
2046
   return 0;
2047
}
2048

2049
//-------------
2050
/**
2051
   @page luaref
2052
   @subsubsection evas_geom evas_object:geom(x, y, w, h)
2053

2054
   Gets (and optionally sets) this objects geometry.
2055

2056
   Wraps evas_object_move() and evas_object_resize.
2057

2058
   @param x The new X coordinate.
2059
   @param y The new Y coordinate.
2060
   @param w The new width.
2061
   @param h The new height.
2062

2063
   Note that the arguments are optional, without them this function just queries
2064
   the current values.  The arguments can be separate values, or named fields in a
2065
   table.
2066

2067
   @return A table with these fields:
2068
   - integer x: X coordinate.
2069
   - integer x: Y coordinate.
2070
   - integer w: Width.
2071
   - integer w: Height.
2072
 */
2073
static int
2074
_elua_geom(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2075
{
2076
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2077
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2078
   Evas_Coord ox, oy, ow, oh;
2079
   int x, y, w, h;
2080

2081
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2082
   evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2083
   if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2084
     {
2085
        if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2086
          {
2087
             evas_object_move(elo->evas_obj,
2088
                              obj->ed->x + x,
2089
                              obj->ed->y + y);
2090
          }
2091
        if ((w != ow) || (h != oh))
2092
          {
2093
             evas_object_resize(elo->evas_obj, w, h);
2094
          }
2095
        evas_object_geometry_get(elo->evas_obj, &ox, &oy, &ow, &oh);
2096
        elo->x = ox - obj->ed->x;
2097
        elo->y = oy - obj->ed->y;
2098
     }
2099
   _elua_ret(L, "%x %y %w %h", elo->x, elo->y, ow, oh);
2100
   // Stack usage [-8, +9, em]
2101
   return 1;
2102
}
2103

2104
/**
2105
   @page luaref
2106
   @subsubsection evas_move evas_object:move(x, y)
2107

2108
   Gets (and optionally sets) this objects position.
2109

2110
   Wraps evas_object_move().
2111

2112
   @param x The new X coordinate.
2113
   @param y The new Y coordinate.
2114

2115
   Note that the arguments are optional, without them this function just queries
2116
   the current values.  The arguments can be separate values, or named fields in a
2117
   table.
2118

2119
   @return A table with these fields:
2120
   - integer x: X coordinate.
2121
   - integer x: Y coordinate.
2122
 */
2123
static int
2124
_elua_move(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2125
{
2126
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2127
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2128
   Evas_Coord ox, oy;
2129
   int x, y;
2130

2131
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2132
   evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2133
   if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2134
     {
2135
        if ((x != (ox - obj->ed->x)) || (y != (oy - obj->ed->y)))
2136
          {
2137
             evas_object_move(elo->evas_obj,
2138
                              obj->ed->x + x,
2139
                              obj->ed->y + y);
2140
             evas_object_geometry_get(elo->evas_obj, &ox, &oy, NULL, NULL);
2141
          }
2142
        elo->x = ox - obj->ed->x;
2143
        elo->y = oy - obj->ed->y;
2144
     }
2145
   _elua_ret(L, "%x %y", elo->x, elo->y);
2146
   // Stack usage [-4, +5, em]
2147
   return 1;
2148
}
2149

2150
/**
2151
   @page luaref
2152
   @subsubsection evas_pos evas_object:pos(x, y)
2153

2154
   An alias for evas_object:move().
2155
 */
2156
static int
2157
_elua_pos(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2158
{
2159
   return _elua_move(L);
2160
}
2161

2162
/**
2163
   @page luaref
2164
   @subsubsection evas_resize evas_object:resize(w, h)
2165

2166
   Gets (and optionally sets) this objects size.
2167

2168
   Wraps evas_object_resize().
2169

2170
   @param w The new width.
2171
   @param h The new height.
2172

2173
   Note that the arguments are optional, without them this function just queries
2174
   the current values.  The arguments can be separate values, or named fields in a
2175
   table.
2176

2177
   @return A table with these fields:
2178
   - integer w: Width.
2179
   - integer w: Height.
2180
 */
2181
static int
2182
_elua_resize(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2183
{
2184
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2185
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2186
   Evas_Coord ow, oh;
2187
   int w, h;
2188

2189
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2190
   evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2191
   if (_elua_scan_params(L, 2, "%w %h", &w, &h) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2192
     {
2193
        if ((w != ow) || (h != oh))
2194
          {
2195
             evas_object_resize(elo->evas_obj, w, h);
2196
             evas_object_geometry_get(elo->evas_obj, NULL, NULL, &ow, &oh);
2197
          }
2198
     }
2199
   _elua_ret(L, "%w %h", ow, oh);
2200
   // Stack usage [-4, +5, em]
2201
   return 1;
2202
}
2203

2204
/**
2205
   @page luaref
2206
   @subsubsection evas_size evas_object:size()
2207

2208
   An alias for evas_object:resize().
2209
 */
2210
static int
2211
_elua_size(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2212
{
2213
   return _elua_resize(L);
2214
}
2215

2216
//-------------
2217
/**
2218
   @page luaref
2219
   @subsubsection evas_clip evas_object:clip(evas_object2)
2220

2221
   Get (and optionally set) the object that clips this object.
2222

2223
   Note that the argument is optional, without it this function just queries the
2224
   current value.
2225

2226
   Wraps evas_object_clip_set().
2227

2228
   @param evas_object2 A reference to the object to clip this object with.
2229

2230
   @returns A reference to the object clipping this object, if any.
2231
 */
2232
static int
2233
_elua_clip(lua_State *L) // Stack usage [-3, +4, -]
2234
{
2235
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1); // Stack usage [-0, +0, -]
2236
   Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2237
   Evas_Object *o;
2238
   int n;
2239
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2240
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2241
   if (n == 2)
2242
     {
2243
        Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2);  // Stack usage [-0, +0, -]
2244
        elo2 = (Edje_Lua_Evas_Object *)obj2;
2245
        if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
2246
        evas_object_clip_set(elo->evas_obj, elo2->evas_obj);
2247
     }
2248
   o = evas_object_clip_get(elo->evas_obj);
2249
   if (!o) return 0;
2250
   if (!(elo2 = evas_object_data_get(o, ELO))) return 0;
2251
   _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2252
   return 1;
2253
}
2254

2255
/**
2256
   @page luaref
2257
   @subsubsection evas_clipees evas_object:clipees()
2258

2259
   Gets the list of objects this objects clips.
2260

2261
   Wraps evas_object_clipees_get().
2262

2263
   @return A table, that holds all the objects this clips, if any,
2264
         otherwise an empty table.
2265
 */
2266
static int
2267
_elua_clipees(lua_State *L) // Stack usage [-0, +1, me] plus [-5, +5] for each clipee.
2268
{
2269
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2270
   Edje_Lua_Evas_Object *elo2, *elo = (Edje_Lua_Evas_Object *)obj;
2271
   Eina_List *list, *l;
2272
   Evas_Object *o;
2273
   int n = 0;
2274
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2275
   list = (Eina_List *)evas_object_clipees_get(elo->evas_obj);
2276
   lua_newtable(L); // Stack usage [-0, +1, m]
2277
   EINA_LIST_FOREACH(list, l, o)
2278
     {
2279
        if (!(elo2 = evas_object_data_get(o, ELO))) continue;
2280
        lua_pushinteger(L, n + 1); // Stack usage [-0, +1, -]
2281
        _elua_ref_get(L, elo2); // Stack usage [-3, +4, -]
2282
        lua_settable(L, -3); // Stack usage [-2, +0, e]
2283
        n++;
2284
     }
2285
   return 1;
2286
}
2287

2288
/**
2289
   @page luaref
2290
   @subsubsection evas_unclip evas_object:unclip()
2291

2292
   Remove any clipping on this object.
2293

2294
   Wraps evas_object_clip_unset().
2295
 */
2296
static int
2297
_elua_unclip(lua_State *L) // Stack usage [-0, +0, -]
2298
{
2299
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2300
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2301
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2302
   evas_object_clip_unset(elo->evas_obj);
2303
   return 0;
2304
}
2305

2306
//-------------
2307
/**
2308
   @page luaref
2309
   @subsubsection evas_type evas_object:type()
2310

2311
   Get the type of this object.  See the documentation of the evas_object_type_get()
2312
   C function for details.
2313

2314
   Wraps evas_object_type_get().
2315

2316
   @return A string with this objects type in it.
2317
 */
2318
static int
2319
_elua_type(lua_State *L) // Stack usage [-0, +1, m]
2320
{
2321
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2322
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2323
   const char *t;
2324
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2325
   t = evas_object_type_get(elo->evas_obj);
2326
   if (!t) return 0;
2327
   lua_pushstring(L, t); // Stack usage [-0, +1, m]
2328
   return 1;
2329
}
2330

2331
//-------------
2332
/**
2333
   @page luaref
2334
   @subsubsection evas_pass evas_object:pass(pass)
2335

2336
   Get (and optionally set) whether this object ignores events, passing them to the
2337
   next object underneath it.
2338

2339
   Wraps evas_object_pass_events_set().
2340

2341
   @param pass A boolean saying if this object passes events.
2342

2343
   Note that the argument is optional, without it this function just queries the
2344
   current value.
2345

2346
   @return A boolean saying if this object passes events.
2347
 */
2348
static int
2349
_elua_pass(lua_State *L) // Stack usage [-0, +1, -]
2350
{
2351
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2352
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2353
   int n;
2354
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2355
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2356
   if (n == 2)
2357
     {
2358
        if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2359
          {
2360
             evas_object_pass_events_set(elo->evas_obj, lua_toboolean(L, 2));
2361
             // Stack usage [-0, +0, -]
2362
          }
2363
     }
2364
   lua_pushboolean(L, evas_object_pass_events_get(elo->evas_obj));
2365
   // Stack usage [-0, +1, -]
2366
   return 1;
2367
}
2368

2369
/**
2370
   @page luaref
2371
   @subsubsection evas_precise evas_object:precise(precise)
2372

2373
   Get (and optionally set) whether to use precise (usually expensive) point
2374
   collision detection for this object.
2375

2376
   Wraps evas_object_precise_is_inside_set().
2377

2378
   @param precise A boolean saying if this object is precisely detected.
2379

2380
   Note that the argument is optional, without it this function just queries the
2381
   current value.
2382

2383
   @return A boolean saying if this object is precisely detected.
2384
 */
2385
static int
2386
_elua_precise(lua_State *L) // Stack usage [-0, +1, -]
2387
{
2388
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2389
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2390
   int n;
2391
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2392
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2393
   if (n == 2)
2394
     {
2395
        if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2396
          {
2397
             evas_object_precise_is_inside_set(elo->evas_obj, lua_toboolean(L, 2));
2398
             // Stack usage [-0, +0, -]
2399
          }
2400
     }
2401
   lua_pushboolean(L, evas_object_precise_is_inside_get(elo->evas_obj));
2402
   // Stack usage [-0, +1, -]
2403
   return 1;
2404
}
2405

2406
/**
2407
   @page luaref
2408
   @subsubsection evas_repeat evas_object:repeat(repeat)
2409

2410
   Get (and optionally set) whether this object repeats events.
2411

2412
   Wraps evas_object_repeat_events_set().
2413

2414
   @param repeat A boolean saying if this object repeats events to lower objects.
2415

2416
   Note that the argument is optional, without it this function just queries the
2417
   current value.
2418

2419
   @return A boolean saying if this object repeats events.
2420
 */
2421
static int
2422
_elua_repeat(lua_State *L) // Stack usage [-0, +1, -]
2423
{
2424
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2425
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2426
   int n;
2427
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2428
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2429
   if (n == 2)
2430
     {
2431
        if (lua_isboolean(L, 2)) // Stack usage [-0, +0, -]
2432
          {
2433
             evas_object_repeat_events_set(elo->evas_obj, lua_toboolean(L, 2));
2434
             // Stack usage [-0, +0, -]
2435
          }
2436
     }
2437
   lua_pushboolean(L, evas_object_repeat_events_get(elo->evas_obj));
2438
   // Stack usage [-0, +1, -]
2439
   return 1;
2440
}
2441

2442
//-------------
2443
/**
2444
   @page luaref
2445
   @subsubsection evas_colour evas_object:color(r, g, b, a)
2446

2447
   Gets (and optionally sets) this objects colour.
2448

2449
   Wraps evas_object_color_set().
2450

2451
   @param r The new red value.
2452
   @param g The new green value.
2453
   @param b The new blue value.
2454
   @param a The new alpha value.
2455

2456
   Note that the arguments are optional, without them this function just queries
2457
   the current values.  The arguments can be separate values, or named fields in a
2458
   table.
2459

2460
   @return A table with these fields:
2461
   - integer r: The red value.
2462
   - integer g: The green value.
2463
   - integer b: The blue value.
2464
   - integer a: The alpha value.
2465
 */
2466
static int
2467
_elua_color(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2468
{
2469
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2470
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2471
   int r, g, b, a;
2472

2473
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2474
   if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2475
     {
2476
        _elua_color_fix(&r, &g, &b, &a);
2477
        evas_object_color_set(elo->evas_obj, r, g, b, a);
2478
     }
2479
   evas_object_color_get(elo->evas_obj, &r, &g, &b, &a);
2480
   _elua_ret(L, "%r %g %b %a", r, g, b, a);
2481
   // Stack usage [-8, +9, em]
2482
   return 1;
2483
}
2484

2485
//-------------
2486
/**
2487
   @page luaref
2488
   @subsubsection evas_map evas_object:map(map)
2489

2490
   Attach a map to this object.
2491

2492
   Wraps evas_object_map_set().
2493

2494
   @param map The map to attach.
2495

2496
   @since 1.1.0
2497
 */
2498
static int
2499
_elua_obj_map(lua_State *L) // Stack usage [-0, +0, -]
2500
{
2501
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2502
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2503
   Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2);   // Stack usage [-0, +0, -]
2504
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj2;
2505
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2506
   if (!_elua_isa(obj2, _elua_evas_map_meta)) return 0;
2507

2508
   evas_object_map_set(elo->evas_obj, elm->map);
2509

2510
   return 0;
2511
}
2512

2513
/**
2514
   @page luaref
2515
   @subsubsection evas_map_enable evas_object:map_enable(enable)
2516

2517
   Enable or disable the map attached to this object.
2518

2519
   Wraps evas_object_map_enable_set().
2520

2521
   @param enable A booleon that controls if the attached map is enabled or not.
2522

2523
   @return A boolean reflecting the map enabled status of this object.
2524

2525
   @since 1.1.0
2526
 */
2527
static int
2528
_elua_obj_map_enable(lua_State *L) // Stack usage [-0, +1, -]
2529
{
2530
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2531
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2532
   int n;
2533
   if (!_elua_isa(obj, _elua_evas_meta)) return 0;
2534

2535
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2536
   if (n == 2)
2537
     {
2538
        evas_object_map_enable_set(elo->evas_obj, lua_toboolean(L, 2));
2539
        // Stack usage [-0, +0, -]
2540
     }
2541
   lua_pushboolean(L, evas_object_map_enable_get(elo->evas_obj));
2542
   // Stack usage [-0, +1, -]
2543
   return 1;
2544
}
2545

2546
//-------------
2547
//-------------
2548
/**
2549
   @page luaref
2550
   @subsection ecore_animator Ecore animator class.
2551

2552
   The lua ecore animator class includes functions for dealing with ecore animator objects.
2553
   The ecore animator objects must have been previously created by lua using the lua
2554
   edje object creation function edje.animator() or edje.transition().
2555

2556
   In the following, "animator_object" is a place holder for any lua variable that
2557
   holds a reference to an ecore animator object.
2558
 */
2559
static const char *_elua_ecore_animator_api = "ecore_animator";
2560
static const struct luaL_Reg _elua_ecore_animator_funcs [] =
2561
{
2562
   {NULL, NULL}   // end
2563
};
2564

2565
//-------------
2566
//-------------
2567
/**
2568
   @page luaref
2569
   @subsection ecore_timer Ecore timer class.
2570

2571
   The lua ecore timer class includes functions for dealing with ecore timer objects.
2572
   The ecore timer objects must have been previously created by lua using the lua
2573
   edje object creation function edje.timer().
2574

2575
   In the following, "timer_object" is a place holder for any lua variable that
2576
   holds a reference to an ecore timer object.
2577
 */
2578

2579
static const char *_elua_ecore_timer_api = "ecore_timer";
2580
static const struct luaL_Reg _elua_ecore_timer_funcs [] =
2581
{
2582
   {NULL, NULL}   // end
2583
};
2584

2585
//-------------
2586
//-------------
2587
/**
2588
   @page luaref
2589
   @subsection evas_edje Evas edje class.
2590

2591
   The lua evas edje class includes functions for dealing with evas edje objects.
2592
   The evas edje objects must have been previously created by lua using the lua
2593
   edje object creation function edje.edje().
2594

2595
   In the following, "edje_object" is a place holder for any lua variable that
2596
   holds a reference to an evas edje object.  NOT the edje class specified earlier
2597
   though.
2598

2599
   @since 1.1.0
2600
 */
2601

2602
static int _elua_edje_file(lua_State *L);
2603

2604
static const char *_elua_evas_edje_api = "evas_edje";
2605
static const char *_elua_evas_edje_parent = "evas_edje_parent";
2606
static const struct luaL_Reg _elua_evas_edje_funcs [] =
2607
{
2608
   {"file", _elua_edje_file},           // get or set edje file and group
2609

2610
   {NULL, NULL}   // end
2611
};
2612

2613
/**
2614
   @page luaref
2615
   @subsubsection edje_file edje_object:file(file, group)
2616

2617
   Load an edje group into this edje object.
2618

2619
   Wraps edje_object_file_set().
2620

2621
   @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2622
   @param group The group within the edje file to be loaded.
2623

2624
   Note that the arguments are optional, without them this function just queries
2625
   the current values.  The arguments can be separate values, or named fields in a
2626
   table.  The file argument is optional, and ignored anyway.
2627

2628
   @return A table with these fields:
2629
   - string file: The name of the edje file this edje's group is loaded from.
2630
   - string group: The name of the group this edje is loaded from.
2631

2632
   @since 1.1.0
2633
 */
2634
static int
2635
_elua_edje_file(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2636
{
2637
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2638
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2639
   const char *file = NULL, *group = NULL;
2640
   int n = lua_gettop(L); // Stack usage [-0, +0, -]
2641

2642
   if (!_elua_isa(obj, _elua_evas_edje_meta)) return 0;
2643

2644
   n = _elua_scan_params(L, 2, "$file $group", &file, &group);
2645
   // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2646
   if (0 >= n)
2647
     {
2648
        file = (char *)obj->ed->file->path;
2649
        group = (char *)lua_tostring(L, 2); // Stack usage [-0, +0, m]
2650
        n = 2;
2651
     }
2652

2653
   if (1 < n)
2654
     {
2655
        // Sandbox lua - Only allow access to groups within the same file.
2656
        // By the simple expedient of completely ignoring what file was requested.
2657
        file = (char *)obj->ed->file->path;
2658
        if (!edje_object_file_set(elo->evas_obj, file, group))
2659
          {
2660
             Edje_Load_Error err = edje_object_load_error_get(elo->evas_obj);
2661

2662
             switch (err)
2663
               {
2664
                case EDJE_LOAD_ERROR_NONE:                         LE("Edje file loading errer %s %s - no error happened, but you should not see this.", obj->ed->file->path, group);  break;
2665

2666
                case EDJE_LOAD_ERROR_GENERIC:                      LE("Edje file loading errer %s %s - generic error.", obj->ed->file->path, group);  break;
2667

2668
                case EDJE_LOAD_ERROR_DOES_NOT_EXIST:               LE("Edje file loading errer %s %s - file does not exist.", obj->ed->file->path, group);  break;
2669

2670
                case EDJE_LOAD_ERROR_PERMISSION_DENIED:            LE("Edje file loading errer %s %s - permission denied reading the file.", obj->ed->file->path, group);  break;
2671

2672
                case EDJE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:   LE("Edje file loading errer %s %s - resource allocation failed.", obj->ed->file->path, group);  break;
2673

2674
                case EDJE_LOAD_ERROR_CORRUPT_FILE:                 LE("Edje file loading errer %s %s - corrupt file.", obj->ed->file->path, group);  break;
2675

2676
                case EDJE_LOAD_ERROR_UNKNOWN_FORMAT:               LE("Edje file loading errer %s %s - unknown file format.", obj->ed->file->path, group);  break;
2677

2678
                case EDJE_LOAD_ERROR_INCOMPATIBLE_FILE:            LE("Edje file loading errer %s %s - incompatible file.", obj->ed->file->path, group);  break;
2679

2680
                case EDJE_LOAD_ERROR_UNKNOWN_COLLECTION:           LE("Edje file loading errer %s %s - unknown group.", obj->ed->file->path, group);  break;
2681

2682
                case EDJE_LOAD_ERROR_RECURSIVE_REFERENCE:          LE("Edje file loading errer %s %s - recursive reference in group.", obj->ed->file->path, group);  break;
2683
               }
2684
          }
2685
     }
2686
   edje_object_file_get(elo->evas_obj, &file, &group);
2687
   _elua_ret(L, "$file $group", file, group);
2688
   // Stack usage [-4, +5, em]
2689
   return 1;
2690
}
2691

2692
//-------------
2693
//-------------
2694
/**
2695
   @page luaref
2696
   @subsection evas_image Evas image class.
2697

2698
   The lua evas image class includes functions for dealing with evas image objects.
2699
   The evas image objects must have been previously created by lua using the lua
2700
   image object creation function edje.image().
2701

2702
   In the following, "image_object" is a place holder for any lua variable that
2703
   holds a reference to an evas image object.
2704

2705
   @since 1.1.0
2706
 */
2707

2708
static int _elua_image_fill(lua_State *L);
2709
static int _elua_image_filled(lua_State *L);
2710
static int _elua_image_image(lua_State *L);
2711

2712
static const char *_elua_evas_image_api = "evas_image";
2713
static const char *_elua_evas_image_parent = "evas_image_parent";
2714
static const struct luaL_Reg _elua_evas_image_funcs [] =
2715
{
2716
   {"fill", _elua_image_fill},             // get or set the fill parameters
2717
   {"filled", _elua_image_filled},         // get or set the filled state (overrides fill())
2718
   {"image", _elua_image_image},           // get or set image
2719

2720
   {NULL, NULL}   // end
2721
};
2722

2723
/**
2724
   @page luaref
2725
   @subsubsection image_fill image_object:fill(x, y, w, h)
2726

2727
   Gets (and optionally sets) how to fill this image's drawing rectangle given the
2728
   (real) image bound to it.
2729

2730
   Wraps evas_object_image_fill_set().
2731

2732
   @param x The x coordinate (from the top left corner of the bound image) to start drawing from.
2733
   @param y The y coordinate (from the top left corner of the bound image) to start drawing from.
2734
   @param w The width the bound image will be displayed at.
2735
   @param h The height the bound image will be displayed at.
2736

2737
   Note that the arguments are optional, without them this function just queries
2738
   the current values.  The arguments can be separate values, or named fields in a
2739
   table.
2740

2741
   @return A table with these fields:
2742
   - integer x: The x coordinate (from the top left corner of the bound image) to start drawing from.
2743
   - integer y: The y coordinate (from the top left corner of the bound image) to start drawing from.
2744
   - integer w: The width the bound image will be displayed at.
2745
   - integer h: The height the bound image will be displayed at.
2746

2747
   @since 1.1.0
2748
 */
2749
static int
2750
_elua_image_fill(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2751
{
2752
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2753
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2754
   Evas_Coord x, y, w, h;
2755

2756
   if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2757

2758
   if (_elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2759
     {
2760
        evas_object_image_fill_set(elo->evas_obj, x, y, w, h);
2761
     }
2762
   evas_object_image_fill_get(elo->evas_obj, &x, &y, &w, &h);
2763
   _elua_ret(L, "%x %y %w %h", x, y, w, h);
2764
   // Stack usage [-8, +9, em]
2765
   return 1;
2766
}
2767

2768
/**
2769
   @page luaref
2770
   @subsubsection image_filled image_object:filled(filled)
2771

2772
   Get (and optionally set) whether this image fills the object.
2773

2774
   Wraps evas_object_image_filled_set().
2775

2776
   @param filled A boolean saying if this image fills the object.
2777

2778
   Note that the argument is optional, without it this function just queries the
2779
   current value.
2780

2781
   @return A boolean saying if this image fills the object.
2782

2783
   @since 1.1.0
2784
 */
2785
static int
2786
_elua_image_filled(lua_State *L) // Stack usage [-0, +0, -]
2787
{
2788
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2789
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2790
   int n;
2791

2792
   if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2793

2794
   n = lua_gettop(L); // Stack usage [-0, +0, -]
2795
   if (n == 2)
2796
     {
2797
        evas_object_image_filled_set(elo->evas_obj, lua_toboolean(L, 2));
2798
        // Stack usage [-0, +0, -]
2799
     }
2800
   lua_pushboolean(L, evas_object_image_filled_get(elo->evas_obj));
2801
   // Stack usage [-0, +0, -]
2802
   return 1;
2803
}
2804

2805
/**
2806
   @page luaref
2807
   @subsubsection image_image image_object:image(file, key)
2808

2809
   Load an image into this edje object.
2810

2811
   Wraps evas_object_image_file_set().
2812

2813
   @param file An edje file name (ignored, sandboxed to the file this lua script is in).
2814
   @param group The name of an image.
2815

2816
   Note that the arguments are optional, without them this function just queries
2817
   the current values.  The arguments can be separate values, or named fields in a
2818
   table.  The file argument is optional, and ignored anyway.
2819

2820
   @return A table with these fields:
2821
   - string file: The name of the edje file the image is loaded from.
2822
   - string key: The name of the image within the edje file.
2823

2824
   @since 1.1.0
2825
 */
2826
static int
2827
_elua_image_image(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
2828
{
2829
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2830
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2831
   const char *file = NULL, *key = NULL;
2832
   int n, id = -1;
2833

2834
   if (!_elua_isa(obj, _elua_evas_image_meta)) return 0;
2835

2836
   n = _elua_scan_params(L, 2, "$file $key", &file, &key);
2837
   // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
2838
   if (0 >= n)
2839
     {
2840
        file = (char *)obj->ed->file->path;
2841
        key = (char *)lua_tostring(L, 2); // Stack usage [-0, +0, m]
2842
        n = 2;
2843
     }
2844

2845
   if (1 < n)
2846
     {
2847
        if (obj->ed->file->image_dir)
2848
          {
2849
             Edje_Image_Directory_Entry *de;
2850
             unsigned int i;
2851
             char *name;
2852

2853
             /* Image name */
2854
             if ((name = strrchr(key, '/'))) name++;
2855
             else name = (char *)key;
2856

2857
             /* Loop through image directory to find if image exists */
2858
             for (i = 0; i < obj->ed->file->image_dir->entries_count; ++i)
2859
               {
2860
                  de = obj->ed->file->image_dir->entries + i;
2861

2862
                  if (de->entry)
2863
                    {
2864
                       if (strcmp(name, de->entry) == 0)
2865
                         {
2866
                            char buf[32];
2867

2868
                            id = i;
2869
                            // This is copied from _edje_image_recalc_apply()), dunno if it provides any benefit over sprintf().
2870
                            /* Replace snprint("edje/images/%i") == memcpy + itoa */
2871
#define IMAGES "edje/images/"
2872
                            memcpy(buf, IMAGES, strlen(IMAGES));
2873
                            eina_convert_itoa(id, buf + strlen(IMAGES)); /* No need to check length as 2³² need only 10 characters. */
2874
                            evas_object_image_file_set(elo->evas_obj, obj->ed->file->path, buf);
2875
                            break;
2876
                         }
2877
                    }
2878
               }
2879
          }
2880

2881
        if (-1 == id)
2882
          {
2883
             LE("Image %s not found in our edje file.", key);
2884
             /* Sandbox lua - Only allow access to images within the same edje file.  I'm not so sure we need this level of sandboxing though.  So leaving it here, just in case.
2885
                LI("Image %s not found in our edje file, trying external image file %s.", key, file);
2886
                evas_object_image_file_set(elo->evas_obj, file, key);
2887
              */
2888
          }
2889
     }
2890
   evas_object_image_file_get(elo->evas_obj, &file, &key);
2891
   _elua_ret(L, "$file $key", file, key);
2892
   // Stack usage [-4, +5, em]
2893
   return 1;
2894
}
2895

2896
//-------------
2897
//-------------
2898
/**
2899
   @page luaref
2900
   @subsection evas_line Evas line class.
2901

2902
   The lua evas line class includes functions for dealing with evas line objects.
2903
   The evas line objects must have been previously created by lua using the lua
2904
   line object creation function edje.line().
2905

2906
   In the following, "line_object" is a place holder for any lua variable that
2907
   holds a reference to an evas line object.
2908

2909
   @since 1.1.0
2910
 */
2911

2912
static int _elua_line_xy(lua_State *L);
2913

2914
static const char *_elua_evas_line_api = "evas_line";
2915
static const char *_elua_evas_line_parent = "evas_line_parent";
2916
static const struct luaL_Reg _elua_evas_line_funcs [] =
2917
{
2918
   {"xy", _elua_line_xy},           // get or set line coords
2919

2920
   {NULL, NULL}   // end
2921
};
2922

2923
/**
2924
   @page luaref
2925
   @subsubsection line_xy line_object:xy(x1, y1, x2, y2)
2926

2927
   Sets the end points of this line.
2928

2929
   Wraps evas_object_line_xy_set().
2930

2931
   @param x1 The X coordinate of the first line end.
2932
   @param y1 The Y coordinate of the first line end.
2933
   @param x2 The X coordinate of the other line end.
2934
   @param y2 The Y coordinate of the other line end.
2935

2936
   Note that the arguments are optional, without them this function just queries
2937
   the current values.  The arguments can be separate values, or named fields in a
2938
   table.
2939

2940
   @return A table with these fields:
2941
   - integer x1: The X coordinate of the first line end.
2942
   - integer y1: The Y coordinate of the first line end.
2943
   - integer x2: The X coordinate of the other line end.
2944
   - integer y2: The Y coordinate of the other line end.
2945

2946
   @since 1.1.0
2947
 */
2948
static int
2949
_elua_line_xy(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
2950
{
2951
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
2952
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
2953
   Evas_Coord x1, y1, x2, y2;
2954

2955
   if (!_elua_isa(obj, _elua_evas_line_meta)) return 0;
2956

2957
   if (_elua_scan_params(L, 2, "%x1 %y1 %x2 %y2", &x1, &y1, &x2, &y2) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
2958
     {
2959
        evas_object_line_xy_set(elo->evas_obj, x1, y1, x2, y2);
2960
     }
2961
   evas_object_line_xy_get(elo->evas_obj, &x1, &y1, &x2, &y2);
2962
   _elua_ret(L, "%x1 %y1 %x2 %y2", x1, y1, x2, y2);
2963
   // Stack usage [-8, +9, em]
2964
   return 1;
2965
}
2966

2967
//-------------
2968
//-------------
2969
/**
2970
   @page luaref
2971
   @subsection evas_object_map Evas map class.
2972

2973
   The lua evas map class includes functions for dealing with evas map objects.
2974
   The evas map objects must have been previously created by lua using the lua
2975
   map object creation function edje.map().  The evas map system is complex, rather
2976
   than repeat the copious documentation here, please refer to the evas map
2977
   documentation.  It has pictures and everything.  B-)
2978

2979
   In the following, "map_object" is a place holder for any lua variable that
2980
   holds a reference to an evas map object.
2981

2982
   @since 1.1.0
2983
 */
2984

2985
static int _elua_map_alpha(lua_State *L);
2986
static int _elua_map_clockwise(lua_State *L);
2987
static int _elua_map_colour(lua_State *L);
2988
static int _elua_map_coord(lua_State *L);
2989
static int _elua_map_lighting(lua_State *L);
2990
static int _elua_map_perspective(lua_State *L);
2991
static int _elua_map_populate(lua_State *L);
2992
static int _elua_map_rotate(lua_State *L);
2993
static int _elua_map_rotate3d(lua_State *L);
2994
static int _elua_map_smooth(lua_State *L);
2995
static int _elua_map_uv(lua_State *L);
2996
static int _elua_map_zoom(lua_State *L);
2997

2998
static const char *_elua_evas_map_api = "evas_map";
2999
static const struct luaL_Reg _elua_evas_map_funcs [] =
3000
{
3001
   {"alpha", _elua_map_alpha},
3002
//     {"dup",           _elua_map_dup},  // not sure of proper api for this.
3003
   {"clockwise", _elua_map_clockwise},
3004
   {"color", _elua_map_colour},
3005
   {"coord", _elua_map_coord},
3006
   {"lighting", _elua_map_lighting},
3007
   {"perspective", _elua_map_perspective},
3008
   {"populate", _elua_map_populate},
3009
   {"rotate", _elua_map_rotate},
3010
   {"rotate3d", _elua_map_rotate3d},
3011
//     {"size",          _elua_map_size},  // not sure of proper API for this
3012
   {"smooth", _elua_map_smooth},
3013
   {"uv", _elua_map_uv},
3014
   {"zoom", _elua_map_zoom},
3015

3016
   {NULL, NULL}   // end
3017
};
3018

3019
/**
3020
   @page luaref
3021
   @subsubsection map_alpha map_object:alpha(alpha)
3022

3023
   Get (and optionally set) the maps alpha mode.
3024

3025
   Wraps evas_map_alpha_set().
3026

3027
   @param alpha The alpha mode.
3028

3029
   Note that the argument is optional, without it this function just queries the
3030
   current value.
3031

3032
   @return A boolean reflecting the alpha mode.
3033

3034
   @since 1.1.0
3035
 */
3036
static int
3037
_elua_map_alpha(lua_State *L) // Stack usage [-0, +1, -]
3038
{
3039
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3040
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3041
   int n;
3042

3043
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3044

3045
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3046
   if (n == 2)
3047
     {
3048
        evas_map_alpha_set(elm->map, lua_toboolean(L, 2));
3049
        // Stack usage [-0, +0, -]
3050
     }
3051
   lua_pushboolean(L, evas_map_alpha_get(elm->map)); // Stack usage [-0, +1, -]
3052
   return 1;
3053
}
3054

3055
/**
3056
   @page luaref
3057
   @subsubsection map_clockwise map_object:clockwise()
3058

3059
   Get the maps clockwise state.
3060

3061
   Wraps evas_map_util_clockwise_get().
3062

3063
   @return A boolean reflecting if the map is clockwise or not.
3064

3065
   @since 1.1.0
3066
 */
3067
static int
3068
_elua_map_clockwise(lua_State *L) // Stack usage [-0, +1, -]
3069
{
3070
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3071
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3072

3073
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3074

3075
   lua_pushboolean(L, evas_map_util_clockwise_get(elm->map));   // Stack usage [-0, +1, -]
3076
   return 1;
3077
}
3078

3079
/**
3080
   @page luaref
3081
   @subsubsection map_colour map_object:colour(index, r, g, b, a)
3082

3083
   Gets or sets colour information for the map.  There are two variations, with or
3084
   without the index.  With the index parameter it gets (and optionally sets) the
3085
   colour of the point the index refers to, without it sets the colour for the
3086
   entire map.
3087

3088
   Wraps evas_map_point_color_set() or evas_map_util_points_color_set()
3089

3090
   @param index Which point to change the colour of.
3091
   @param r The new red value.
3092
   @param g The new green value.
3093
   @param b The new blue value.
3094
   @param a The new alpha value.
3095

3096
   Note that the arguments are optional, without them this function just queries
3097
   the current values.  The colour arguments can be separate values, or named
3098
   fields in a table.
3099

3100
   @return A table with these fields:
3101
   - integer r: The red value.
3102
   - integer g: The green value.
3103
   - integer b: The blue value.
3104
   - integer a: The alpha value.
3105

3106
   @since 1.1.0
3107
 */
3108
static int
3109
_elua_map_colour(lua_State *L) // Stack usage [-(8|12), +(9|13), em]
3110
{
3111
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3112
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3113
   int r, g, b, a;
3114
   int n;
3115

3116
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3117
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3118

3119
   switch (n)
3120
     {
3121
      case 5:
3122
      {
3123
         if (_elua_scan_params(L, 2, "%r %g %b %a", &r, &g, &b, &a) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3124
           {
3125
              evas_map_util_points_color_set(elm->map, r, g, b, a);
3126
           }
3127
         break;
3128
      }
3129

3130
      case 1:
3131
      case 6:
3132
      {
3133
         if (_elua_scan_params(L, 3, "%r %g %b %a", &r, &g, &b, &a) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3134
           {
3135
              evas_map_point_color_set(elm->map, lua_tointeger(L, 2), r, g, b, a);
3136
              // Stack usage [-0, +0, -]
3137
           }
3138
         evas_map_point_color_get(elm->map, lua_tointeger(L, 2), &r, &g, &b, &a);
3139
         // Stack usage [-0, +0, -]
3140
         _elua_ret(L, "%r %g %b %a", r, g, b, a);
3141
         // Stack usage [-8, +9, em]
3142
         return 1;
3143
      }
3144
     }
3145

3146
   return 0;
3147
}
3148

3149
/**
3150
   @page luaref
3151
   @subsubsection map_coord map_object:coord(index, x, y, z)
3152

3153
   Gets (and optionally sets) the 3D coordinates of a point on the map.
3154

3155
   Wraps evas_map_point_coord_set().
3156

3157
   @param x The x coordinate of the point.
3158
   @param y The y coordinate of the point.
3159
   @param z The z coordinate of the point.
3160

3161
   Note that the arguments are optional, without them this function just queries
3162
   the current values.  The coordinate arguments can be separate values, or named
3163
   fields in a table.
3164

3165
   @return A table with these fields:
3166
   - integer x: The x coordinate of the point.
3167
   - integer y: The y coordinate of the point.
3168
   - integer z: The z coordinate of the point.
3169

3170
   @since 1.1.0
3171
 */
3172
static int
3173
_elua_map_coord(lua_State *L) // Stack usage [-(6|9), +(7|10), em]
3174
{
3175
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3176
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3177
   Evas_Coord x, y, z;
3178
   int n;
3179

3180
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3181
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3182
   if (2 > n) return 0;
3183

3184
   if (_elua_scan_params(L, 2, "%x %y %z", &x, &y, &z) > 0)     // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3185
     {
3186
        evas_map_point_coord_set(elm->map, lua_tointeger(L, 2), x, y, z);
3187
        // Stack usage [-0, +0, -]
3188
     }
3189
   evas_map_point_coord_get(elm->map, lua_tointeger(L, 2), &x, &y, &z);
3190
   // Stack usage [-0, +0, -]
3191
   _elua_ret(L, "%x %y %z", x, y, z);
3192
   // Stack usage [-6, +7, em]
3193
   return 1;
3194
}
3195

3196
/**
3197
   @page luaref
3198
   @subsubsection map_lighting map_object:lighting(x, y, z, r, g, b, ar, ag, ab)
3199

3200
   Set the 3D lights for the map.  The three triplets can be tables.
3201

3202
   Wraps evas_map_util_3d_lighting().
3203

3204
   @param x The x coordinate of the light point.
3205
   @param y The y coordinate of the light point.
3206
   @param z The z coordinate of the light point.
3207
   @param r The new red value of the light point.
3208
   @param g The new green value of the light point.
3209
   @param b The new blue value of the light point.
3210
   @param ar The new red value of the ambient light.
3211
   @param ag The new green value of the ambient light.
3212
   @param ab The new blue value of the ambient light.
3213

3214
   @since 1.1.0
3215
 */
3216
static int
3217
_elua_map_lighting(lua_State *L) // Stack usage [-(0|9), +(0|9), e]
3218
{
3219
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3220
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3221
   Evas_Coord x, y, z;
3222
   int r, g, b, r1, g1, b1;
3223
   int n;
3224

3225
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3226

3227
   if ((n = _elua_scan_params(L, 2, "%x %y %z", &x, &y, &z)) > 0)
3228
     // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3229
     if (n += _elua_scan_params(L, 2 + n, "%r %g %b", &r, &g, &b) > 0)
3230
       // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3231
       if (_elua_scan_params(L, 2 + n, "%r %g %b", &r1, &g1, &b1) > 0) // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3232
         {
3233
            evas_map_util_3d_lighting(elm->map, x, y, z, r, g, b, r1, g1, b1);
3234
         }
3235
   return 0;
3236
}
3237

3238
/**
3239
   @page luaref
3240
   @subsubsection map_perspective map_object:perspective(x, y, z, f)
3241

3242
   Apply a perspective transform to the map.
3243

3244
   Wraps evas_map_util_3d_perspective().
3245

3246
   The arguments can be separate values, or named fields in a table.
3247

3248
   @param x The perspective distance X coordinate
3249
   @param y The perspective distance Y coordinate
3250
   @param z The "0" z plane value
3251
   @param f The focal distance
3252

3253
   @since 1.1.0
3254
 */
3255
static int
3256
_elua_map_perspective(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3257
{
3258
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3259
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3260
   Evas_Coord x, y, z, f;
3261

3262
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3263

3264
   if (_elua_scan_params(L, 2, "%x %y %z %f", &x, &y, &z, &f) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3265
     {
3266
        evas_map_util_3d_perspective(elm->map, x, y, z, f);
3267
     }
3268
   return 0;
3269
}
3270

3271
/**
3272
   @page luaref
3273
   @subsubsection map_populate map_object:populate(...)
3274

3275
   Populate the points in a map, in one of three different methods.
3276

3277
   1) Wraps evas_map_util_points_populate_from_object().
3278

3279
   @param source An evas object to copy points from.
3280

3281
   2) Wraps evas_map_util_paints_populate_from_object_full().
3282

3283
   @param source An evas object to copy points from.
3284
   @param z Common Z coordinate hint for all four points.
3285

3286
   3) Wraps evas_map_util_points_populate_from_geometry().
3287

3288
   The first four arguments can be separate values, or named fields in a table.
3289

3290
   @param x Point X coordinate
3291
   @param y Point Y coordinate
3292
   @param w Width to use to calculate second and third points.
3293
   @param h Height to use to calculate third and fourth points.
3294
   @param z Common Z coordinate hint for all four points.
3295

3296
   @since 1.1.0
3297
 */
3298
static int
3299
_elua_map_populate(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3300
{
3301
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3302
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3303
   int n;
3304

3305
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3306
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3307

3308
   switch (n)
3309
     {
3310
      case 2:
3311
      {
3312
         Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2);      // Stack usage [-0, +0, -]
3313
         const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3314

3315
         if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3316
         evas_map_util_points_populate_from_object(elm->map, source->evas_obj);
3317
         break;
3318
      }
3319

3320
      case 3:
3321
      {
3322
         Edje_Lua_Obj *obj2 = (Edje_Lua_Obj *)lua_touserdata(L, 2);      // Stack usage [-0, +0, -]
3323
         const Edje_Lua_Evas_Object *source = (Edje_Lua_Evas_Object *)obj2;
3324
         Evas_Coord z = lua_tointeger(L, 3);
3325

3326
         if (!_elua_isa(obj2, _elua_evas_meta)) return 0;
3327
         evas_map_util_points_populate_from_object_full(elm->map, source->evas_obj, z);
3328
         break;
3329
      }
3330

3331
      case 6:
3332
      {
3333
         Evas_Coord x, y, w, h;
3334

3335
         if ((n = _elua_scan_params(L, 2, "%x %y %w %h", &x, &y, &w, &h)) > 0) // Stack usage [-0, +0, m] unless it's in a table [-4, +4, e]
3336
           {
3337
              evas_map_util_points_populate_from_geometry(elm->map, x, y, w, h, lua_tointeger(L, 2 + n));
3338
           }
3339
         break;
3340
      }
3341
     }
3342
   return 0;
3343
}
3344

3345
/**
3346
   @page luaref
3347
   @subsubsection map_rotate map_object:rotate(degrees, x, y)
3348

3349
   Rotate the maps coordinates in 2D.
3350

3351
   Wraps evas_map_util_rotate().
3352

3353
   The coordinates can be separate values, or named fields in a table.
3354

3355
   @param degrees Amount of degrees from 0.0 to 360.0 to rotate.
3356
   @param x Rotation's centre horizontal position.
3357
   @param y Rotation's centre vertical position.
3358

3359
   @since 1.1.0
3360
 */
3361
static int
3362
_elua_map_rotate(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
3363
{
3364
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3365
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3366
   double degrees;
3367
   Evas_Coord x, y;
3368
   int n;
3369

3370
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3371
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3372
   if (4 != n) return 0;
3373

3374
   degrees = lua_tonumber(L, 2);
3375
   if (_elua_scan_params(L, 3, "%x %y", &x, &y) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3376
     {
3377
        evas_map_util_rotate(elm->map, degrees, x, y);
3378
     }
3379
   return 0;
3380
}
3381

3382
/**
3383
   @page luaref
3384
   @subsubsection map_rotate3d map_object:rotate3d(dx, dy, dz, x, y, z)
3385

3386
   Rotate the maps coordinates in 3D.
3387

3388
   Wraps evas_map_util_3d_rotate().
3389

3390
   The coordinates can be separate values, or named fields in a table.  The same
3391
   with the rotation.
3392

3393
   @param dx Amount of degrees from 0.0 to 360.0 to rotate around X axis.
3394
   @param dy Amount of degrees from 0.0 to 360.0 to rotate around Y axis.
3395
   @param dz Amount of degrees from 0.0 to 360.0 to rotate around Z axis.
3396
   @param x Rotation's centre horizontal position.
3397
   @param y Rotation's centre vertical position.
3398
   @param z Rotation's centre vertical position.
3399

3400
   @since 1.1.0
3401
 */
3402
static int
3403
_elua_map_rotate3d(lua_State *L) // Stack usage [-(0|6), +(0|6), e]
3404
{
3405
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3406
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3407
   double zx, zy, zz;
3408
   Evas_Coord x, y, z;
3409
   int n;
3410

3411
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3412

3413
   if ((n = _elua_scan_params(L, 2, "#x #y #z", &zx, &zy, &zz)) > 0)
3414
     // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3415
     if (_elua_scan_params(L, 2 + n, "%x %y %z", &x, &y, &z) > 0) // Stack usage [-0, +0, m] unless it's in a table [-3, +3, e]
3416
       {
3417
          evas_map_util_3d_rotate(elm->map, zx, zy, zz, x, y, z);
3418
       }
3419
   return 0;
3420
}
3421

3422
/**
3423
   @page luaref
3424
   @subsubsection map_smooth map_object:smooth(smooth)
3425

3426
   Get (and optionally set) the maps smooth mode.
3427

3428
   Wraps evas_map_smooth_set().
3429

3430
   @param smooth The smooth mode.
3431

3432
   Note that the argument is optional, without it this function just queries the
3433
   current value.
3434

3435
   @return A boolean reflecting the smooth mode.
3436

3437
   @since 1.1.0
3438
 */
3439
static int
3440
_elua_map_smooth(lua_State *L) // Stack usage [-0, +1, -]
3441
{
3442
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3443
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3444
   int n;
3445

3446
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3447

3448
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3449
   if (n == 2)
3450
     {
3451
        evas_map_smooth_set(elm->map, lua_toboolean(L, 2));
3452
        // Stack usage [-0, +0, -]
3453
     }
3454
   lua_pushboolean(L, evas_map_smooth_get(elm->map)); // Stack usage [-0, +1, -]
3455
   return 1;
3456
}
3457

3458
/**
3459
   @page luaref
3460
   @subsubsection map_uv map_object:uv(index, u, v)
3461

3462
   Gets (and optionally sets) the texture U and V texture coordinates for this map.
3463

3464
   Wraps evas_map_point_image_uv_set().
3465

3466
   @param index Index of the point to change. Must be smaller than map size.
3467
   @param u The X coordinate within the image/texture source.
3468
   @param v The Y coordinate within the image/texture source.
3469

3470
   Note that the U,V arguments are optional, without them this function just queries
3471
   the current values.  The coordinate arguments can be separate values, or named
3472
   fields in a table.
3473

3474
   @return A table with these fields:
3475
   - number u: The X coordinate within the image/texture source.
3476
   - number v: The Y coordinate within the image/texture source.
3477

3478
   @since 1.1.0
3479
 */
3480
static int
3481
_elua_map_uv(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3482
{
3483
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3484
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3485
   double u, v;
3486
   int n;
3487

3488
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3489
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3490
   if (2 > n) return 0;
3491

3492
   if (_elua_scan_params(L, 3, "#u #v", &u, &v) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3493
     {
3494
        evas_map_point_image_uv_set(elm->map, lua_tonumber(L, 2), u, v);
3495
        // Stack usage [-0, +0, -]
3496
     }
3497
   evas_map_point_image_uv_get(elm->map, lua_tonumber(L, 2), &u, &v);
3498
   // Stack usage [-0, +0, -]
3499
   _elua_ret(L, "#u #v", u, v);
3500
   // Stack usage [-4, +5, em]
3501
   return 1;
3502
}
3503

3504
/**
3505
   @page luaref
3506
   @subsubsection map_zoom map_object:zoom(x, y, x, y)
3507

3508
   Apply a zoom to the map.
3509

3510
   Wraps evas_map_util_zoom().
3511

3512
   The arguments can be two separate values, or named fields in a table.
3513

3514
   @param x The horizontal zoom amount.
3515
   @param y The vertical zoom amount.
3516
   @param x The X coordinate of the centre of the zoom.
3517
   @param y The Y coordinate of the centre of the zoom.
3518

3519
   @since 1.1.0
3520
 */
3521
static int
3522
_elua_map_zoom(lua_State *L) // Stack usage [-(0|4), +(0|4), e]
3523
{
3524
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3525
   Edje_Lua_Map *elm = (Edje_Lua_Map *)obj;
3526
   double zx, zy;
3527
   Evas_Coord x, y;
3528
   int n;
3529

3530
   if (!_elua_isa(obj, _elua_evas_map_meta)) return 0;
3531

3532
   if ((n = _elua_scan_params(L, 2, "#x #y", &zx, &zy)) > 0)
3533
     // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3534
     if (_elua_scan_params(L, 2 + n, "%x %y", &x, &y) > 0)      // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3535
       {
3536
          evas_map_util_zoom(elm->map, zx, zy, x, y);
3537
       }
3538
   return 0;
3539
}
3540

3541
//-------------
3542
//-------------
3543
/**
3544
   @page luaref
3545
   @subsection evas_polygon Evas polygon class.
3546

3547
   The lua evas polygon class includes functions for dealing with evas polygon objects.
3548
   The evas polygon objects must have been previously created by lua using the lua
3549
   polygon object creation function edje.polygon().
3550

3551
   In the following, "polygon_object" is a place holder for any lua variable that
3552
   holds a reference to an evas polygon object.
3553

3554
   @since 1.1.0
3555
 */
3556

3557
static int _elua_polygon_clear(lua_State *L);
3558
static int _elua_polygon_point(lua_State *L);
3559

3560
static const char *_elua_evas_polygon_api = "evas_polygon";
3561
static const char *_elua_evas_polygon_parent = "evas_polygon_parent";
3562
static const struct luaL_Reg _elua_evas_polygon_funcs [] =
3563
{
3564
   {"clear", _elua_polygon_clear},           // clear all polygon points
3565
   {"point", _elua_polygon_point},           // add a polygon point
3566

3567
   {NULL, NULL}   // end
3568
};
3569

3570
/**
3571
   @page luaref
3572
   @subsubsection polygon_clear polygon_object:clear()
3573

3574
   Clears all points from the polygon.
3575

3576
   Wraps evas_object_polygon_points_clear(),
3577

3578
   @since 1.1.0
3579
 */
3580
static int
3581
_elua_polygon_clear(lua_State *L) // Stack usage [-0, +0, -]
3582
{
3583
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3584
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3585

3586
   if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3587
   evas_object_polygon_points_clear(elo->evas_obj);
3588
   return 0;
3589
}
3590

3591
/**
3592
   @page luaref
3593
   @subsubsection polygon_point polygon_object:point(x, y)
3594

3595
   Adds a point to this polygon.
3596

3597
   Wraps evas_object_polygon_point_add().
3598

3599
   @param x The X coordinate of the point.
3600
   @param y The Y coordinate of the point.
3601

3602
   @since 1.1.0
3603
 */
3604
static int
3605
_elua_polygon_point(lua_State *L) // Stack usage [-(0|2), +(0|2), e]
3606
{
3607
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3608
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3609
   Evas_Coord x, y;
3610

3611
   if (!_elua_isa(obj, _elua_evas_polygon_meta)) return 0;
3612

3613
   if (_elua_scan_params(L, 2, "%x %y", &x, &y) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3614
     {
3615
        evas_object_polygon_point_add(elo->evas_obj, x, y);
3616
     }
3617

3618
   return 0;
3619
}
3620

3621
//-------------
3622
//-------------
3623
/**
3624
   @page luaref
3625
   @subsection evas_text Evas text class.
3626

3627
   The lua evas text class includes functions for dealing with evas text objects.
3628
   The evas text objects must have been previously created by lua using the lua
3629
   text object creation function edje.text().
3630

3631
   In the following, "text_object" is a place holder for any lua variable that
3632
   holds a reference to an evas text object.
3633

3634
   @since 1.1.0
3635
 */
3636

3637
static int _elua_text_font(lua_State *L);
3638
static int _elua_text_text(lua_State *L);
3639

3640
static const char *_elua_evas_text_api = "evas_text";
3641
static const char *_elua_evas_text_parent = "evas_text_parent";
3642
static const struct luaL_Reg _elua_evas_text_funcs [] =
3643
{
3644
   {"font", _elua_text_font},           // get or set text font
3645
   {"text", _elua_text_text},           // get or set text
3646
//     {"text_class", _elua_object_text_class}, // get or set object text class
3647

3648
   {NULL, NULL}   // end
3649
};
3650

3651
/**
3652
   @page luaref
3653
   @subsubsection text_font text_object:font(font, size)
3654

3655
   Gets, (and optionally sets) the font for this text object.
3656

3657
   Wraps evas_object_text_font_set().
3658

3659
   @param font The new font name.
3660
   @param size The new font size.
3661

3662
   Note that the font and size arguments are optional, without them this function
3663
   just queries the current values.  The font and size arguments can be separate
3664
   values, or named fields in a table.  The font name can refer to a font in the
3665
   edje file, or an external font.
3666

3667
   @return A table with these fields:
3668
   - string font: The font name.
3669
   - integer size: The font size.
3670

3671
   @since 1.1.0
3672
 */
3673
static int
3674
_elua_text_font(lua_State *L) // Stack usage [-(4|6), +(5|7), em]
3675
{
3676
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3677
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3678
   char *font, *font2 = NULL;
3679
   Evas_Font_Size size;
3680
   int inlined_font = 0;
3681

3682
   if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3683

3684
   if (_elua_scan_params(L, 2, "$font %size", &font, &size) > 0) // Stack usage [-0, +0, m] unless it's in a table [-2, +2, e]
3685
     {
3686
        /* Check if the font is embedded in the .edj
3687
         * This is a simple check.
3688
         * There is a much more complicated version in edje_text.c _edje_text_recalc_apply().
3689
         * If we need to get more complicated, we can do that later,
3690
         * and maybe refactor things.
3691
         */
3692
        if (obj->ed->file->fonts)
3693
          {
3694
             Edje_Font_Directory_Entry *fnt = eina_hash_find(obj->ed->file->fonts, font);
3695

3696
             if (fnt)
3697
               {
3698
                  size_t len = strlen(font) + sizeof("edje/fonts/") + 1;
3699
                  font2 = alloca(len);
3700
                  sprintf(font2, "edje/fonts/%s", font);
3701
                  font = font2;
3702
                  inlined_font = 1;
3703
                  font2 = NULL;
3704
               }
3705
          }
3706

3707
        if (inlined_font) evas_object_text_font_source_set(elo->evas_obj, obj->ed->path);
3708
        else evas_object_text_font_source_set(elo->evas_obj, NULL);
3709

3710
        evas_object_text_font_set(elo->evas_obj, font, size);
3711
     }
3712

3713
   // When one external API says it's gotta be const, and another one says not, then one of them's gotta be cast.  :-P
3714
   evas_object_text_font_get(elo->evas_obj, (const char **)&font, &size);
3715
   _elua_ret(L, "$font %size", font, size);
3716
   // Stack usage [-4, +5, em]
3717
   return 1;
3718
}
3719

3720
/**
3721
   @page luaref
3722
   @subsubsection text_text text_object:text(text)
3723

3724
   Get (and optionally set) the actual text for this text object.
3725

3726
   Wraps evas_object_text_text_set().
3727

3728
   @param text The text to set for this text object.
3729

3730
   Note that the argument is optional, without it this function just queries the
3731
   current value.
3732

3733
   @return A string of the text on this text object.
3734

3735
   @since 1.1.0
3736
 */
3737
static int
3738
_elua_text_text(lua_State *L) // Stack usage [-0, +1, m]
3739
{
3740
   Edje_Lua_Obj *obj = (Edje_Lua_Obj *)lua_touserdata(L, 1);    // Stack usage [-0, +0, -]
3741
   Edje_Lua_Evas_Object *elo = (Edje_Lua_Evas_Object *)obj;
3742
   int n;
3743

3744
   if (!_elua_isa(obj, _elua_evas_text_meta)) return 0;
3745
   n = lua_gettop(L); // Stack usage [-0, +0, -]
3746
   if (n == 2)
3747
     {
3748
        if (lua_isstring(L, 2))
3749
          {
3750
             const char *str;
3751

3752
             if ((str = lua_tostring(L, 2))) // Extra parenthesis, coz Mikes compiler has a lisp.
3753
               // Stack usage [-0, +0, m]
3754
               evas_object_text_text_set(elo->evas_obj, str);
3755
          }
3756
     }
3757
   lua_pushstring(L, evas_object_text_text_get(elo->evas_obj)); // Stack usage [-0, +1, m]
3758
   return 1;
3759
}
3760

3761
//--------------------------------------------------------------------------//
3762

3763
// A metatable and functions so that calling non existant API does not crash Lua scripts.
3764

3765
static int _elua_bogan_nilfunc(lua_State *L);
3766
static int _elua_bogan_index(lua_State *L);
3767

3768
static const struct luaL_Reg _elua_bogan_funcs [] =
3769
{
3770
   {"nilfunc", _elua_bogan_nilfunc},           // Just return a nil.
3771
   {"__index", _elua_bogan_index},             // Return the above func.
3772

3773
   {NULL, NULL}   // end
3774
};
3775

3776
static int
3777
_elua_bogan_nilfunc(lua_State *L)
3778
{
3779
   lua_getglobal(L, "nil");
3780
   return 1;
3781
}
3782

3783
static int
3784
_elua_bogan_index(lua_State *L)
3785
{
3786
   const char *key;
3787

3788
   key = lua_tostring(L, 2);
3789
   LE("%s does not exist!", key);
3790
   lua_pushcfunction(L, _elua_bogan_nilfunc);
3791
   return 1;
3792
}
3793

3794
static void
3795
_elua_bogan_protect(lua_State *L) // Stack usage [-3, +3, m]
3796
{
3797
   lua_pushnil(L); // Stack usage [-0, +1, -]
3798
   luaL_newmetatable(L, "bogan"); // Stack usage [-0, +1, m]
3799
#if LUA_VERSION_NUM >= 502
3800
   luaL_setfuncs(L, _elua_bogan_funcs, 0); // Stack usage [-0, +0, e]
3801
#else
3802
   luaL_register(L, 0, _elua_bogan_funcs); // Stack usage [-1, +1, m]
3803
#endif
3804
   lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3805
   lua_pop(L, 1); // Stack usage [-1, +0, -]
3806
}
3807

3808
//--------------------------------------------------------------------------//
3809

3810
// TODO - All the register / setfuncs and rlelated stuff around here should be reviewed.  Works fine for 5.1, probably works fine for 5.2, but maybe there's a better way?  It may also need to change if we start using LuaJIT.
3811

3812
// Brain dead inheritance thingy, built for speed.  Kinda.  Part 1.
3813
static void
3814
_elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base)  // Stack usage [-3, +5, m]  if inheriting [-6, +11, em]
3815
{
3816
   // Create an api table, fill it full of the methods.
3817
#if LUA_VERSION_NUM >= 502
3818
   lua_newtable(L); // Stack usage [-0, +1, e]
3819
   lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
3820
   lua_setglobal(L, api); // Stack usage [-1, +0, e]
3821
   luaL_setfuncs(L, funcs, 0); // Stack usage [-0, +0, e]
3822
#else
3823
   luaL_register(L, api, funcs); // Stack usage [-0, +1, m]
3824
#endif
3825
   // Set the api metatable to the bogan metatable.
3826
   luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
3827
   lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3828
   // Creat a meta metatable.
3829
   luaL_newmetatable(L, meta); // Stack usage [-0, +1, m]
3830
   // Put the gc functions in the metatable.
3831
#if LUA_VERSION_NUM >= 502
3832
   luaL_setfuncs(L, _elua_edje_gc_funcs, 0);  // Stack usage [-0, +0, e]
3833
#else
3834
   luaL_register(L, 0, _elua_edje_gc_funcs);  // Stack usage [-1, +1, m]
3835
#endif
3836
   // Create an __index entry in the metatable, make it point to the api table.
3837
   lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3838
   lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3839
   lua_rawset(L, -3); // Stack usage [-2, +0, m]
3840
   // Later this metatable is used as the metatable for newly created objects of this class.
3841

3842
   if (base && parent)
3843
     {
3844
        // Inherit from base
3845
        lua_getglobal(L, base); // Stack usage [-0, +1, e]
3846
        // Create a new parent metatable.
3847
        luaL_newmetatable(L, parent); // Stack usage [-0, +1, m]
3848
        // Create an __index entry in the metatable, make it point to the base table.
3849
        lua_pushliteral(L, "__index"); // Stack usage [-0, +1, m]
3850
        lua_pushvalue(L, -3); // Stack usage [-0, +1, -]
3851
        lua_rawset(L, -3); // Stack usage [-2, +0, m]
3852
        // Set the metatable for the api table to the parent metatable.
3853
        lua_getglobal(L, api); // Stack usage [-0, +1, e]
3854
        luaL_getmetatable(L, parent); // Stack usage [-0, +1, -]
3855
        lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
3856
     }
3857
}
3858

3859
// Brain dead inheritance thingy, built for speed.  Kinda.  Part 2.
3860
static Eina_Bool
3861
_elua_isa(Edje_Lua_Obj *obj, const char *type)
3862
{
3863
   Eina_Bool isa = EINA_FALSE;
3864

3865
   if (!obj) return isa;
3866
   if (obj->meta == type)
3867
     isa = EINA_TRUE;
3868
   if (_elua_evas_meta == type)
3869
     {
3870
        if (obj->meta == _elua_evas_image_meta)
3871
          isa = EINA_TRUE;
3872
        else if (obj->meta == _elua_evas_text_meta)
3873
          isa = EINA_TRUE;
3874
        else if (obj->meta == _elua_evas_edje_meta)
3875
          isa = EINA_TRUE;
3876
        else if (obj->meta == _elua_evas_line_meta)
3877
          isa = EINA_TRUE;
3878
        else if (obj->meta == _elua_evas_polygon_meta)
3879
          isa = EINA_TRUE;
3880
     }
3881
   return isa;
3882
}
3883

3884
#ifndef RASTER_FORGOT_WHY
3885
static void
3886
_elua_init(void) // Stack usage [-16, +20, em]
3887
{
3888
   static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3889
   Edje_Lua_Allocator *al;
3890
   const luaL_Reg *l;
3891
   lua_State *L;
3892

3893
   if (lstate) return;
3894

3895
   lstate = L = luaL_newstate();
3896
   al = lua_newuserdata(L, sizeof(Edje_Lua_Allocator));
3897
   al->ref = luaL_ref(L, LUA_REGISTRYINDEX);
3898
   al->func = lua_getallocf(L, &(al->ud));
3899
   al->ela = &ela;
3900
   lua_setallocf(L, _elua_alloc, al); // Stack usage [-0, +0, -]
3901
   lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3902

3903
// FIXME: figure out optimal gc settings later
3904
//   lua_gc(L, LUA_GCSETPAUSE, 200);                                                       // Stack usage [-0, +0, e]
3905
//   lua_gc(L, LUA_GCSETSTEPMUL, 200);                                                     // Stack usage [-0, +0, e]
3906

3907
   for (l = _elua_libs; l->func; l++) // Currently * 4
3908
     {
3909
#if LUA_VERSION_NUM >= 502
3910
        luaL_requiref(L, l->name, l->func, 1); // Stack usage [-0, +1, e]
3911
#else
3912
        lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3913
        lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3914
        lua_call(L, 1, 0); // Stack usage [-2, +0, e]
3915
#endif
3916
     }
3917

3918
#if LUA_VERSION_NUM >= 502
3919
   lua_newtable(L); // Stack usage [-0, +1, e]
3920
   lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
3921
   lua_setglobal(L, _elua_edje_api); // Stack usage [-1, +0, e]
3922
   luaL_setfuncs(L, _elua_edje_funcs, 0); // Stack usage [-0, +0, e]
3923
#else
3924
   luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
3925
#endif
3926
   luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
3927
#if LUA_VERSION_NUM >= 502
3928
   luaL_setfuncs(L, _elua_edje_gc_funcs, 0); // Stack usage [-0, +0, e]
3929
#else
3930
   luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
3931
#endif
3932

3933
   _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL);  // Stack usage [-3, +5, m]
3934

3935
   // weak table for our objects
3936
   lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
3937
   lua_newtable(L); // Stack usage [-0, +1, m]
3938
   lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
3939
   lua_pushstring(L, "kv"); // Stack usage [-0, +1, m]
3940
   lua_rawset(L, -3); // Stack usage [-2, +0, m]
3941
   lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
3942
}
3943

3944
#endif
3945

3946
void
3947
_edje_lua2_script_init(Edje *ed) // Stack usage [-63, +99, em]
3948
{
3949
   static Edje_Lua_Alloc ela = { MAX_LUA_MEM, 0 };
3950
   Edje_Lua_Allocator *al;
3951
   const luaL_Reg *l;
3952
   char buf[256];
3953
   void *data;
3954
   int size;
3955
   lua_State *L;
3956

3957
   if (ed->L) return;
3958
   if (0 > _log_domain)
3959
     _log_domain = eina_log_domain_register("lua", NULL);
3960
   if (0 <= _log_domain)
3961
     {
3962
        _log_count++;
3963
        eina_log_domain_level_set("lua", EINA_LOG_LEVEL_WARN);
3964
     }
3965

3966
#ifndef RASTER_FORGOT_WHY
3967
   _elua_init(); // This is actually truly pointless, even if raster remembers.
3968
#endif
3969
   L = ed->L = luaL_newstate();
3970
   if (!L)
3971
     {
3972
        ERR("Lua state assign failed");
3973
        return;
3974
     }
3975
   al = lua_newuserdata(L, sizeof(Edje_Lua_Allocator));
3976
   al->ref = luaL_ref(L, LUA_REGISTRYINDEX);
3977
   al->func = lua_getallocf(L, &(al->ud));
3978
   al->ela = &ela;
3979
   lua_setallocf(L, _elua_alloc, al); // Stack usage [-0, +0, -]
3980
   lua_atpanic(L, _elua_custom_panic); // Stack usage [-0, +0, -]
3981

3982
// FIXME: figure out optimal gc settings later
3983
//   lua_gc(L, LUA_GCSETPAUSE, 200);                              // Stack usage [-0, +0, e]
3984
//   lua_gc(L, LUA_GCSETSTEPMUL, 200);                            // Stack usage [-0, +0, e]
3985

3986
   for (l = _elua_libs; l->func; l++) // Currently * 4
3987
     {
3988
#if LUA_VERSION_NUM >= 502
3989
        luaL_requiref(L, l->name, l->func, 1); // Stack usage [-0, +1, e]
3990
#else
3991
        lua_pushcfunction(L, l->func); // Stack usage [-0, +1, m]
3992
        lua_pushstring(L, l->name); // Stack usage [-0, +1, m]
3993
        lua_call(L, 1, 0); // Stack usage [-2, +0, m]
3994
#endif
3995
     }
3996

3997
   _elua_bogan_protect(L); // Stack usage [+3, -3, m]
3998

3999
#if LUA_VERSION_NUM >= 502
4000
   lua_newtable(L); // Stack usage [-0, +1, e]
4001
   lua_pushvalue(L, -1); // Stack usage [-0, +1, -]
4002
   lua_setglobal(L, _elua_edje_api); // Stack usage [-1, +0, e]
4003
   luaL_setfuncs(L, _elua_edje_funcs, 0); // Stack usage [-0, +0, e]
4004
#else
4005
   luaL_register(L, _elua_edje_api, _elua_edje_funcs); // Stack usage [-0, +1, m]
4006
#endif
4007
   luaL_getmetatable(L, "bogan"); // Stack usage [-0, +1, -]
4008
   lua_setmetatable(L, -2); // Stack usage [-1, +0, -]
4009
   luaL_newmetatable(L, _elua_edje_meta); // Stack usage [-0, +1, m]
4010
#if LUA_VERSION_NUM >= 502
4011
   luaL_setfuncs(L, _elua_edje_gc_funcs, 0); // Stack usage [-0, +0, e]
4012
#else
4013
   luaL_register(L, 0, _elua_edje_gc_funcs); // Stack usage [-1, +1, m]
4014
#endif
4015

4016
   lua_pop(L, 2); // Stack usage [-n, +0, -]
4017

4018
   _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL);
4019
   // Stack usage [-3, +5, m]
4020
   _elua_add_functions(L, _elua_ecore_timer_api, _elua_ecore_timer_funcs, _elua_ecore_timer_meta, NULL, NULL);
4021
   // Stack usage [-3, +5, m]
4022
   _elua_add_functions(L, _elua_ecore_animator_api, _elua_ecore_animator_funcs, _elua_ecore_animator_meta, NULL, NULL);
4023
   // Stack usage [-6, +11, m]
4024
   _elua_add_functions(L, _elua_evas_edje_api, _elua_evas_edje_funcs, _elua_evas_edje_meta, _elua_evas_edje_parent, _elua_evas_api);
4025
   // Stack usage [-6, +11, em]
4026
   _elua_add_functions(L, _elua_evas_image_api, _elua_evas_image_funcs, _elua_evas_image_meta, _elua_evas_image_parent, _elua_evas_api);
4027
   // Stack usage [-6, +11, em]
4028
   _elua_add_functions(L, _elua_evas_line_api, _elua_evas_line_funcs, _elua_evas_line_meta, _elua_evas_line_parent, _elua_evas_api);
4029
   // Stack usage [-6, +11, em]
4030
   _elua_add_functions(L, _elua_evas_map_api, _elua_evas_map_funcs, _elua_evas_map_meta, NULL, NULL);
4031
   // Stack usage [-3, +5, m]
4032
   _elua_add_functions(L, _elua_evas_polygon_api, _elua_evas_polygon_funcs, _elua_evas_polygon_meta, _elua_evas_polygon_parent, _elua_evas_api);
4033
   // Stack usage [-6, +11, em]
4034
   _elua_add_functions(L, _elua_evas_text_api, _elua_evas_text_funcs, _elua_evas_text_meta, _elua_evas_text_parent, _elua_evas_api);
4035
   // Stack usage [-6, +11, em]
4036

4037
   // weak table for our objects
4038
   lua_pushlightuserdata(L, &_elua_objs); // Stack usage [-0, +1, -]
4039
   lua_newtable(L); // Stack usage [-0, +1, m]
4040
   lua_pushstring(L, "__mode"); // Stack usage [-0, +1, m]
4041
   lua_pushstring(L, "kv"); // Stack usage [-0, +1, m]
4042
   lua_rawset(L, -3); // Stack usage [-2, +0, m]
4043
   lua_rawset(L, LUA_REGISTRYINDEX); // Stack usage [-2, +0, m]
4044

4045
   _elua_table_ptr_set(L, _elua_key, ed); // Stack usage [-2, +2, e]
4046

4047
   snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", ed->collection->id);
4048
   data = eet_read(ed->file->ef, buf, &size);
4049

4050
   if (data)
4051
     {
4052
        int err;
4053

4054
        /* This ends up pushing a function onto the stack for the lua_pcall() below to use.
4055
         * The function is the compiled code. */
4056
        err = luaL_loadbuffer(L, data, size, "edje_lua_script");  // Stack usage [-0, +1, m]
4057
        if (err)
4058
          {
4059
             if (err == LUA_ERRSYNTAX)
4060
               ERR("Lua load syntax error: %s",
4061
                   lua_tostring(L, -1));  // Stack usage [-0, +0, m]
4062
             else if (err == LUA_ERRMEM)
4063
               ERR("Lua load memory allocation error: %s",
4064
                   lua_tostring(L, -1));  // Stack usage [-0, +0, m]
4065
          }
4066
        free(data);
4067
        /* This is not needed, pcalls don't longjmp(), that's why they are protected.
4068
           if (setjmp(panic_jmp) == 1)
4069
           {
4070
             ERR("Lua script init panic");
4071
             return;
4072
           }
4073
         */
4074
        if ((err = lua_pcall(L, 0, 0, 0))) // Stack usage [-1, +0, -]
4075
          _edje_lua2_error(L, err);  // Stack usage [-0, +0, m]
4076
     }
4077
}
4078

4079
void
4080
_edje_lua2_script_shutdown(Edje *ed)
4081
{
4082
   Edje_Lua_Allocator *al;
4083
   void *ud;
4084
   if (!ed->L) return;
4085
   lua_getallocf(ed->L, &ud);
4086
   al = ud;
4087
   // restore old allocator to close the state
4088
   lua_setallocf(ed->L, al->func, al->ud);
4089
   luaL_unref(ed->L, LUA_REGISTRYINDEX, al->ref);
4090
   lua_close(ed->L);  // Stack usage irrelevant, as it's all gone now.
4091
   ed->L = NULL;
4092
   while (ed->lua_objs)
4093
     {
4094
        Edje_Lua_Obj *obj = (Edje_Lua_Obj *)ed->lua_objs;
4095
        if (obj->free_func)
4096
          {
4097
             ERR("uncollected Lua object %p", obj);
4098
             ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
4099
          }
4100
        else
4101
          {
4102
             ERR("dangling Lua object %p", obj);
4103
             ed->lua_objs = eina_inlist_remove(ed->lua_objs, ed->lua_objs);
4104
          }
4105
     }
4106

4107
   if (0 <= _log_domain)
4108
     {
4109
        _log_count--;
4110
        if (0 >= _log_count)
4111
          {
4112
             eina_log_domain_unregister(_log_domain);
4113
             _log_domain = -1;
4114
          }
4115
     }
4116
}
4117

4118
void
4119
_edje_lua2_script_load(Edje_Part_Collection *edc EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED)  // Stack usage [-16, +20, em]
4120
{
4121
#ifndef RASTER_FORGOT_WHY
4122
   _elua_init();  // Stack usage [-16, +20, em]
4123
#endif
4124
}
4125

4126
void
4127
_edje_lua2_script_unload(Edje_Part_Collection *edc EINA_UNUSED)  // Stack usage [-0, +0, e]
4128
{
4129
#ifndef RASTER_FORGOT_WHY
4130
   lua_State *L;
4131

4132
   if (!lstate) return;
4133
   L = lstate;
4134
   lua_gc(L, LUA_GCCOLLECT, 0);  // Stack usage [-0, +0, e]
4135
#endif
4136
}
4137

4138
void
4139
_edje_lua2_error_full(const char *file, const char *fnc, int line,
4140
                      lua_State *L, int err_code) // Stack usage [-0, +0, m]
4141
{
4142
   const char *err_type;
4143

4144
   switch (err_code)
4145
     {
4146
      case LUA_ERRRUN:
4147
        err_type = "runtime";
4148
        break;
4149

4150
      case LUA_ERRSYNTAX:
4151
        err_type = "syntax";
4152
        break;
4153

4154
      case LUA_ERRMEM:
4155
        err_type = "memory allocation";
4156
        break;
4157

4158
      case LUA_ERRERR:
4159
        err_type = "error handler";
4160
        break;
4161

4162
      default:
4163
        err_type = "unknown";
4164
        break;
4165
     }
4166
   eina_log_print
4167
     (_edje_default_log_dom, EINA_LOG_LEVEL_ERR, file, fnc, line,
4168
     "Lua %s error: %s", err_type, lua_tostring(L, -1));   // Stack usage [-0, +0, m]
4169
}
4170

4171
/**
4172
   @page luaref
4173
   @section callbacks Lua callbacks
4174

4175
   These are lua functions that are called by the lua edje system when certain
4176
   events occur.  If the functions don't exist in the lua group, they don't get
4177
   called.
4178

4179
 */
4180

4181
/**
4182
   @page luaref
4183
   @subsection edje_shutdown Edje shutdown() callback.
4184

4185
   If a function called "shutdown" exists in a lua edje group, then it is called when
4186
   that edje gets deleted.
4187
 */
4188
void
4189
_edje_lua2_script_func_shutdown(Edje *ed) // Stack usage [-1, +1, em]
4190
{
4191
   int err;
4192

4193
   lua_getglobal(ed->L, "shutdown"); // Stack usage [-0, +1, e]
4194
   if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4195
     {
4196
        if ((err = lua_pcall(ed->L, 0, 0, 0))) // Stack usage [-1, +0, -]
4197
          _edje_lua2_error(ed->L, err);  // Stack usage [-0, +0, m]
4198
     }
4199
   else
4200
     lua_pop(ed->L, 1);  // Stack usage [-n, +0, -]
4201
   _edje_lua2_script_shutdown(ed);
4202
}
4203

4204
/**
4205
   @page luaref
4206
   @subsection edje_show Edje show() callback.
4207

4208
   If a function called "show" exists in a lua edje group, then it is called when
4209
   that edje gets shown.
4210
 */
4211
void
4212
_edje_lua2_script_func_show(Edje *ed)  // Stack usage [-1, +1, e]
4213
{
4214
   int err;
4215

4216
   lua_getglobal(ed->L, "show");
4217
   if (!lua_isnil(ed->L, -1))
4218
     {
4219
        if ((err = lua_pcall(ed->L, 0, 0, 0)))
4220
          _edje_lua2_error(ed->L, err);
4221
     }
4222
   else
4223
     lua_pop(ed->L, 1);
4224
}
4225

4226
/**
4227
   @page luaref
4228
   @subsection edje_hide Edje hide() callback.
4229

4230
   If a function called "hide" exists in a lua edje group, then it is called when
4231
   that edje gets hidden.
4232
 */
4233
void
4234
_edje_lua2_script_func_hide(Edje *ed)  // Stack usage [-1, +1, e]
4235
{
4236
   int err;
4237

4238
   lua_getglobal(ed->L, "hide");
4239
   if (!lua_isnil(ed->L, -1))
4240
     {
4241
        if ((err = lua_pcall(ed->L, 0, 0, 0)))
4242
          _edje_lua2_error(ed->L, err);
4243
     }
4244
   else
4245
     lua_pop(ed->L, 1);
4246
}
4247

4248
/**
4249
   @page luaref
4250
   @subsection edje_move Edje move(x, y) callback.
4251

4252
   If a function called "move" exists in a lua edje group, then it is called when
4253
   that edje gets moved, with the new position passed to it.
4254
 */
4255
void
4256
_edje_lua2_script_func_move(Edje *ed)  // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4257
{
4258
   int err;
4259

4260
   // FIXME: move all objects created by script
4261
   lua_getglobal(ed->L, "move"); // Stack usage [-0, +1, e]
4262
   if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4263
     {
4264
        lua_pushinteger(ed->L, ed->x); // Stack usage [-0, +1, -]
4265
        lua_pushinteger(ed->L, ed->y); // Stack usage [-0, +1, -]
4266
        if ((err = lua_pcall(ed->L, 2, 0, 0))) // Stack usage [-3, +0, -]
4267
          _edje_lua2_error(ed->L, err);
4268
     }
4269
   else
4270
     lua_pop(ed->L, 1);  // Stack usage [-n, +0, -]
4271
}
4272

4273
/**
4274
   @page luaref
4275
   @subsection edje_resize Edje resize(w, h) callback.
4276

4277
   If a function called "resize" exists in a lua edje group, then it is called when
4278
   that edje gets resized, with the new size passed to it.
4279
 */
4280
void
4281
_edje_lua2_script_func_resize(Edje *ed)  // Stack usage [-3, +3, e] or [-1, +1, e] if no matching function.
4282
{
4283
   int err;
4284

4285
   lua_getglobal(ed->L, "resize");
4286
   if (!lua_isnil(ed->L, -1))
4287
     {
4288
        lua_pushinteger(ed->L, ed->w);
4289
        lua_pushinteger(ed->L, ed->h);
4290
        if ((err = lua_pcall(ed->L, 2, 0, 0)))
4291
          _edje_lua2_error(ed->L, err);
4292
     }
4293
   else
4294
     lua_pop(ed->L, 1);
4295
}
4296

4297
/**
4298
   @page luaref
4299
   @subsection edje_message Edje message(id, type, ...) callback.
4300

4301
   If a function called "message" exists in a lua edje group, then it is called when
4302
   that edje gets gets a message sent to it, with the message details passed to it.
4303
   See edje.messagesend() for details of what each type means.  The arrays are
4304
   passed as a table.
4305
 */
4306
void
4307
_edje_lua2_script_func_message(Edje *ed, Edje_Message *em)  // Stack usage [-?, +?, em]  It's complicated, but it's even at least.
4308
{
4309
   int err, n, c, i;
4310

4311
   lua_getglobal(ed->L, "message"); // Stack usage [-0, +1, e]
4312
   if (!lua_isnil(ed->L, -1)) // Stack usage [-0, +0, -]
4313
     {
4314
        n = 2;
4315
        lua_pushinteger(ed->L, em->id); // Stack usage [-0, +1, -]
4316
        switch (em->type)
4317
          {
4318
           case EDJE_MESSAGE_NONE:
4319
             lua_pushstring(ed->L, "none"); // Stack usage [-0, +1, m]
4320
             break;
4321

4322
           case EDJE_MESSAGE_SIGNAL:
4323
             break;
4324

4325
           case EDJE_MESSAGE_STRING:
4326
             lua_pushstring(ed->L, "str"); // Stack usage [-0, +1, m]
4327
             lua_pushstring(ed->L, ((Edje_Message_String *)em->msg)->str);
4328
             // Stack usage [-0, +1, m]
4329
             n += 1;
4330
             break;
4331

4332
           case EDJE_MESSAGE_INT:
4333
             lua_pushstring(ed->L, "int"); // Stack usage [-0, +1, m]
4334
             lua_pushinteger(ed->L, ((Edje_Message_Int *)em->msg)->val);
4335
             // Stack usage [-0, +1, -]
4336
             n += 1;
4337
             break;
4338

4339
           case EDJE_MESSAGE_FLOAT:
4340
             lua_pushstring(ed->L, "float"); // Stack usage [-0, +1, m]
4341
             lua_pushnumber(ed->L, ((Edje_Message_Float *)em->msg)->val);
4342
             // Stack usage [-0, +1, -]
4343
             n += 1;
4344
             break;
4345

4346
           case EDJE_MESSAGE_STRING_SET:
4347
             lua_pushstring(ed->L, "strset"); // Stack usage [-0, +1, m]
4348
             c = ((Edje_Message_String_Set *)em->msg)->count;
4349
             lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4350
             for (i = 0; i < c; i++)
4351
               {
4352
                  lua_pushstring(ed->L, ((Edje_Message_String_Set *)em->msg)->str[i]);
4353
                  // Stack usage [-0, +1, m]
4354
                  // It's OK to bypass the metatable in these cases,
4355
                  // we create the table, and know there is no metatable.  B-)
4356
                  lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4357
               }
4358
             n += 1;
4359
             break;
4360

4361
           case EDJE_MESSAGE_INT_SET:
4362
             lua_pushstring(ed->L, "intset"); // Stack usage [-0, +1, m]
4363
             c = ((Edje_Message_Int_Set *)em->msg)->count;
4364
             lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4365
             for (i = 0; i < c; i++)
4366
               {
4367
                  lua_pushinteger(ed->L, ((Edje_Message_Int_Set *)em->msg)->val[i]);
4368
                  // Stack usage [-0, +1, -]
4369
                  lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4370
               }
4371
             n += 1;
4372
             break;
4373

4374
           case EDJE_MESSAGE_FLOAT_SET:
4375
             lua_pushstring(ed->L, "floatset"); // Stack usage [-0, +1, m]
4376
             c = ((Edje_Message_Float_Set *)em->msg)->count;
4377
             lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4378
             for (i = 0; i < c; i++)
4379
               {
4380
                  lua_pushnumber(ed->L, ((Edje_Message_Float_Set *)em->msg)->val[i]);
4381
                  // Stack usage [-0, +1, -]
4382
                  lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4383
               }
4384
             n += 1;
4385
             break;
4386

4387
           case EDJE_MESSAGE_STRING_INT:
4388
             lua_pushstring(ed->L, "strint"); // Stack usage [-0, +1, m]
4389
             lua_pushstring(ed->L, ((Edje_Message_String_Int *)em->msg)->str);
4390
             // Stack usage [-0, +1, m]
4391
             lua_pushinteger(ed->L, ((Edje_Message_String_Int *)em->msg)->val);
4392
             // Stack usage [-0, +1, -]
4393
             n += 2;
4394
             break;
4395

4396
           case EDJE_MESSAGE_STRING_FLOAT:
4397
             lua_pushstring(ed->L, "strfloat"); // Stack usage [-0, +1, m]
4398
             lua_pushstring(ed->L, ((Edje_Message_String_Float *)em->msg)->str);
4399
             // Stack usage [-0, +1, m]
4400
             lua_pushnumber(ed->L, ((Edje_Message_String_Float *)em->msg)->val);
4401
             // Stack usage [-0, +1, -]
4402
             n += 2;
4403
             break;
4404

4405
           case EDJE_MESSAGE_STRING_INT_SET:
4406
             lua_pushstring(ed->L, "strintset"); // Stack usage [-0, +1, m]
4407
             lua_pushstring(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->str);
4408
             // Stack usage [-0, +1, m]
4409
             c = ((Edje_Message_String_Int_Set *)em->msg)->count;
4410
             lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4411
             for (i = 0; i < c; i++)
4412
               {
4413
                  lua_pushinteger(ed->L, ((Edje_Message_String_Int_Set *)em->msg)->val[i]);
4414
                  // Stack usage [-0, +1, -]
4415
                  lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4416
               }
4417
             n += 2;
4418
             break;
4419

4420
           case EDJE_MESSAGE_STRING_FLOAT_SET:
4421
             lua_pushstring(ed->L, "strfloatset"); // Stack usage [-0, +1, m]
4422
             lua_pushstring(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->str);
4423
             // Stack usage [-0, +1, m]
4424
             c = ((Edje_Message_String_Float_Set *)em->msg)->count;
4425
             lua_createtable(ed->L, c, 0); // Stack usage [-0, +1, m]
4426
             for (i = 0; i < c; i++)
4427
               {
4428
                  lua_pushnumber(ed->L, ((Edje_Message_String_Float_Set *)em->msg)->val[i]);
4429
                  // Stack usage [-0, +1, -]
4430
                  lua_rawseti(ed->L, -2, i + 1); // Stack usage [-1, +0, m]
4431
               }
4432
             n += 2;
4433
             break;
4434

4435
           default:
4436
             break;
4437
          }
4438
        if ((err = lua_pcall(ed->L, n, 0, 0))) // Stack usage [-n+1, +0, -]
4439
          _edje_lua2_error(ed->L, err);
4440
     }
4441
   else
4442
     lua_pop(ed->L, 1);  // Stack usage [-n, +0, -]
4443
}
4444

4445
/**
4446
   @page luaref
4447
   @subsection edje_signal Edje signal(signal, source) callback.
4448

4449
   If a function called "signal" exists in a lua edje group, then it is called when
4450
   ever a signal arrives, with the signal details passed to it.
4451

4452
 */
4453
void
4454
_edje_lua2_script_func_signal(Edje *ed, const char *sig, const char *src)  // Stack usage [-3, +3, em] or [-1, +1, e] if no matching function.
4455
{
4456
   int err;
4457

4458
   lua_getglobal(ed->L, "signal");
4459
   if (!lua_isnil(ed->L, -1))
4460
     {
4461
        lua_pushstring(ed->L, sig);
4462
        lua_pushstring(ed->L, src);
4463
        if ((err = lua_pcall(ed->L, 2, 0, 0)))
4464
          _edje_lua2_error(ed->L, err);
4465
     }
4466
   else
4467
     lua_pop(ed->L, 1);
4468
}
4469

4470

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.