Re: libseed-list trying to read a gio stream



Tim Horton wrote:
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.

Yes, I know about the c_new(), but the strange thing with the code above is that c_new() is called with the new operator. So c_new() is a JS constructor? I thought that c_new() would just return a new instance.. But perhaps 'new' is used only to set the 'this' variable for c_new()?

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)

It can be very useful to write core functions in a C module and do the high-level OOP abstractions and other extensions in a JS module.

/Jonatan


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