This file contains 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
--sort core | |
-- | |
-- stable sorting routines for lua | |
-- | |
--based on MIT licensed code from Dirk Laurie and Steve Fisher | |
--license as follows: | |
--[[ | |
Copyright © 2013 Dirk Laurie and Steve Fisher. |
This file contains 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
--[[ | |
"semi-manual" garbage collection | |
specify a time budget and a memory ceiling per call. | |
called once per frame, this will spread any big collections | |
over a couple of frames, and "catch up" when there is. This | |
keeps GC burden much more predictable. | |
The memory ceiling provides some level of "relief valve" - if |
This file contains 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
--[[ | |
typewriter class | |
]] | |
local typewriter = {} | |
--(metatable used for instances, don't worry about it too much | |
-- but do read up on metatables at some point) | |
typewriter._mt = {__index = typewriter} | |
--create a new typewriter |
This file contains 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
--[[ | |
example use | |
]] | |
local recolour = require("recolour") | |
--we want to recolour this asset image | |
local to_recolour = love.image.newImageData("path/to/image.png") | |
--using this palette image | |
local palette = love.image.newImageData("path/to/palette.png") |
This file contains 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
--[[ | |
audio manager | |
]] | |
--sound source wrapper | |
local sound = class() | |
-- | |
function sound:new(source, volume, set) | |
return self:init({ |
This file contains 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
--[[ | |
oop basics | |
]] | |
function class(inherits) | |
local c = {} | |
c.__mt = {__index = c} | |
--handle single inheritence | |
if type(inherits) == "table" and inherits.__mt then | |
setmetatable(c, inherits.__mt) |
This file contains 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
-- stable sorting routines for lua | |
-- | |
-- modifies the global table namespace so you don't have | |
-- to re-require it everywhere. | |
-- | |
-- table.stable_sort | |
-- a fast stable sort | |
-- table.unstable_sort | |
-- alias for the builtin unstable table.sort | |
-- table.insertion_sort |
This file contains 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
--require the state machine module | |
local state_machine = require("state_machine") | |
--variable for the example state machine - set up in love.load | |
local example_machine | |
--(simple "last 10" history of what states we've been to) | |
local state_history = {} | |
function add_history(s) | |
table.insert(state_history, s) |
This file contains 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
--dialogue type | |
local dialogue = {} | |
dialogue._mt = { | |
__index = dialogue, | |
} | |
function dialogue:new(f) | |
return setmetatable({ |
This file contains 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
--config | |
local replicas = 3 | |
local test_duration = 0.5 | |
local single_test_size = 1e3 | |
--per-iteration operation | |
function test_operation(a, b, work_size) | |
for _ = 1, work_size do | |
local s = tostring(a + b) |
OlderNewer