libgeda

scheme_toplevel.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library - Scheme API
00003  * Copyright (C) 2010-2012 Peter Brett <peter@peter-b.co.uk>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
00018  */
00019 
00025 #include <config.h>
00026 
00027 #include "libgeda_priv.h"
00028 #include "libgedaguile_priv.h"
00029 
00030 SCM scheme_toplevel_fluid = SCM_UNDEFINED;
00031 
00042 void
00043 edascm_dynwind_toplevel (TOPLEVEL *toplevel)
00044 {
00045   SCM s_toplevel = edascm_from_toplevel (toplevel);
00046 
00047   scm_dynwind_fluid (scheme_toplevel_fluid, s_toplevel);
00048 }
00049 
00056 SCM_DEFINE (edascm_current_toplevel, "%current-toplevel", 0, 0, 0,
00057             (),
00058             "Get the TOPLEVEL for the current dynamic context.")
00059 {
00060   return scm_fluid_ref (scheme_toplevel_fluid);
00061 }
00062 
00072 TOPLEVEL *
00073 edascm_c_current_toplevel ()
00074 {
00075   SCM s_toplevel = edascm_current_toplevel ();
00076 
00077   EDASCM_ASSERT_SMOB_VALID(s_toplevel);
00078 
00079   return (TOPLEVEL *) SCM_SMOB_DATA (s_toplevel);
00080 }
00081 
00087 SCM_DEFINE (edascm_with_toplevel, "%with-toplevel", 2, 0, 0,
00088             (SCM toplevel, SCM thunk),
00089             "Call `thunk', setting the TOPLEVEL fluid to `toplevel'.")
00090 {
00091   return scm_with_fluid (scheme_toplevel_fluid, toplevel, thunk);
00092 }
00093 
00101 SCM
00102 edascm_c_with_toplevel (TOPLEVEL *toplevel, SCM (*func)(void *),
00103                         void *user_data)
00104 {
00105   SCM s_toplevel = edascm_from_toplevel (toplevel);
00106   return scm_c_with_fluid (scheme_toplevel_fluid, s_toplevel, func, user_data);
00107 }
00108 
00115 static void
00116 init_module_geda_core_toplevel ()
00117 {
00118   /* Register the functions */
00119   #include "scheme_toplevel.x"
00120 
00121   /* Add them to the module's public definitions. */
00122   scm_c_export (s_edascm_with_toplevel, s_edascm_current_toplevel, NULL);
00123 }
00124 
00132 void
00133 edascm_init_toplevel ()
00134 {
00135   scheme_toplevel_fluid = scm_permanent_object (scm_make_fluid ());
00136 
00137   /* Define the (geda core toplevel) module */
00138   scm_c_define_module ("geda core toplevel",
00139                        init_module_geda_core_toplevel,
00140                        NULL);
00141 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines