Last active
May 18, 2026 13:43
-
-
Save Dregu/1cade5626337f80bfb707a446531e0b1 to your computer and use it in GitHub Desktop.
Lua REPL console for Hyprland
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Lua UDP REPL console for Hyprland | |
| -- Just stick repl.lua in .config/hypr and `require "repl"` | |
| -- Connect with `socat readline,prompt="> " udp-datagram:localhost:42069` | |
| -- Get luasocket somehow, `pacman -S lua-socket` installs here: | |
| package.path = "/usr/share/lua/" .. _VERSION:sub(5) .. "/?.lua;/usr/share/lua/" .. _VERSION:sub(5) .. "/?/init.lua;" .. package.path | |
| -- lua-inspect is on e.g. aur | |
| -- Pretty useful, not really required, so lets not error on that, although hl custom error handler might do it anyway | |
| _, inspect = pcall(require, "inspect") | |
| local socket = require("socket") | |
| local udp = assert(socket.udp()) | |
| local function listen() | |
| udp:setoption("reuseaddr", true) | |
| udp:setoption("reuseport", true) | |
| udp:setsockname("*", 42069) | |
| udp:settimeout(0) | |
| while true do | |
| local msg, ip, port = udp:receivefrom() | |
| if msg then | |
| if msg:sub(1, 7) ~= "return " then msg = "return " .. msg end | |
| local f, e = load(msg) | |
| if f then | |
| local s, r = pcall(f) | |
| if s then | |
| udp:sendto(tostring(r) .. "\n", ip, port) | |
| else | |
| udp:sendto("Error: " .. tostring(r) .. "\n", ip, port) | |
| end | |
| end | |
| end | |
| coroutine.yield() | |
| end | |
| end | |
| hl.timer(function() | |
| if not repl_thread then | |
| repl_thread = coroutine.create(listen) | |
| end | |
| if repl_thread then | |
| local s, e = coroutine.resume(repl_thread) | |
| if coroutine.status(repl_thread) == "dead" then | |
| repl_thread = coroutine.create(listen) | |
| end | |
| end | |
| end, { timeout = 16, type = "repeat" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment