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
#!/bin/lua | |
local lib = {} | |
function lib.pair(init) | |
local variable = init | |
return function() | |
return variable | |
end, function(value) | |
variable = value |
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
This small benchmark test compares the performance of using `ipairs{...}` vs. | |
`select('#',<n>)` to iterate over the arguments inside a variadic function. |
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
<style> | |
* { | |
margin: 0; | |
padding: 0; | |
} | |
svg.template { | |
height: 0em; | |
width: 0em; | |
display: block; | |
} |
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
import min from math | |
levenshtein = (a, b) -> | |
c = {nil, nil, nil, nil, nil} | |
p = {nil, nil, nil, nil, nil} | |
for i=1,#a+1 | |
c[i]=i-1 -- Distance to "" | |
for i=1,#b | |
p,c = c,p | |
c[1] = i -- Distance from "" |
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
local mod = {} | |
local meta = { | |
__call = function(tab, ...) | |
if not tab.func then | |
tab.func = tab.loader() | |
end | |
tab.func(...) | |
end |
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
env = do | |
local env | |
env = _ENV | |
setmetatable {}, { | |
__index: (key) => | |
env[key] or (...) -> | |
@.tag(key, ...) | |
} |
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
height = 20 | |
width = 100 | |
split = 6/10 | |
tag = (number, color='#ea316e') -> | |
buf = require'strbuffer'! | |
generator = require'moonxml'.xml -> | |
svg { | |
xmlns: 'http://www.w3.org/2000/svg' | |
:width |
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
--- Vector objects with several mathematical operations | |
-- @author DarkWiiPlayer | |
-- @license MIT | |
-- luacheck: ignore 4.1 | |
local transformation, array4 = require "classes.transformation" | |
local ffi = require "ffi" | |
local sin, cos = math.sin, math.cos |
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
--- An abstract implementation of an object pool | |
-- @usage | |
-- local pool = require("pool"){ | |
-- initialize = function(elem) elem.name = "John Doe"; return elem end; | |
-- max = 50; | |
-- } | |
-- local elem = pool:get() -- Creates a new element because pool is empty | |
-- print(elem.x) --> John Doe -- pool:put(elem) -- Puts element back into pool --- You know, the thing that this is all about, the pool class -- @type pool | |
local math = require "math" |
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
moonscript = require "moonscript" | |
moonscript.loadstring('print "\\nHere I am!"', 'string', 't', setmetatable({}, { | |
__index: (key) => | |
print "index", key | |
for key, value in pairs debug.getinfo 2 | |
print '', key, value | |
print debug.traceback() | |
}))() |
OlderNewer