After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 689664 - format.printf(): New API
format.printf(): New API
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2012-12-04 22:52 UTC by Colin Walters
Modified: 2015-10-28 00:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
format.printf(): New API (925 bytes, patch)
2012-12-04 22:52 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2012-12-04 22:52:53 UTC
While writing an app, I kept finding myself doing:

print(format.vprintf("%s %s", [arg1, arg2]))

So this lets me do just:

format.printf("%s %s", arg1, arg2)

which is obviously way better.
Comment 1 Colin Walters 2012-12-04 22:52:55 UTC
Created attachment 230706 [details] [review]
format.printf(): New API
Comment 2 Giovanni Campagna 2012-12-10 22:33:47 UTC
Review of attachment 230706 [details] [review]:

::: modules/format.js
@@ +57,3 @@
+    let args = Array.prototype.slice.call(arguments);    
+    let fmt = args.shift();
+    print(vprintf(fmt, args));

Do you need the Array conversion?
And why vprintf() returns a string while printf() actually prints?

And on a related note, do we want gjs applications to print anything without going through log()? Especially if at some point log() is hooked to g_log() and from that to the journal.
Comment 3 Colin Walters 2012-12-13 00:57:14 UTC
(In reply to comment #2)

> Do you need the Array conversion?

Yes, "arguments" is immutable.

> And why vprintf() returns a string while printf() actually prints?

Umm...yeah, that is confusing.  But I can't change vprintf now...

> And on a related note, do we want gjs applications to print anything without
> going through log()? Especially if at some point log() is hooked to g_log() and
> from that to the journal.

So the larger question of how gjs does logging is definitely entagled with the question of how GLib does logging.  I guess let's figure the second out first, and then we can just have gjs bound to it.
Comment 4 Cosimo Cecchi 2015-10-28 00:41:56 UTC
Looks good to me. Pushed to master now.

Attachment 230706 [details] pushed as 2166fe9 - format.printf(): New API