Browse code

app_lua: support returning long value and functions with (str,long) params

Daniel-Constantin Mierla authored on 24/11/2022 09:35:36
Showing 1 changed files
... ...
@@ -957,6 +957,9 @@ int sr_kemi_lua_return_xval(lua_State* L, sr_kemi_t *ket, sr_kemi_xval_t *rx)
957 957
 		case SR_KEMIP_INT:
958 958
 			lua_pushinteger(L, rx->v.n);
959 959
 			return 1;
960
+		case SR_KEMIP_LONG:
961
+			lua_pushnumber(L, rx->v.l);
962
+			return 1;
960 963
 		case SR_KEMIP_STR:
961 964
 			lua_pushlstring(L, rx->v.s.s, rx->v.s.len);
962 965
 			return 1;
... ...
@@ -1066,6 +1069,10 @@ int sr_kemi_lua_exec_func_ex(lua_State* L, sr_kemi_t *ket, int pdelta)
1066 1069
 			vps[i].n = lua_tointeger(L, i+pdelta+1);
1067 1070
 			LM_DBG("param[%d] for: %.*s is int: %d\n", i,
1068 1071
 				fname->len, fname->s, vps[i].n);
1072
+		} else if(ket->ptypes[i]==SR_KEMIP_LONG) {
1073
+			vps[i].l = (long)lua_tonumber(L, i+pdelta+1);
1074
+			LM_DBG("param[%d] for: %.*s is long: %ld\n", i,
1075
+				fname->len, fname->s, vps[i].l);
1069 1076
 		} else {
1070 1077
 			LM_ERR("unknown parameter type %d (%d)\n", ket->ptypes[i], i);
1071 1078
 			return app_lua_return_false(L);
... ...
@@ -1136,6 +1143,14 @@ int sr_kemi_lua_exec_func_ex(lua_State* L, sr_kemi_t *ket, int pdelta)
1136 1143
 						ret = ((sr_kemi_fmss_f)(ket->func))(env_L->msg, &vps[0].s, &vps[1].s);
1137 1144
 						return sr_kemi_lua_return_int(L, ket, ret);
1138 1145
 					}
1146
+				} else if(ket->ptypes[1]==SR_KEMIP_LONG) {
1147
+					if(ket->rtype==SR_KEMIP_XVAL) {
1148
+						xret = ((sr_kemi_xfmsl_f)(ket->func))(env_L->msg, &vps[0].s, vps[1].l);
1149
+						return sr_kemi_lua_return_xval(L, ket, xret);
1150
+					} else {
1151
+						ret = ((sr_kemi_fmsl_f)(ket->func))(env_L->msg, &vps[0].s, vps[1].l);
1152
+						return sr_kemi_lua_return_int(L, ket, ret);
1153
+					}
1139 1154
 				} else {
1140 1155
 					LM_ERR("invalid parameters for: %.*s\n",
1141 1156
 							fname->len, fname->s);