| 792 | } |
| 793 | |
| 794 | static int l_siplua_moduleFunc(lua_State *L) |
| 795 | { |
| 796 | struct sipapi_object *o; |
| 797 | const char *func; |
| 798 | int n, nargs; |
| 799 | const cmd_export_t *exp_func_struct; |
| 800 | action_elem_t elems[MAX_ACTION_ELEMS]; |
| 801 | const char *msg; |
| 802 | int i; |
| 803 | struct action *act; |
| 804 | int retval, rc; |
| 805 | pv_spec_t *specs[MAX_CMD_PARAMS]; |
| 806 | const struct cmd_param *param; |
| 807 | char *largs[MAX_CMD_PARAMS]; |
| 808 | str s; |
| 809 | |
| 810 | o = luaL_checkudata(L, 1, "siplua.api"); |
| 811 | func = luaL_checkstring(L, 2); |
| 812 | n = lua_gettop(L); |
| 813 | nargs = n - 2; |
| 814 | if (n - 1 > MAX_ACTION_ELEMS) |
| 815 | return luaL_error(L, "function '%s' called with too many arguments [%d > %d]", |
| 816 | func, nargs, MAX_ACTION_ELEMS - 1); |
| 817 | |
| 818 | exp_func_struct = find_cmd_export_t((char *)func, 0); |
| 819 | if (!exp_func_struct) |
| 820 | return luaL_error(L, "function '%s' called, but not available", func); |
| 821 | |
| 822 | elems[0].type = CMD_ST; |
| 823 | elems[0].u.data_const = exp_func_struct; |
| 824 | |
| 825 | for (i = 0; i < nargs; ++i) { |
| 826 | if (lua_isnil(L, 3 + i)) { |
| 827 | elems[i+1].type = NULLV_ST; |
| 828 | largs[i] = NULL; |
| 829 | } else { |
| 830 | largs[i] = (char*)lua_tostring(L, 3 + i); |
| 831 | if (!largs[i]) { |
| 832 | msg = lua_pushfstring(L, "%s expected, got %s", |
| 833 | lua_typename(L, LUA_TSTRING), luaL_typename(L, 3 + i)); |
| 834 | return luaL_argerror(L, 3 + i, msg); |
| 835 | } |
| 836 | elems[i+1].type = NOSUBTYPE; |
| 837 | } |
| 838 | specs[i] = NULL; |
| 839 | } |
| 840 | |
| 841 | retval = check_cmd_call_params(exp_func_struct, elems, nargs); |
| 842 | if (retval == -1 || retval == -2) |
| 843 | return luaL_error(L, "to few or too many parameters for function '%s'", func); |
| 844 | else if (retval == -3) |
| 845 | return luaL_error(L, "mandatory parameter ommited for function '%s'", func); |
| 846 | |
| 847 | for (param=exp_func_struct->params, i=1; param->flags; param++, i++) { |
| 848 | if (!largs[i-1]) |
| 849 | continue; |
| 850 | |
| 851 | if (param->flags & CMD_PARAM_INT) { |
nothing calls this directly
no test coverage detected