static int mod_load_servlet(lua_State *l) { const char *path = luaL_checkstring(l, -1); SCM module = scm_c_define_module(path, NULL, NULL); SCM prev_module = scm_set_current_module(module); // TODO: don't define these functions every time for each servlet scm_c_define_gsubr("get_arg", 2, 0, 0, &api_get_arg); scm_c_define_gsubr("get_method", 1, 0, 0, &api_get_method); scm_c_define_gsubr("get_header", 2, 0, 0, &api_get_header); scm_c_define_gsubr("set_status", 2, 0, 0, &api_set_status); scm_c_define_gsubr("set_header", 3, 0, 0, &api_set_header); scm_c_define_gsubr("rwrite", 2, 0, 0, &api_rwrite); scm_c_define_gsubr("rflush", 1, 0, 0, &api_rflush); SCM foo = scm_c_primitive_load(path); SCM run_symbol = scm_c_lookup("run"); SCM run_ref = scm_variable_ref(run_symbol); scm_set_current_module(prev_module); lua_newtable(l); lua_pushlightuserdata(l, (void*)run_ref); lua_pushcclosure(l, servlet_run, 1); lua_setfield(l, -2, "run"); return 1; }
static void inner_main_add_price_quotes(void *closure, int argc, char **argv) { SCM mod, add_quotes, scm_book, scm_result = SCM_BOOL_F; QofSession *session = NULL; scm_c_eval_string("(debug-set! stack 200000)"); mod = scm_c_resolve_module("gnucash price-quotes"); scm_set_current_module(mod); load_gnucash_modules(); qof_event_suspend(); scm_c_eval_string("(gnc:price-quotes-install-sources)"); if (!gnc_quote_source_fq_installed()) { g_print("%s", _("No quotes retrieved. Finance::Quote isn't " "installed properly.\n")); goto fail; } add_quotes = scm_c_eval_string("gnc:book-add-quotes"); session = gnc_get_current_session(); if (!session) goto fail; qof_session_begin(session, add_quotes_file, FALSE, FALSE); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; qof_session_load(session, NULL); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; scm_book = gnc_book_to_scm(qof_session_get_book(session)); scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book); qof_session_save(session, NULL); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; qof_session_destroy(session); if (!scm_is_true(scm_result)) { g_warning("Failed to add quotes to %s.", add_quotes_file); goto fail; } qof_event_resume(); gnc_shutdown(0); return; fail: if (session && qof_session_get_error(session) != ERR_BACKEND_NO_ERR) g_warning("Session Error: %s", qof_session_get_error_message(session)); qof_event_resume(); gnc_shutdown(1); }
void weechat_guile_unload (struct t_plugin_script *script) { int *rc; void *interpreter; char *filename; if ((weechat_guile_plugin->debug >= 2) || !guile_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), GUILE_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } filename = strdup (script->filename); interpreter = script->interpreter; if (guile_current_script == script) guile_current_script = (guile_current_script->prev_script) ? guile_current_script->prev_script : guile_current_script->next_script; plugin_script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script, script); if (interpreter) weechat_guile_catch (scm_gc_unprotect_object, interpreter); if (guile_current_script) scm_set_current_module ((SCM)(guile_current_script->interpreter)); (void) weechat_hook_signal_send ("guile_script_unloaded", WEECHAT_HOOK_SIGNAL_STRING, filename); if (filename) free (filename); }
/* Start the LazyCat main procedure. */ static void inner_main (void* closure, int argc, char** argv) { SCM main; SCM args; SCM module; scm_c_define_module ("lazycat prctl", init_prctl_module, NULL); module = scm_c_resolve_module ("lazycat daemon lazycatd"); scm_set_current_module (module); scm_c_define_gsubr ("c-set-lazycat-signals", 0, 0, 0, set_lazycat_signals); scm_c_export ("c-set-lazycat-signals", NULL); main = scm_c_module_lookup (module, "main"); args = scm_program_arguments (); scm_call_1 (scm_variable_ref (main), args); }
void * weechat_guile_exec (struct t_plugin_script *script, int ret_type, const char *function, char *format, void **argv) { struct t_plugin_script *old_guile_current_script; SCM rc, old_current_module; void *argv2[17], *ret_value; int i, argc, *ret_int; old_guile_current_script = guile_current_script; old_current_module = NULL; if (script->interpreter) { old_current_module = scm_current_module (); scm_set_current_module ((SCM)(script->interpreter)); } guile_current_script = script; if (argv && argv[0]) { argc = strlen (format); for (i = 0; i < argc; i++) { switch (format[i]) { case 's': /* string */ argv2[i] = scm_from_locale_string ((char *)argv[i]); break; case 'i': /* integer */ argv2[i] = scm_from_int (*((int *)argv[i])); break; case 'h': /* hash */ argv2[i] = weechat_guile_hashtable_to_alist (argv[i]); break; } } for (i = argc; i < 17; i++) { argv2[i] = SCM_UNDEFINED; } rc = weechat_guile_exec_function (function, (SCM *)argv2, argc); } else { rc = weechat_guile_exec_function (function, NULL, 0); } ret_value = NULL; if ((ret_type == WEECHAT_SCRIPT_EXEC_STRING) && (scm_is_string (rc))) { ret_value = scm_to_locale_string (rc); } else if ((ret_type == WEECHAT_SCRIPT_EXEC_INT) && (scm_is_integer (rc))) { ret_int = malloc (sizeof (*ret_int)); if (ret_int) *ret_int = scm_to_int (rc); ret_value = ret_int; } else if (ret_type == WEECHAT_SCRIPT_EXEC_HASHTABLE) { ret_value = weechat_guile_alist_to_hashtable (rc, WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING); } else { weechat_printf (NULL, weechat_gettext ("%s%s: function \"%s\" must return " "a valid value"), weechat_prefix ("error"), GUILE_PLUGIN_NAME, function); } if (ret_value == NULL) { weechat_printf (NULL, weechat_gettext ("%s%s: error in function \"%s\""), weechat_prefix ("error"), GUILE_PLUGIN_NAME, function); } if (old_current_module) scm_set_current_module (old_current_module); guile_current_script = old_guile_current_script; return ret_value; }
static void inner_main (void *closure, int argc, char **argv) { SCM main_mod; char* fn; GError *error = NULL; scm_c_eval_string("(debug-set! stack 200000)"); main_mod = scm_c_resolve_module("gnucash main"); scm_set_current_module(main_mod); load_gnucash_modules(); /* Load the config before starting up the gui. This insures that * custom reports have been read into memory before the Reports * menu is created. */ load_system_config(); load_user_config(); /* Setting-up the report menu must come after the module loading but before the gui initialization. */ scm_c_use_module("gnucash report report-gnome"); scm_c_eval_string("(gnc:report-menu-setup)"); /* TODO: After some more guile-extraction, this should happen even before booting guile. */ gnc_main_gui_init(); gnc_hook_add_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit, NULL); scm_c_eval_string("(gnc:main)"); /* Install Price Quote Sources */ gnc_update_splash_screen(_("Checking Finance::Quote..."), GNC_SPLASH_PERCENTAGE_UNKNOWN); scm_c_use_module("gnucash price-quotes"); scm_c_eval_string("(gnc:price-quotes-install-sources)"); gnc_hook_run(HOOK_STARTUP, NULL); if (!nofile && (fn = get_file_to_load())) { gnc_update_splash_screen(_("Loading data..."), GNC_SPLASH_PERCENTAGE_UNKNOWN); gnc_file_open_file(fn); g_free(fn); } else if (gnc_gconf_get_bool("dialogs/new_user", "first_startup", &error) && !error) { gnc_destroy_splash_screen(); gnc_ui_new_user_dialog(); } gnc_destroy_splash_screen(); gnc_main_window_show_all_windows(); gnc_hook_run(HOOK_UI_POST_STARTUP, NULL); gnc_ui_start_event_loop(); gnc_hook_remove_dangler(HOOK_UI_SHUTDOWN, (GFunc)gnc_file_quit); gnc_shutdown(0); return; }