[gjs: 1/4] ns: Expose __version__ property
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/4] ns: Expose __version__ property
- Date: Thu, 5 Aug 2021 03:59:10 +0000 (UTC)
commit 9aca552e85a45a3cc1991236becb68bae91ca27c
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Aug 3 23:33:34 2021 +0200
ns: Expose __version__ property
It can be useful to know the version of a namespace that has been
loaded, so expose a corresponding property alongside the name.
gi/ns.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
---
diff --git a/gi/ns.cpp b/gi/ns.cpp
index 063b31f0..54ab994d 100644
--- a/gi/ns.cpp
+++ b/gi/ns.cpp
@@ -164,6 +164,13 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> {
return gjs_string_from_utf8(cx, priv->get(), args.rval());
}
+ GJS_JSAPI_RETURN_CONVENTION
+ static bool get_version(JSContext* cx, unsigned argc, JS::Value* vp) {
+ GJS_CHECK_WRAPPER_PRIV(cx, argc, vp, args, this_obj, Ns, priv);
+ const char *version = g_irepository_get_version(nullptr, priv->get());
+ return gjs_string_from_utf8(cx, version, args.rval());
+ }
+
static constexpr JSClassOps class_ops = {
nullptr, // addProperty
nullptr, // deleteProperty
@@ -178,6 +185,7 @@ class Ns : private GjsAutoChar, public CWrapper<Ns> {
static constexpr JSPropertySpec proto_props[] = {
JS_STRING_SYM_PS(toStringTag, "GIRepositoryNamespace", JSPROP_READONLY),
JS_PSG("__name__", &Ns::get_name, GJS_MODULE_PROP_FLAGS),
+ JS_PSG("__version__", &Ns::get_version, GJS_MODULE_PROP_FLAGS & ~JSPROP_ENUMERATE),
JS_PS_END};
// clang-format on
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]