Skip to content

Instantly share code, notes, and snippets.

View daurnimator's full-sized avatar

daurnimator

View GitHub Profile
-- Generalized Partial Application Implementation In Lua
-- Azer Koculu <azerkoculu@gmail.com>
-- Mon May 24 10:33:40 UTC 2010
local function partial(fn,initialargs)
return function(...)
args = {}
if initialargs then table.foreach(initialargs,function(ind,el) table.insert(args,el) end) end
for i=0,arg['n'],1 do table.insert(args,arg[i]) end
return fn(unpack(args))
end
-- Generalized Partial Application Implementation In Lua
-- Azer Koculu <azerkoculu@gmail.com>
-- Mon May 24 10:33:40 UTC 2010
local function partial(fn,initialargs)
return function(...)
args = {}
if initialargs then table.foreach(initialargs,function(ind,el) table.insert(args,el) end) end
for i=0,arg['n'],1 do table.insert(args,arg[i]) end
return fn(unpack(args))
end
@daurnimator
daurnimator / require.lua
Created July 22, 2010 17:27
A replacement/wrapper for lua's require
local _G = _G
local next , pairs , rawset , require = next , pairs , rawset , require
local cache = { }
---A new require: loads modules in a way that they don't modify the global environment
--@param lib module name to load (given to require)
--@param keepchanges whether changes to existing global keys should be kept (default is to revert changes)
local function newrequire ( lib , keepchanges )
-- Check if its in the cache
@daurnimator
daurnimator / pointer.lua
Created April 5, 2011 01:28
A small library that will let you use luajit cdata how you would hope.
local ffi=require"ffi"
local topointer
local pointer_mt
local key_address , key_ctype , key_cdata , key_methods = {},{},{},{}
local function ispointer ( ob )
return getmetatable ( ob ) == pointer_mt
end
local function denormalise ( ob )
local ffi,pointer
do
local ok , err = pcall ( require , "ffi" )
if ok then
ffi = err
pointer = require"pointer"
end
end
@daurnimator
daurnimator / codedoc.lua
Created July 4, 2011 17:08
Documentation Framework
local dt = { }
local function doc ( ... )
local args = {...}
return function ( v )
if type(v) == "function" then
local t = dt [ v ]
if t then
local tn = #t
for i,doctbl in ipairs(args) do
@daurnimator
daurnimator / play.lua
Created October 12, 2011 03:26
Now with generalised lazy buffer.
local general = require"general"
local len = general.len
local decode = require"decode"
local new_fifo = require"fifo"
local lazybuffer = require"lazybuffer"
local empty_item = { source = "silent" , from = 0 , to = math.huge }
@daurnimator
daurnimator / openal.lua
Created October 13, 2011 16:20
OpenAL with luajit
local ffi = require"ffi"
local function process_defines(file,defines)
defines = defines or {}
--TODO: unifdef
for line in io.lines(file) do
local n ,v = line:match("#define%s+(%S+)%s+(.*)")
if n then
v = defines[v] or v
v = tonumber(v) or v
defines[n] = v
local function add_dep(ob,dep)
local reg = debug.getregistry()
local t = reg[dep]
if not t then
t = setmetatable({},{__mode="k"})
reg[dep] = t
end
t[ob]=true
end
@daurnimator
daurnimator / test.lua
Created October 14, 2011 01:07
playtest
local setup_play = require"play"
-- Must have return value that has __add metamethod
local function newbuffer ( buff_size )
return setmetatable({a=8000000},{
__len = function (o) return buff_size end;
})
end
local num_buffers = 3