Skip to content

Instantly share code, notes, and snippets.

@markandgo
markandgo / lovelib.lua
Last active December 30, 2021 05:29
Loadable love in Lua
package.cpath = package.cpath..';C:/Program Files/LOVE/?.dll;./?.dll'
-- Modification of boot.lua
-- This file loads love but does not execute love.run or open a window
-- This file must be located in the root game directory
-- The root game directory must also be the working directory
-- Make sure love exists.
local love = require("love")
@markandgo
markandgo / css_colors
Created November 9, 2013 06:43
From irc #love
CSS_COLORS = {
aliceblue = {240, 248, 255},
antiquewhite = {250, 235, 215},
aqua = { 0, 255, 255},
aquamarine = {127, 255, 212},
azure = {240, 255, 255},
beige = {245, 245, 220},
bisque = {255, 228, 196},
black = { 0, 0, 0},
blanchedalmond = {255, 235, 205},
@markandgo
markandgo / utf8.lua
Last active January 19, 2024 08:34
Kyle Smith's utf8.lua with some extra functions
-- $Id: utf8.lua 179 2009-04-03 18:10:03Z pasta $
--
-- Provides UTF-8 aware string functions implemented in pure lua:
-- * string.utf8len(s)
-- * string.utf8sub(s, i, j)
-- * string.utf8reverse(s)
-- * string.utf8char(unicode)
-- * string.utf8unicode(s, i, j)
-- * string.utf8gensub(s, sub_len)
--
@markandgo
markandgo / class.lua
Last active December 18, 2015 06:09
A class system with a novel constructor
-- simple class
-------------------------------------------------
local mixin_reserved = {
['new'] = true,
['onMixin'] = true,
['__type'] = true,
['__index'] = true,
}
local base = {__type = 'Object'}
@markandgo
markandgo / text.lua
Created May 10, 2013 02:46
Text with scrolling and wrapping support for LOVE 0.8.0
--[[
v0.91 text.lua
Copyright (c) 2013 Minh Ngo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWA
@markandgo
markandgo / asserts.lua
Last active December 14, 2015 18:39
Suspect, a simple unit testing module with support for a custom output handler. Includes bonus/optional asserts.lua
local assert = assert
local tostring = tostring
local pcall = pcall
local FORMAT_ASSERT_EQUALS = 'expected %s to be equal to %s'
local FORMAT_ASSERT_UNEQ = 'all values are %s'
asserteq = function(...)
local values = {...}
local first = values[1]
@markandgo
markandgo / ray.lua
Created November 17, 2012 00:53
Generic raycasting through grid (Digital Differential Algorithm)
-- v1.0
local floor = math.floor
-- cell_width being the width of the cell along an axis e.g. x/y axis
local initRayData = function(cell_width,i,f)
local d = f-i
local cell_i = floor(i/cell_width)
local dRatio,Delta,Step,Start
if d > 0 then