On 5/12/10 11:09 AM, "Brian McCallister" <[email protected]> wrote:
> Ah, but what happens when there are multiple functions for same hook?
> We could get into magic naming and scanning of global scope, but that
> really turns my stomach.
No need. It's easy. Think about it in lua, not C.
Something like this for a loader:
handlers = { }
-- mods is an array of modules. Probably passed in via post_config or
something. Hooks is an array of hook names
function load_stuff(mods, hooks)
-- try to load each mod like
local m = require 'modname'
-- now examine m for functions named in hooks
if m.functionname add to my array
end
Then in you runner something like
function hook_runner(r, hook_name)
-- look in handlers for hook_name. It should be an array of functions
-- call them, with r as the single argument until one returns something
-- other than declined
end
> Conceptually, we probably don't want different script authors
> stomping on each other anyway.
Forcing the use of modules rather than standalone scripts helps this some.
We loose a lot of the efficiencies of lua because of the design of worker,
prefork, event, etc. Lua Strings, memory, etc, per thread -- with lots of
threads - seems wasteful. But that's a larger discussion.
FWIW, I do a lot of lua now. We use it in almost every web server config
now.
--
Brian Akins