Skip to content

Instantly share code, notes, and snippets.

@JlnWntr
JlnWntr / ringbuffer.lua
Created August 16, 2018 10:22
Most simple ringbuffer/queue in Lua (5.3.4)
MAX_SIZE = 4
Ring = {}
function insert(ring, a)
table.insert(ring, a)
if #ring > MAX_SIZE then
table.remove(ring, 1)
end
end
@JlnWntr
JlnWntr / deepcopy.lua
Last active November 9, 2018 19:24
Simplest Lua table deep copy
function fullcopy(a, b)
for k, v in pairs(a) do
if type(v)=="table" then
b[k] = {}
fullcopy(v, b[k])
else
b[k] = v
end
end
end
@JlnWntr
JlnWntr / CMakeLists.txt
Created December 22, 2019 13:28
Download and build latest liblua via CMake
cmake_minimum_required(VERSION 3.10)
include(ExternalProject)
ExternalProject_Add(lua
URL "https://www.lua.org/ftp/lua-5.3.5.tar.gz"
CONFIGURE_COMMAND ""
BUILD_COMMAND make generic
BUILD_ALWAYS true
BUILD_IN_SOURCE true
INSTALL_COMMAND ""
@JlnWntr
JlnWntr / key_poll.c
Last active March 17, 2020 16:35
Key polling on Linux in plain C
#define KEY_POLL_TEST
struct termios poll_before, poll_new;
struct timeval poll_tv;
fd_set poll_fs;
int poll_init(){
poll_tv.tv_usec = POLL_TIMEOUT_MICROSECONDS;
poll_tv.tv_sec = POLL_TIMEOUT_SECONDS;
if(tcgetattr(STDIN_FILENO, &poll_before) != 0) return 1;