[seed] Start fleshing out the os module a little bit...aiming for identical to the python one as much as po



commit 437f98900823b3311087d6c42d122129684d3f06
Author: Robert Carr <racarr mireia (none)>
Date:   Mon Apr 13 20:30:40 2009 -0400

    Start fleshing out the os module a little bit...aiming for identical to the python one as much as possible
---
 configure.ac            |    1 +
 libseed/seed-importer.c |   24 ++++++++++++-
 modules/Makefile.am     |    2 +-
 modules/os/Makefile.am  |   25 +++++++++++++
 modules/os/os.c         |   93 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4eabc8d..827a881 100644
--- a/configure.ac
+++ b/configure.ac
@@ -290,6 +290,7 @@ modules/sqlite/Makefile
 modules/canvas/Makefile
 modules/readline/Makefile
 modules/Multiprocessing/Makefile
+modules/os/Makefile
 ])
 AC_OUTPUT
 
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index b010a2c..c7d7d43 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -50,6 +50,10 @@ GHashTable *file_imports;
  *        for that context.
  */
 
+/* 
+* Handle definition of toplevel functions in a namespace.
+* i.e. Gtk.main
+*/
 static void
 seed_gi_importer_handle_function (JSContextRef ctx,
 				  JSObjectRef namespace_ref,
@@ -61,6 +65,12 @@ seed_gi_importer_handle_function (JSContextRef ctx,
   g_base_info_ref ((GIBaseInfo *) info);
 }
 
+/*
+ * Handle definition of enums in a namespace.
+ * Each enum class gets an object containing
+ * a value for each member, all in uppercase
+ * i.e. Gtk.WindowType.NORMAL
+ */
 static void
 seed_gi_importer_handle_enum (JSContextRef ctx,
 			      JSObjectRef namespace_ref,
@@ -105,6 +115,11 @@ seed_gi_importer_handle_enum (JSContextRef ctx,
     }
 }
 
+/*
+ * Handle setting up the prototype and constructor for a GObject type
+ * Namespace.Type will be the constructor and Namespace.Type.prototype is
+ * the prototype object. Namespace.Type.type will be the GType.
+ */
 static void
 seed_gi_importer_handle_object (JSContextRef ctx,
 				JSObjectRef namespace_ref,
@@ -175,6 +190,10 @@ seed_gi_importer_handle_object (JSContextRef ctx,
     }
 }
 
+/*
+ * Set up prototype and constructor for structs. Same semantics as objects except
+ * for the type.
+ */
 static void
 seed_gi_importer_handle_struct (JSContextRef ctx,
 				JSObjectRef namespace_ref,
@@ -261,6 +280,9 @@ seed_gi_importer_handle_callback (JSContextRef ctx,
 			    (JSValueRef) callback_ref);
 }
 
+/* 
+ * Define constants toplevel. Uses the casing as in the typelib
+ */
 static void
 seed_gi_importer_handle_constant (JSContextRef ctx,
 				  JSObjectRef namespace_ref,
@@ -764,7 +786,7 @@ JSClassDefinition gi_importer_class_def = {
   NULL,                         /* Initialize */
   NULL,				/* Finalize */
   NULL,				/* Has Property */
-  seed_gi_importer_get_property,	/* Get Property */
+  seed_gi_importer_get_property,/* Get Property */
   NULL,				/* Set Property */
   NULL,				/* Delete Property */
   NULL,				/* Get Property Names */
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 6549541..7335b2d 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -1 +1 @@
-SUBDIRS = example sqlite canvas Multiprocessing readline
+SUBDIRS = example sqlite canvas Multiprocessing readline os
diff --git a/modules/os/Makefile.am b/modules/os/Makefile.am
new file mode 100644
index 0000000..b4b52b8
--- /dev/null
+++ b/modules/os/Makefile.am
@@ -0,0 +1,25 @@
+lib_LTLIBRARIES = \
+	libos.la
+
+libos_la_SOURCES = \
+	os.c
+
+libos_la_LDFLAGS = \
+	`pkg-config --libs seed`
+
+AM_CPPFLAGS = \
+	-I../../libseed/ \
+	`pkg-config --cflags seed` \
+	`pkg-config --cflags glib-2.0` -g \
+	`pkg-config --cflags gobject-introspection-1.0` \
+	$(SEED_DEBUG_CFLAGS)
+
+AM_LDFLAGS = 
+
+if PROFILE_MODULES
+	AM_CPPFLAGS += $(SEED_PROFILE_CFLAGS)
+	AM_LDFLAGS += $(SEED_PROFILE_LDFLAGS)
+endif
+
+libdir = ${exec_prefix}/lib/seed
+
diff --git a/modules/os/os.c b/modules/os/os.c
new file mode 100644
index 0000000..b1a93c6
--- /dev/null
+++ b/modules/os/os.c
@@ -0,0 +1,93 @@
+#include <seed.h>
+#define _GNU_SOURCE
+#include <unistd.h>
+
+SeedObject os_namespace;
+
+#define EXPECTED_EXCEPTION(name, argnum) \
+  gchar *mes = g_strdup_printf (name " expected " argnum " got %d", argument_count); \
+  seed_make_exception (ctx, exception, "ArgumentError", mes); \
+  g_free (mes); \
+  return seed_make_null (ctx);
+
+SeedValue
+seed_os_chdir (SeedContext ctx,
+	       SeedObject function,
+	       SeedObject this_object,
+	       size_t argument_count,
+	       const SeedValue arguments[], 
+	       SeedException * exception)
+{
+  gchar *arg;
+  gint ret;
+  
+  if (argument_count != 1)
+    {
+      EXPECTED_EXCEPTION("os.chdir", "1 argument");
+    }
+  arg = seed_value_to_string (ctx, arguments[0], exception);
+  ret = chdir (arg);
+  g_free (arg);
+  
+  return seed_value_from_int (ctx, ret, exception);
+}
+
+SeedValue
+seed_os_fchdir (SeedContext ctx,
+	       SeedObject function,
+	       SeedObject this_object,
+	       size_t argument_count,
+	       const SeedValue arguments[], 
+	       SeedException * exception)
+{
+  gint ret, arg;
+  
+  if (argument_count != 1)
+    {
+      EXPECTED_EXCEPTION("os.fchdir", "1 argument");
+    }
+  arg = seed_value_to_int (ctx, arguments[0], exception);
+  ret = fchdir (arg);
+  
+  return seed_value_from_int (ctx, ret, exception);
+}
+
+SeedValue
+seed_os_getcwd (SeedContext ctx,
+		SeedObject function,
+		SeedObject this_object,
+		size_t argument_count,
+		const SeedValue arguments[], 
+		SeedException * exception)
+{
+  SeedValue seed_ret;
+  gchar *ret;
+  
+  if (argument_count != 0)
+    {
+      EXPECTED_EXCEPTION("os.getcwd", "no arguments");
+    }
+  ret = getcwd (NULL, 0);
+  seed_ret = seed_value_from_string (ctx, ret, exception);
+  g_free (ret);
+  
+  return seed_ret;
+}
+
+seed_static_function os_funcs[] = {
+  {"chdir", seed_os_chdir, 0},
+  {"fchdir", seed_os_fchdir, 0},
+  {"getcwd", seed_os_getcwd, 0}
+};
+
+SeedObject
+seed_module_init(SeedEngine * eng)
+{
+  SeedClass os_namespace_class;
+  seed_class_definition os_namespace_class_definition = seed_empty_class;
+  
+  os_namespace_class_definition.static_functions = os_funcs;
+  os_namespace_class = seed_create_class (&os_namespace_class_definition);
+
+  os_namespace = seed_make_object (eng->context, os_namespace_class, NULL);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]