[PATCH] osmocom-bb[master]: mobile: Simplify code and check the cb ref in load_cb

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Holger Freyther gerrit-no-reply at lists.osmocom.org
Sun Dec 3 22:03:24 UTC 2017


Review at  https://gerrit.osmocom.org/5155

mobile: Simplify code and check the cb ref in load_cb

Change parameters and check if the cb_ref is valid or not.

Change-Id: I74fbcd7e853e24b1225ecc4c19304134b8467c9b
---
M src/host/layer23/src/mobile/script_lua.c
1 file changed, 14 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/55/5155/1

diff --git a/src/host/layer23/src/mobile/script_lua.c b/src/host/layer23/src/mobile/script_lua.c
index 422f9e4..e63d205 100644
--- a/src/host/layer23/src/mobile/script_lua.c
+++ b/src/host/layer23/src/mobile/script_lua.c
@@ -97,9 +97,14 @@
 };
 
 /* Push table and function.   Stack+=2 */
-static bool load_cb(lua_State *L, int ref, const char *cb_name)
+static bool load_cb(struct osmocom_ms *ms, const char *cb_name)
 {
-	lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+	struct lua_State *L = ms->lua_state;
+
+	if (ms->lua_cb_ref == LUA_REFNIL)
+		return false;
+
+	lua_rawgeti(L, LUA_REGISTRYINDEX, ms->lua_cb_ref);
 	lua_pushstring(L, cb_name);
 	lua_gettable(L, -2);
 	if (lua_isnil(L, -1)) {
@@ -138,12 +143,9 @@
 
 static void handle_started(struct mobile_prim_intf *intf, struct mobile_started_param *param)
 {
-	lua_State *L = intf->ms->lua_state;
+	struct lua_State *L = intf->ms->lua_state;
 
-	if (intf->ms->lua_cb_ref == LUA_REFNIL)
-		return;
-
-	if (!load_cb(L, intf->ms->lua_cb_ref, "Started"))
+	if (!load_cb(intf->ms, "Started"))
 		return;
 
 	lua_pushinteger(L, param->started);
@@ -154,12 +156,9 @@
 
 static void handle_shutdown(struct mobile_prim_intf *intf, struct mobile_shutdown_param *param)
 {
-	lua_State *L = intf->ms->lua_state;
+	struct lua_State *L = intf->ms->lua_state;
 
-	if (intf->ms->lua_cb_ref == LUA_REFNIL)
-		return;
-
-	if (!load_cb(L, intf->ms->lua_cb_ref, "Shutdown"))
+	if (!load_cb(intf->ms, "Shutdown"))
 		return;
 
 	lua_pushinteger(L, param->old_state);
@@ -171,12 +170,9 @@
 
 static void handle_sms(struct mobile_prim_intf *intf, struct mobile_sms_param *param)
 {
-	lua_State *L = intf->ms->lua_state;
+	struct lua_State *L = intf->ms->lua_state;
 
-	if (intf->ms->lua_cb_ref == LUA_REFNIL)
-		return;
-
-	if (!load_cb(L, intf->ms->lua_cb_ref, "Sms"))
+	if (!load_cb(intf->ms, "Sms"))
 		return;
 
 	lua_createtable(L, 0, 11);
@@ -225,10 +221,7 @@
 {
 	lua_State *L = intf->ms->lua_state;
 
-	if (intf->ms->lua_cb_ref == LUA_REFNIL)
-		return;
-
-	if (!load_cb(L, intf->ms->lua_cb_ref, "Mm"))
+	if (!load_cb(intf->ms, "Mm"))
 		return;
 
 	lua_pushinteger(L, param->state);

-- 
To view, visit https://gerrit.osmocom.org/5155
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74fbcd7e853e24b1225ecc4c19304134b8467c9b
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>



More information about the gerrit-log mailing list