1 /* -*- mode: C; indent-tabs-mode: t; tab-width: 8; c-basic-offset: 2; -*- */
4 * This file is part of Seed, the GObject Introspection<->Javascript bindings.
6 * Seed is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 * Seed is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with Seed. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) Robert Carr 2009 <carrr@rpi.edu>
22 #include <glib-object.h>
23 #include "../libseed/seed.h"
24 #include "../libseed/seed-debug.h"
25 #include <girepository.h>
28 #define DEFAULT_PATH "."
31 gboolean seed_interpreter_arg_print_version;
32 gchar *seed_interpreter_arg_exec_string;
34 gboolean seed_interpreter_parse_args (int *argc, char ***argv);
42 script = seed_make_script (eng->context, "repl = imports.repl", NULL, 0);
44 if ((e = seed_script_exception (script)))
46 g_critical ("%s", seed_exception_to_string (eng->context, e));
50 seed_evaluate (eng->context, script, 0);
52 if ((e = seed_script_exception (script)))
54 g_critical ("%s", seed_exception_to_string (eng->context, e));
62 seed_exec (gchar * filename)
69 g_file_get_contents (filename, &buffer, 0, 0);
73 g_critical ("File %s not found!", filename);
79 while (*buffer != '\n')
84 script = seed_make_script (eng->context, buffer, filename, 1);
86 if ((e = seed_script_exception (script)))
88 g_critical ("%s", seed_exception_to_string (eng->context, e));
92 global = seed_context_get_global_object (eng->context);
93 seed_importer_add_global (global, filename);
95 seed_evaluate (eng->context, script, 0);
96 if ((e = seed_script_exception (script)))
98 g_critical ("%s", seed_exception_to_string (eng->context, e));
108 SeedException e = NULL;
113 seed_simple_evaluate (eng->context, seed_interpreter_arg_exec_string, &e);
117 g_critical ("%s", seed_exception_to_string (eng->context, e));
122 val_str = seed_value_to_string (eng->context, val, &e);
125 g_critical ("%s", seed_exception_to_string (eng->context, e));
129 g_print ("%s\n", val_str);
130 g_free (seed_interpreter_arg_exec_string);
139 main (gint argc, gchar ** argv)
141 g_set_prgname ("seed");
142 g_thread_init (NULL);
144 seed_interpreter_parse_args (&argc, &argv);
146 if (seed_interpreter_arg_print_version)
148 g_print ("%s\n", "Seed " VERSION);
152 eng = seed_init (&argc, &argv);
154 seed_engine_set_search_path (eng, DEFAULT_PATH);
156 if (seed_interpreter_arg_exec_string)