| 591 | }; |
| 592 | |
| 593 | LUAMOD_API int luaopen_socket (lua_State *L) { |
| 594 | luaL_newlib(L, funcs_socket); |
| 595 | |
| 596 | #ifndef PLUTO_DONT_LOAD_ANY_STANDARD_LIBRARY_CODE_WRITTEN_IN_PLUTO |
| 597 | lua_pushliteral(L, "bind"); |
| 598 | luaL_loadstring(L, R"EOC( |
| 599 | return function(sched, port, callback) |
| 600 | local l = require"pluto:socket".listen(port) |
| 601 | assert(l, "Failed to bind port "..port) |
| 602 | return sched:add(function() |
| 603 | while s := l:accept() do |
| 604 | sched:add(function() |
| 605 | callback(s) |
| 606 | end) |
| 607 | end |
| 608 | end) |
| 609 | end)EOC"); |
| 610 | lua_call(L, 0, 1); |
| 611 | lua_settable(L, -3); |
| 612 | #endif |
| 613 | |
| 614 | return 1; |
| 615 | } |
| 616 | const Pluto::PreloadedLibrary Pluto::preloaded_socket{ PLUTO_SOCKETLIBNAME, funcs_socket, &luaopen_socket }; |
| 617 | |
| 618 | #endif |
nothing calls this directly
no test coverage detected