Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR steve.j.donovan@gmail.com
!_TAG_PROGRAM_NAME ltags //
!_TAG_PROGRAM_URL http://github.com/stevedonovan/ltags /official site/
!_TAG_PROGRAM_VERSION 0.1 //
Q fs\win32.lua /^function Q(arg)$/;" m struct:luarocks.fs.win32
Q fs\lua.lua /^function Q(arg)$/;" m struct:luarocks.fs.lua
_ fs\lua.lua /^local _, ftp = pcall(require, "socket.ftp")$/;" v file:
absolute_name fs\win32.lua /^function absolute_name(pathname, relative_to)$/;" m struct:luarocks.fs.win32
@stevedonovan
stevedonovan / from.lua
Last active August 29, 2015 13:58
Utility module to simplify initializing locals from tables or modules.
local debug = require 'debug'
-- from.lua
-- supports some useful shortcuts when creating locals from tables or modules
-- require 'from'
-- local sin,cos,tan = slots(3) from(math)
-- local import,printf = slots(2) from 'pl.utils'
-- local pretty,utils,xml = slots(3) from 'pl.*'
--
-- Uses the debug library, so it's not very fast - only use for top-level initialization!
@stevedonovan
stevedonovan / StringAccessor.lua
Created December 20, 2010 08:38
A Lua class for accessing individual characters in a string
--[[ Example:
sa = StringAccessor 'hello'
for c in sa:iter() do
print(c)
end
print(sa[1],sa[3])
print('end',sa[-1])
--]]
@stevedonovan
stevedonovan / safe_array.lua
Created December 30, 2010 08:20
This defines an array with strict bounds checking. It is also impossible to set any existing index to a nil value, so the array remains free of holes. The table functions will not work on such arrays because they are userdata, giving an extra layer of pro
local function out_of_range(i,n)
if type(i) == 'number' then
if i > 0 and i <= n then return true
else error('out of range',3)
end
else
error 'cannot index array by non-number type'
end
end
@stevedonovan
stevedonovan / lua_prompt.lua
Created March 28, 2011 07:04
An interactive Lua prompt for the Textadept editor
-- makes interactive prompt dodgy.
-- (In an ideal world, should be able to switch this off only for
-- the message buffer)
_m.textadept.editing.AUTOPAIR = false
-- useful function which can safely handle argument lists containing nil;
-- the resulting table has n set to the real length.
local function pack (...)
local args = {...}
args.n = select('#',...)
@stevedonovan
stevedonovan / list.moon
Created December 15, 2011 10:33
An example of a MoonScript class
import insert,concat,remove from table
class List
new: (t) =>
@ls = t or {}
add: (item) =>
insert @ls,item
@stevedonovan
stevedonovan / array.lua
Created March 26, 2012 12:35
Covariance with pl.class: a specialized List of numbers
require 'pl'
class.Array(List)
function Array.__add (a1,a2)
return a1:map2('+',a2)
end
function Array.__sub (a1,a2)
return a1:map2('-',a2)
@stevedonovan
stevedonovan / deb.lua
Created May 8, 2012 11:53
Correspondance between Lua modules and Debian packages (from ldeb)
local packages = {
bit="liblua5.1-bitop0", -- -- fast bit manipulation library for the Lua language v
cgilua="liblua5.1-cgi0", -- -- CGI library for the Lua language version 5.1
sapi="liblua5.1-cgi0", -- -- CGI library for the Lua language version 5.1
copas="liblua5.1-copas0", -- -- Copas is a dispatcher of concurrent TCP/IP requests
cosmo="liblua5.1-cosmo0", -- -- A template library for the Lua langua version 5.1
coxpcall="liblua5.1-coxpcall0", -- -- Protected function calls across coroutines for Lua 5
curl="liblua5.1-curl0", -- -- libcURL bindings for the Lua language version 5.1
luaevent="liblua5.1-event0", -- -- asynchronous event notification library for Lua vers
lxp="liblua5.1-expat0", -- -- libexpat bindings for the Lua language version 5.1
@stevedonovan
stevedonovan / mockup.ltp
Created October 11, 2012 05:59
Penlight-style Lua template for HTML with JavaScript; note @ used as escape!
<!DOCTYPE HTML>
<html>
<head>
<script src="/flot/jquery.min.js" type="text/javascript"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="/media/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.min.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.navigate.js"></script>
<style type="text/css">
.center { text-align:center; }
@stevedonovan
stevedonovan / struct.lua
Created November 19, 2012 12:56
'Strict' Structs in Lua.
-- struct.lua
--- defining a struct constructor ---
local function ordered_map (t)
local fields,keys = {},{}
for i,item in ipairs(t) do
local key,value = next(item)
fields[key] = value
keys[i] = key
end