Skip to content

Instantly share code, notes, and snippets.

View CapsAdmin's full-sized avatar
🌜
Lua

Elias Hogstvedt CapsAdmin

🌜
Lua
View GitHub Profile
local ffi = require("ffi")
local lua = require("luajit")
local sdl = require("SDL2")
ffi.cdef("void* malloc(size_t size); void *memcpy(void*, void*, size_t);")
local message_type = "struct {uint8_t*to_ptr; size_t to_len; uint8_t*from_ptr; size_t from_len; uint8_t from_ready;}"
local state = lua.L.newstate()
lua.L.openlibs(state)
local fireBlocks = {}
local tilesize = 8
local numberWidthBlocks = math.floor(ScrW() / tilesize)
local numberHeightBlocks = 48 -- means all the 36 colors with a little more space to remaining flames
local offsetY = ScrH() - (numberHeightBlocks * tilesize)
local colorLookup = {
Color(7,7,7),
Color(31,7,7),
Color(47,15,7),
local fireBlocks = {}
local tilesize = 8
local numberWidthBlocks = math.floor(ScrW() / tilesize)
local numberHeightBlocks = 48 -- means all the 36 colors with a little more space to remaining flames
local offsetY = ScrH() - (numberHeightBlocks * tilesize)
local colorLookup = {
Color(7,7,7),
Color(31,7,7),
Color(47,15,7),
local ffi = require("ffi")
ffi.cdef[[
char *mmap(void *addr, size_t length, int prot, int flags, int fd, long int offset);
int munmap(void *addr, size_t length);
]]
local PROT_READ = 0x1 -- Page can be read.
local PROT_WRITE = 0x2 -- Page can be written.
local PROT_EXEC = 0x4 -- Page can be executed.
local ffi = require("ffi")
ffi.cdef[[
char *mmap(void *addr, size_t length, int prot, int flags, int fd, long int offset);
int munmap(void *addr, size_t length);
]]
local PROT_READ = 0x1 -- Page can be read.
local PROT_WRITE = 0x2 -- Page can be written.
local PROT_EXEC = 0x4 -- Page can be executed.
@CapsAdmin
CapsAdmin / main.lua
Last active October 20, 2025 19:54
repat until continue goto problem
-- INPUT:
--[[
local exit = false
repeat
if exit then break end
if true then
continue
end
local callback = {}
do
local meta = {}
meta.__index = meta
meta.Type = "callback"
function meta:__tostring()
return string.format("callback: %p", self)
@CapsAdmin
CapsAdmin / repl.lua
Created October 29, 2018 05:31
lua repl using ffi, windows isn't finished/working
local ffi = require("ffi")
local start
local stop
local read
if jit.os == "Linux" then
ffi.cdef([[
struct termios
g("frame")
Size = Vec2(250, 140)
Title = "Confirm Save As"
SetupLayout("LayoutChildren", "SizeToChildrenHeight", "SizeToChildrenWidth")
local frame = self
g("base")
Style = "frame"
SetupLayout("MoveUp", "FillX", "SizeToChildrenHeight")
g("rectangle")
SetupLayout("SizeToChildren", "CenterSimple")
@CapsAdmin
CapsAdmin / ffi_sockets.lua
Created October 18, 2018 15:07
luajit ffi tcp udp unix, luasocket-like
local ffi = require("ffi")
ffi.cdef[[
typedef int SOCKET;
typedef unsigned int socklen_t;
typedef uint16_t u_short;
typedef uint32_t u_int;
typedef unsigned long u_long;
typedef unsigned char byte;
typedef unsigned long size_t;