seed r51 - in trunk: . examples extensions libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r51 - in trunk: . examples extensions libseed
- Date: Sun, 2 Nov 2008 06:03:37 +0000 (UTC)
Author: racarr
Date: Sun Nov 2 06:03:37 2008
New Revision: 51
URL: http://svn.gnome.org/viewvc/seed?rev=51&view=rev
Log:
Add an "extensions" system. very rudimentary. Idea is you can create a
/usr/local/share/seed/Gio.js, which can add methods to prototypes of Gio
objects. Useful for making extensions to things which are useful in
javascript, say packing an array into a GtkBox.
Fixes I forgot to commit from earlier from tim, return 0 for null from
integer conversion functions.
Added:
trunk/extensions/
trunk/extensions/Gio.js (contents, props changed)
Modified:
trunk/Makefile
trunk/examples/quine.js
trunk/libseed/seed-builtins.c
trunk/libseed/seed-engine.c
trunk/libseed/seed-types.c
Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Sun Nov 2 06:03:37 2008
@@ -3,6 +3,8 @@
gcc `pkg-config --cflags --libs gstreamer-0.10 glib-2.0 webkit-1.0 gobject-introspection-1.0` *.c -g -o seed -L libseed -lseed -lreadline -lffi
install:
cp libseed/libseed.so /usr/local/lib
- cp ./seed /usr/local/bin/seed
+ cp ./seed /usr/local/bin/seed
+ mkdir -p /usr/local/share/seed
+ cp extensions/* /usr/local/share/seed
test:
cd tests ; ./run-tests.py
Modified: trunk/examples/quine.js
==============================================================================
--- trunk/examples/quine.js (original)
+++ trunk/examples/quine.js Sun Nov 2 06:03:37 2008
@@ -3,7 +3,5 @@
file = Gio.file_new_for_path(Seed.argv[1])
input = file.read();
-stream = Gio.DataInputStream._new(input);
-line = stream.read_until("", 0);
-Seed.print(line);
\ No newline at end of file
+Seed.print(input.get_contents());
\ No newline at end of file
Added: trunk/extensions/Gio.js
==============================================================================
--- (empty file)
+++ trunk/extensions/Gio.js Sun Nov 2 06:03:37 2008
@@ -0,0 +1,8 @@
+prototype = Seed.prototype(Gio.FileInputStream);
+
+prototype.get_contents = function()
+{
+ stream = Gio.DataInputStream._new(input);
+ line = stream.read_until("", 0);
+ return line;
+}
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Sun Nov 2 06:03:37 2008
@@ -33,12 +33,8 @@
{
const gchar * import_file;
gchar * buffer, * walk;
- GValue gval = {0};
- seed_gvalue_from_seed_value((SeedValue)arguments[0], G_TYPE_STRING, &gval);
- g_assert(G_VALUE_HOLDS_STRING(&gval));
-
- import_file = g_value_get_string(&gval);
+ import_file = seed_value_to_string(arguments[0]);
g_file_get_contents(import_file, &buffer, 0, 0);
@@ -118,6 +114,26 @@
return valstr;
}
+JSValueRef
+seed_prototype(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef * exception)
+{
+ GType type;
+
+ if (argumentCount != 1)
+ return JSValueMakeNull(eng->context);
+ if (!JSValueIsObject(eng->context, arguments[0]))
+ return JSValueMakeNull(eng->context);
+
+ type = (GType)JSObjectGetPrivate((JSObjectRef)arguments[0]);
+
+ return seed_gobject_get_prototype_for_gtype(type);
+}
+
void seed_init_builtins(int * argc, char *** argv)
{
int i;
@@ -128,6 +144,7 @@
seed_create_function("include", &seed_include, obj);
seed_create_function("print", &seed_print, obj);
seed_create_function("readline", &seed_readline, obj);
+ seed_create_function("prototype", &seed_prototype, obj);
arrayObj = JSObjectMake(eng->context, NULL, NULL);
Modified: trunk/libseed/seed-engine.c
==============================================================================
--- trunk/libseed/seed-engine.c (original)
+++ trunk/libseed/seed-engine.c Sun Nov 2 06:03:37 2008
@@ -546,11 +546,7 @@
cproperty_name);
if (!spec)
{
- //gchar * mes = g_strdup_printf("No such property: %s on object of type %s \n",
- // cproperty_name, g_type_name(G_OBJECT_TYPE(obj)));
- // seed_make_exception(exception, "InvalidProperty", mes)
- //g_free(mes);
- g_free(cproperty_name);
+ g_free(cproperty_name);
return 0;
}
}
@@ -590,8 +586,10 @@
{
GIBaseInfo * info;
const gchar * namespace;
+ const gchar * extension;
const gchar * version = 0;
JSObjectRef namespace_ref;
+ JSStringRef extension_script;
int n,i;
namespace = seed_value_to_string(arguments[0]);
@@ -620,7 +618,7 @@
(g_base_info_get_type(info) == GI_INFO_TYPE_FUNCTION))
{
seed_gobject_define_property_from_function_info(
- (GIFunctionInfo *) info, namespace_ref, FALSE);
+ (GIFunctionInfo *) info, namespace_ref, FALSE);
}
else if (info &&
(g_base_info_get_type(info) == GI_INFO_TYPE_ENUM))
@@ -697,16 +695,20 @@
(gpointer)type);
- n_methods = g_object_info_get_n_methods((GIObjectInfo *)info);
+ n_methods =
+ g_object_info_get_n_methods((GIObjectInfo *)info);
for (i = 0; i < n_methods; i++)
{
- finfo = g_object_info_get_method((GIObjectInfo *)info, i);
+ finfo =
+ g_object_info_get_method(
+ (GIObjectInfo *)info, i);
flags = g_function_info_get_flags(finfo);
if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
{
- seed_gobject_define_property_from_function_info(finfo,
- constructor_ref,
- FALSE);
+ seed_gobject_define_property_from_function_info(
+ finfo,
+ constructor_ref,
+ FALSE);
}
else
{
@@ -726,6 +728,13 @@
}
}
+
+
+ extension = g_strdup_printf("Seed.include(\"/usr/local/share/seed/%s.js\")",
+ namespace);
+ extension_script = JSStringCreateWithUTF8CString(extension);
+ JSEvaluateScript(eng->context, extension_script, NULL, NULL, 0, NULL);
+ JSStringRelease(extension_script);
g_free((gchar *)namespace);
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Sun Nov 2 06:03:37 2008
@@ -693,6 +693,9 @@
{
if(!JSValueIsBoolean(eng->context, val))
{
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
+
seed_value_wrong_type();
return 0;
}
@@ -709,7 +712,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -725,7 +729,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -743,7 +748,8 @@
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -769,7 +775,8 @@
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -793,7 +800,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -809,7 +817,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -825,7 +834,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -841,7 +851,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -857,7 +868,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
@@ -873,7 +885,8 @@
{
if(!JSValueIsNumber(eng->context, val))
{
- seed_value_wrong_type();
+ if(!JSValueIsNull(eng->context, val))
+ seed_value_wrong_type();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]