~ubuntu-branches/ubuntu/wily/lua-lgi/wily-proposed

« back to all changes in this revision

Viewing changes to lgi/core.c

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2015-08-14 21:07:46 UTC
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20150814210746-zu65vvq9bi1q0yhr
Tags: upstream-0.9.0
ImportĀ upstreamĀ versionĀ 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#define G_REC_MUTEX_INIT
25
25
#endif
26
26
 
 
27
/* GLib 2.30 changed g_atomic_int_add() to return the new value. For
 
28
   older GLib versions, use g_atomic_int_exchange_and_add() which did. */
 
29
#if !GLIB_CHECK_VERSION(2, 30, 0)
 
30
#ifdef g_atomic_int_add
 
31
#undef g_atomic_int_add
 
32
#endif
 
33
 
 
34
#define g_atomic_int_add(atomic, val) \
 
35
  (g_atomic_int_exchange_and_add ((atomic), (val)))
 
36
#endif
 
37
 
 
38
volatile gint global_state_id = 0;
 
39
 
27
40
#ifndef NDEBUG
28
41
const char *lgi_sd (lua_State *L)
29
42
{
110
123
  int n = 1;
111
124
  lua_pushstring (L, g_base_info_get_namespace (info));
112
125
 
 
126
  if (g_base_info_get_type (info) == GI_INFO_TYPE_CALLBACK)
 
127
    /* Avoid duplicate name for callbacks. */
 
128
    info = g_base_info_get_container (info);
 
129
 
113
130
  /* Add names on the whole path, but in reverse order. */
114
131
  for (; info != NULL; info = g_base_info_get_container (info))
115
132
    if (!GI_IS_TYPE_INFO (info))
538
555
  return 2;
539
556
}
540
557
 
 
558
static int core_upcase (lua_State *L)
 
559
{
 
560
  gchar *str = g_ascii_strup (luaL_checkstring (L, 1), -1);
 
561
  lua_pushstring (L, str);
 
562
  g_free (str);
 
563
  return 1;
 
564
}
 
565
 
 
566
static int core_downcase (lua_State *L)
 
567
{
 
568
  gchar *str = g_ascii_strdown (luaL_checkstring (L, 1), -1);
 
569
  lua_pushstring (L, str);
 
570
  g_free (str);
 
571
  return 1;
 
572
}
 
573
 
541
574
static const struct luaL_Reg lgi_reg[] = {
542
575
  { "log",  core_log },
543
576
  { "gtype", core_gtype },
548
581
  { "band", core_band },
549
582
  { "bor", core_bor },
550
583
  { "module", core_module },
 
584
  { "upcase", core_upcase },
 
585
  { "downcase", core_downcase },
551
586
  { NULL, NULL }
552
587
};
553
588
 
623
658
luaopen_lgi_corelgilua51 (lua_State* L)
624
659
{
625
660
  LgiStateMutex *mutex;
 
661
  gint state_id;
626
662
 
627
663
  /* Try to make itself resident.  This is needed because this dynamic
628
664
     module is 'statically' linked with glib/gobject, and these
682
718
  lua_newtable (L);
683
719
  luaL_register (L, NULL, lgi_reg);
684
720
 
 
721
  /* Add the state ID */
 
722
  state_id = g_atomic_int_add (&global_state_id, 1);
 
723
  if (state_id == 0)
 
724
    lua_pushliteral (L, "");
 
725
  else
 
726
    lua_pushfstring (L, "+L%d", state_id);
 
727
  lua_setfield (L, -2, "id");
 
728
 
 
729
  /* Add lock and enter/leave locking functions. */
 
730
  lua_pushlightuserdata (L, lgi_state_get_lock (L));
 
731
  lua_setfield (L, -2, "lock");
 
732
  lua_pushlightuserdata (L, lgi_state_enter);
 
733
  lua_setfield (L, -2, "enter");
 
734
  lua_pushlightuserdata (L, lgi_state_leave);
 
735
  lua_setfield (L, -2, "leave");
 
736
 
685
737
  /* Create repo and index table. */
686
738
  create_repo_table (L, "index", &repo_index);
687
739
  create_repo_table (L, "repo", &repo);