Skip to content

Instantly share code, notes, and snippets.

davidm /
Last active Dec 14, 2015
checkglobals patch

Detailed Description: checkglobals module + patch

The checkglobals module + patch (from LuaPowerPatches -- Download Patch for Lua 5.1.3 is a hybrid of a compile-time and run-time approach for detecting undefined variables. Consider the following trivial Lua module:

-- multiplybyx.lua
local function multiplybyx(y)
  return y * X                -- is X defined???
return multiplybyx
davidm / globalsplus.lua
Created Mar 9, 2013
globalsplus.lua for DetectingUndefinedVariables
View globalsplus.lua
-- globalsplus.lua
-- Like globals.lua in Lua 5.1.4 but records fields in global tables too.
-- Probably works but not well tested. Could be extended even further.
-- usage: luac -p -l example.lua | lua globalsplus.lua
-- D.Manura, 2010-07, public domain
local function parse(line)
local idx,linenum,opname,arga,argb,extra =
davidm / makebuild.lua
Last active Dec 14, 2015
Lua makefile generator in < 100 lines of code.
View makebuild.lua
Simple Makefile generator in Lua 5.1.
With gcc include dependency support.
WARNING: proof of concept; not well tested. GNU style Makefile.
See premake for a more complete implementation.
(c) David Manura, 2013-03. MIT license (same as Lua).
local M = {}
davidm / notes-fd-staircase.txt
Created Jul 13, 2012
View notes-fd-staircase.txt
One method I've prototyped to reduce effects of finite difference (F.D.) staircase effects (though not really recommended nor used but provided for reference):
(1) Solve the partial differential equation for f in the usual way by F.D.
(2) Measure f and grad(f) at each point about one or two mesh units away from the boundary surface by using data from #1. Use this to update values at boundary condition mesh points. For example, by linear extrpolation or other extrapolation technique.
(3) Repeat #1 until convergence.
Other obvious variations for updating boundary mesh point values are possible, including expressing #1-3 as a single matrix equation to solve (which probably has some equivalence to currently used techniques), thereby avoiding the repetition needed in #3.
davidm / hamming_weight_test.lua
Created Mar 17, 2012
hamming weight calculation tests
View hamming_weight_test.lua
Correctness and benchmark tests of various hamming weight implementations.
This is also called "popcount".
See also
David Manura, 2012-03.
View memoize.lua
Code is public domain.
davidm / sourceunpack.lua
Created Dec 2, 2011
Lua module 'sourcepack' - Extract Lua files from other Lua files.
View sourceunpack.lua
#!/usr/bin/env lua
--[[ FILE README.txt
sourceunpack v$(_VERSION) - Extract Lua files containing other Lua files.