summaryrefslogtreecommitdiff
blob: 2bb3a8d653e8ff49d1612da7b39686afcac90ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From 2a5f9c51f2f8dd29cd19a14f165ca2b425a172fc Mon Sep 17 00:00:00 2001
From: George Kiagiadakis <george.kiagiadakis@collabora.com>
Date: Wed, 15 Sep 2021 12:51:47 +0300
Subject: [PATCH 2/5] lua/api: fix object constructors to fail gracefully

---
 modules/module-lua-scripting/api.c | 35 ++++++++++++++++++------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/modules/module-lua-scripting/api.c b/modules/module-lua-scripting/api.c
index 5691b63..2830477 100644
--- a/modules/module-lua-scripting/api.c
+++ b/modules/module-lua-scripting/api.c
@@ -836,8 +836,9 @@ device_new (lua_State *L)
 
   WpDevice *d = wp_device_new_from_factory (get_wp_export_core (L),
       factory, properties);
-  wplua_pushobject (L, d);
-  return 1;
+  if (d)
+    wplua_pushobject (L, d);
+  return d ? 1 : 0;
 }
 
 /* WpSpaDevice */
@@ -855,8 +856,9 @@ spa_device_new (lua_State *L)
 
   WpSpaDevice *d = wp_spa_device_new_from_spa_factory (get_wp_export_core (L),
       factory, properties);
-  wplua_pushobject (L, d);
-  return 1;
+  if (d)
+    wplua_pushobject (L, d);
+  return d ? 1 : 0;
 }
 
 static int
@@ -903,8 +905,9 @@ node_new (lua_State *L)
 
   WpNode *d = wp_node_new_from_factory (get_wp_export_core (L),
       factory, properties);
-  wplua_pushobject (L, d);
-  return 1;
+  if (d)
+    wplua_pushobject (L, d);
+  return d ? 1 : 0;
 }
 
 static int
@@ -1011,8 +1014,9 @@ impl_node_new (lua_State *L)
 
   WpImplNode *d = wp_impl_node_new_from_pw_factory (get_wp_export_core (L),
      factory, properties);
-  wplua_pushobject (L, d);
-  return 1;
+  if (d)
+    wplua_pushobject (L, d);
+  return d ? 1 : 0;
 }
 
 /* Port */
@@ -1045,8 +1049,9 @@ link_new (lua_State *L)
   }
 
   WpLink *l = wp_link_new_from_factory (get_wp_core (L), factory, properties);
-  wplua_pushobject (L, l);
-  return 1;
+  if (l)
+    wplua_pushobject (L, l);
+  return l ? 1 : 0;
 }
 
 /* Client */
@@ -1124,8 +1129,9 @@ session_item_new (lua_State *L)
 {
   const char *type = luaL_checkstring (L, 1);
   WpSessionItem *si = wp_session_item_make (get_wp_core (L), type);
-  wplua_pushobject (L, si);
-  return 1;
+  if (si)
+    wplua_pushobject (L, si);
+  return si ? 1 : 0;
 }
 
 static int
@@ -1135,8 +1141,9 @@ session_item_get_associated_proxy (lua_State *L)
   const char *typestr = luaL_checkstring (L, 2);
   WpProxy *proxy = wp_session_item_get_associated_proxy (si,
       parse_gtype (typestr));
-  wplua_pushobject (L, proxy);
-  return 1;
+  if (proxy)
+    wplua_pushobject (L, proxy);
+  return proxy ? 1 : 0;
 }
 
 static int
-- 
2.33.0