MCPcopy Create free account
hub / github.com/PlutoLang/Pluto / luaopen_socket

Function luaopen_socket

src/lsocketlib.cpp:593–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591};
592
593LUAMOD_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(
599return 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)
609end)EOC");
610 lua_call(L, 0, 1);
611 lua_settable(L, -3);
612#endif
613
614 return 1;
615}
616const Pluto::PreloadedLibrary Pluto::preloaded_socket{ PLUTO_SOCKETLIBNAME, funcs_socket, &luaopen_socket };
617
618#endif

Callers

nothing calls this directly

Calls 2

luaL_loadstringFunction · 0.85
lua_settableFunction · 0.85

Tested by

no test coverage detected