Joshua Wise

lua-users home
wiki

Difference (from prior major revision) (no other diffs)

Changed: 56,73c56
* Wrote a quick hooks library to demonstrate a better way to do something than

for k,v in pairs(files_in_directory) do
dofile(v)
client_command(...)
client_command = nil
end

to someone on IRC. Get it from http://joshuawise.com/hooks.lua . A quick test for it is:

require"hooks"
myhooks = {}
myhooks.test = hooks:new()
myhooks.ref1 = myhooks.test:insert(function (foo, bar) print("Test 1", foo, bar) end, 100)
myhooks.ref2 = myhooks.test:insert(function (foo, bar) print("Test 2", foo, bar) end, 50)
myhooks.ref3 = myhooks.test:insert(function (foo, bar) print("Test 3", foo, bar) end, 150)
print"--"
myhooks.test("Hello", "world")
myhooks.test:remove(myhooks.ref1)
print"--"
myhooks.test("Hello", "world")

Should prove useful. This is similar to how naim does its hooks, although all of the hook glue in naim happens in C. Remaining to do: provide support for writable arguments. Patches thoughtfully accepted. This is part of my "Joshua's Lua Hack of the Day" series, and was originally written on 2007-02-01.
* Wrote the hooks setup on LuaDesignPatterns. This was part of my "Joshua's Lua Hack of the Day" series, and was originally written on 2007-02-01.

Hi. I'm Joshua Wise. I do some level of work with Lua. Most recently, I've been working on support in naim (the ncurses AIM/IRC client -- http://naim.n.ml.org/ ) for Lua -- check out the NaimLua? page (which may or may not exist).

I've also been doing some other random stuff lately. RiciLake suggested that I start documenting stuff, so as I find interesting things that I've done, I'll post them here. Like him, I can be found on the IRC channel, which is available at irc://irc.freenode.net/#lua -- my username is usually joshua_. If you're looking for me elsewhere on the web, try http://joshuawise.com/ .

Code

Chat and Messages


RecentChanges · preferences
edit · history
Last edited February 6, 2007 6:12 pm GMT (diff)