seed r387 - in trunk: libseed modules/sqlite
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r387 - in trunk: libseed modules/sqlite
- Date: Fri, 5 Dec 2008 03:15:38 +0000 (UTC)
Author: racarr
Date: Fri Dec 5 03:15:37 2008
New Revision: 387
URL: http://svn.gnome.org/viewvc/seed?rev=387&view=rev
Log:
Lots more API...flesh out sqlite bindings. a little.
Modified:
trunk/libseed/seed-api.c
trunk/libseed/seed.h
trunk/modules/sqlite/seed-sqlite.c
Modified: trunk/libseed/seed-api.c
==============================================================================
--- trunk/libseed/seed-api.c (original)
+++ trunk/libseed/seed-api.c Fri Dec 5 03:15:37 2008
@@ -1,5 +1,10 @@
#include "seed-private.h"
+JSValueRef seed_make_null(JSContextRef ctx)
+{
+ return JSValueMakeNull(ctx);
+}
+
JSObjectRef seed_make_object(JSContextRef ctx,
JSClassRef class,
gpointer private)
@@ -78,3 +83,25 @@
JSStringRelease(string);
}
+JSClassRef seed_create_class(JSClassDefinition * def)
+{
+ return JSClassCreate(def);
+}
+
+JSObjectRef seed_make_constructor(JSContextRef ctx,
+ JSClassRef class,
+ JSObjectCallAsConstructorCallback constructor)
+{
+ return JSObjectMakeConstructor(ctx, class, constructor);
+}
+
+gpointer seed_object_get_private(JSObjectRef object)
+{
+ return (gpointer)JSObjectGetPrivate(object);
+}
+
+void seed_object_set_private(JSObjectRef object, gpointer value)
+{
+ JSObjectSetPrivate(object, value);
+}
+
Modified: trunk/libseed/seed.h
==============================================================================
--- trunk/libseed/seed.h (original)
+++ trunk/libseed/seed.h Fri Dec 5 03:15:37 2008
@@ -88,9 +88,14 @@
* seed-api.c
*/
+SeedValue seed_make_null(SeedContext ctx);
+
SeedObject seed_make_object(SeedContext ctx,
SeedClass class, gpointer private);
+gpointer seed_object_get_private(SeedObject object);
+void seed_object_set_private(SeedObject object, gpointer value);
+
SeedString seed_string_ref(SeedString string);
void seed_string_unref(SeedString string);
@@ -106,10 +111,12 @@
/*
* seed-types.c
*/
-gboolean seed_object_set_property(SeedObject object,
+gboolean seed_object_set_property(SeedContext ctx,
+ SeedObject object,
const gchar * name,
SeedValue value);
-SeedValue seed_object_get_property(SeedObject object,
+SeedValue seed_object_get_property(SeedContext ctx,
+ SeedObject object,
const gchar * name);
gboolean seed_value_to_boolean(SeedContext ctx,
@@ -288,6 +295,7 @@
typedef struct _seed_class_definition
{
+ int version; /* Always 0 */
SeedClassAttributes attributes;
const gchar * class_name;
@@ -309,6 +317,32 @@
SeedObjectConvertToTypeCallback convert_to_type;
} seed_class_definition;
+seed_class_definition seed_empty_class =
+{
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+SeedClass seed_create_class(seed_class_definition * def);
+
+SeedObject seed_make_constructor(SeedContext ctx,
+ SeedClass class,
+ SeedObjectCallAsConstructorCallback constructor);
Modified: trunk/modules/sqlite/seed-sqlite.c
==============================================================================
--- trunk/modules/sqlite/seed-sqlite.c (original)
+++ trunk/modules/sqlite/seed-sqlite.c Fri Dec 5 03:15:37 2008
@@ -1,16 +1,15 @@
#include "../../libseed/seed.h"
#include <sqlite3.h>
+SeedObject namespace_ref;
+SeedClass sqlite_class;
+
#define MAKE_ERROR_ENUM(name) \
- seed_object_set_property(namespace_ref, #name, \
+ seed_object_set_property(eng->context, namespace_ref, #name, \
seed_value_from_int(eng->context, SQLITE_##name, 0))
-void seed_module_init(SeedEngine * eng)
+void define_errors(SeedEngine * eng)
{
- SeedObject namespace_ref = seed_make_object(eng->context, 0, 0);
-
- seed_object_set_property(eng->global, "sqlite", namespace_ref);
-
MAKE_ERROR_ENUM(OK);
MAKE_ERROR_ENUM(ERROR);
MAKE_ERROR_ENUM(INTERNAL);
@@ -40,3 +39,60 @@
MAKE_ERROR_ENUM(ROW);
MAKE_ERROR_ENUM(DONE);
}
+
+void sqlite_database_finalize(SeedObject object)
+{
+ sqlite3 * db = seed_object_get_private(object);
+ if (db)
+ sqlite3_close(db);
+}
+
+SeedObject sqlite_construct_database(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException * exception)
+{
+ SeedObject ret;
+ gchar * file;
+ sqlite3 * db;
+ int rc;
+
+ if (argument_count != 1)
+ {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "sqlite.Database constructor expected 1 argument");
+ return (SeedObject)seed_make_null(ctx);
+ }
+ file = seed_value_to_string(ctx, arguments[0], exception);
+
+ rc = sqlite3_open(file, &db);
+
+ ret = seed_make_object(ctx, sqlite_class, db);
+ seed_object_set_property(ctx, ret, "status",
+ seed_value_from_int(ctx, rc, exception));
+
+ return ret;
+}
+
+void seed_module_init(SeedEngine * eng)
+{
+ SeedObject db_constructor;
+ seed_class_definition sqlite_class_def = seed_empty_class;
+
+ namespace_ref = seed_make_object(eng->context, 0, 0);
+
+ seed_object_set_property(eng->context,
+ eng->global, "sqlite", namespace_ref);
+
+ sqlite_class_def.class_name = "Database";
+ sqlite_class_def.finalize = sqlite_database_finalize;
+
+ sqlite_class = seed_create_class(&sqlite_class_def);
+
+ db_constructor = seed_make_constructor(eng->context,
+ sqlite_class,
+ sqlite_construct_database);
+ seed_object_set_property(eng->context,
+ namespace_ref, "Database", db_constructor);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]