Re: libseed-list trying to read a gio stream
- From: Tim Horton <hortont424 gmail com>
- To: Jonatan Liljedahl <lijon kymatica com>
- Cc: libseed-list gnome org
- Subject: Re: libseed-list trying to read a gio stream
- Date: Tue, 24 Nov 2009 23:17:12 -0500
On Nov 24, 2009, at 22:54, Jonatan Liljedahl wrote:
> Ah, I just found the get_contents() and simple_read() extensions. But I would like to understand this (in Gio.simple_read):
>
> var fstream = file.read();
> var dstream = new Gio.DataInputStream.c_new(fstream); //<-- here
> var line = dstream.read_until("", 0);
>
> why the need for creating a DataInputStream from the FileInputStream, and what about the use of both new operator and c_new() method?
I don't know anything about the reasoning behind the first one (I'm still new to the G* stack) - I'll ask racarr at some point, but we're on thanksgiving break at the moment, so he's not here :-)
The second thing; I'm not remembering exactly, but I think that's right; read the most upvoted comment here, perhaps:
http://stackoverflow.com/questions/383402/is-javascript-s-new-keyword-considered-harmful
I don't know that that actually applies, but at least it provides consistency :-) (it's very likely that this is all something I'm making up, too! sorry!)
Unless you're asking about the c_new function's existence at all (not sure that's documented), to which I'll just note that that's how you use g_data_input_stream_new directly, instead of through the JSON property-setting interface that Seed normally uses, which you need if the _new function takes any arguments which you want to set.
> Thanks for the pointer on taking a look in the tests tree, will do that!
Yeah; it's all not-very-commented or anything, but they're usually really short, which is nice... and the filenames are only *sort of* annoying to guess.
> BTW, are extension .js modules automatically merged when importing a C or gi module? If I have a seed module in an .so and a .js with the same name, will both be loaded by imports.<name>?
If I were to guess from memory/briefly glance over the source code, it looks like it only happens when importing a gi module.That may not be true, and it's likely not the *right* thing to do (why not have JS extensions for C modules?! seems reasonable)
> /Jonatan
>
> Tim Horton wrote:
>> There are numerous examples in the seed-examples git repo that do the following:
>> file = Gio.file_new_for_path(filename);
>> content = file.read().get_contents();
>> I think get_contents() is a seed extension, but I don't remember. There's also Gio.simple_read (another seed extension):
>> http://git.gnome.org/cgit/seed/tree/extensions/Gio.js
>> Also, out arguments work like so:
>> http://git.gnome.org/cgit/seed/tree/tests/javascript/out-test.js
>> (there's a lot of good stuff/demonstrations of stuff that hasn't been documented yet in the tests tree)
>> On Nov 24, 2009, at 22:37, Jonatan Liljedahl wrote:
>>> Here I come with more problems... Sorry. :)
>>>
>>> I'm trying to read a file with Gio:
>>>
>>>> gio = imports.gi.Gio
>>> [object Object]
>>>
>>>> f = gio.file_new_for_path("helloworld.js")
>>> [object GLocalFile]
>>>> x = f.read()
>>> [object GLocalFileInputStream]
>>>> x.read()
>>> (seed:2637): GLib-GIO-CRITICAL **: g_input_stream_read: assertion `buffer != NULL' failed
>>> 0
>>>> buf = {}
>>> [object Object]
>>>> x.read(buf)
>>> (seed:2637): GLib-GIO-CRITICAL **: g_input_stream_read: assertion `buffer != NULL' failed
>>> 0
>>>> buf = []
>>>> x.read(buf)
>>> (seed:2637): GLib-GIO-CRITICAL **: g_input_stream_read: assertion `buffer != NULL' failed
>>> 0
>>> How does functions that take an output parameter map to javascript in seed? I thought they would return the output, or an object with a property for each output if there are several?
>>>
>>> /Jonatan
>>> _______________________________________________
>>> libseed-list mailing list
>>> libseed-list gnome org
>>> http://mail.gnome.org/mailman/listinfo/libseed-list
>
> _______________________________________________
> libseed-list mailing list
> libseed-list gnome org
> http://mail.gnome.org/mailman/listinfo/libseed-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]