allocate a SocketAPM */
| 926 | allocate a SocketAPM |
| 927 | */ |
| 928 | int lua_get_SocketAPM(lua_State *L) { |
| 929 | binding_argcheck(L, 1); |
| 930 | const uint8_t datagram = get_uint8_t(L, 1); |
| 931 | auto *scripting = AP::scripting(); |
| 932 | |
| 933 | auto *sock = NEW_NOTHROW SocketAPM(datagram); |
| 934 | if (sock == nullptr) { |
| 935 | return luaL_argerror(L, 1, "SocketAPM device nullptr"); |
| 936 | } |
| 937 | for (uint8_t i=0; i<SCRIPTING_MAX_NUM_NET_SOCKET; i++) { |
| 938 | if (scripting->_net_sockets[i] == nullptr) { |
| 939 | scripting->_net_sockets[i] = sock; |
| 940 | *new_SocketAPM(L) = scripting->_net_sockets[i]; |
| 941 | return 1; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | return luaL_argerror(L, 1, "no sockets available"); |
| 946 | } |
| 947 | |
| 948 | /* |
| 949 | socket close |
nothing calls this directly
no test coverage detected