Skip to content

Instantly share code, notes, and snippets.

local ffi = require("ffi")
local lua = require("luajit")
local sdl = require("SDL2")
local message_type = "struct {uint8_t*to_ptr; size_t to_len; uint8_t*from_ptr; size_t from_len;} *"
local state = lua.L.newstate()
lua.L.openlibs(state)
local ok = lua.L.loadstring(state, [[
local function check (self)
if not self.isDirty then
return self
end
self.length = 0
local item = self.firstItem
while item do
self.length = self.length + 1
self.items[self.length] = item
item = self.itemAfter[item]
@airstruck
airstruck / wrap.lua
Created July 13, 2016 18:51
Love text wrapping
local function wrap (text, limit)
local font = love.graphics.getFont()
local lines = {{ width = 0 }}
local advance = 0
local lastSpaceAdvance = 0
local function append (word, space)
local wordAdvance = font:getWidth(word)
local spaceAdvance = font:getWidth(space)
local words = lines[#lines]
@airstruck
airstruck / multilove.md
Last active October 31, 2018 14:02
Installing multiple versions of LÖVE

Installing multiple versions of LÖVE

This document explains how to set up multiple LÖVE installations. Make sure you have all dependencies for the versions of LÖVE you want to install.

Initial setup

Make a directory to install LÖVE source and binaries into.

mkdir $HOME/love/
// Test it on https://love2d.org/wiki/love.thread.newThread
// TODO: dl notes: https://love2d.org/wiki/GraphicsFeature
// TODO: box notes: https://love2d.org/wiki/love.event.push
var picker = document.createElement('select')
picker.onchange = function () {
applyFilter(this.options[this.selectedIndex].value)
}
#include <lua.h>
#include <lauxlib.h>
int tuple (lua_State *L) {
/* first upvalue is number of tuple values */
int argc = luaL_checkint(L, lua_upvalueindex(1));
/* if arg is "#", return number of tuple values */
const char *count = luaL_optstring(L, 1, "");
if (count[0] == '#') {
@airstruck
airstruck / alea.lua
Last active August 5, 2020 05:57
A LuaJIT port of Johannes Baagøe's Alea
-- A Lua port of Johannes Baagøe's Alea
-- From http://baagoe.com/en/RandomMusings/javascript/
-- Johannes Baagøe <baagoe@baagoe.com>, 2010
-- Mirrored at:
-- https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
local floor = math.floor