On 23/05/2012, at 8:55 AM, Leif Hedstrom wrote:
> On 5/22/12 9:39 PM, James Peach wrote:
>> On 11/05/2012, at 10:21 AM, James Peach wrote:
>> I thought a bit more about how the remap and full APIs can be supported.
>> Currently the remap plugin looks for global functions called 'init' and
>> 'remap' respectively.
>>
>> We don't really need 'init' because you can just run code at global scope
>> when the source file is loaded; so 'init' can go away. I think that the
>> global 'remap' function can go away too in favour of explicitly registering
>> a remap callback, eg.
>>
>> TS.remap(function(request) {
>> -- do stuff here
>> })
>>
>> This will match the hook function that I'm thinking of, eg:
>>
>> TS.hook(TS.HttpReadRequestHeader, function(foo1, foo2) {
>> -- do stuff here
>> })
>>
>>
>
> +1.
>
> Is there a reason not to use the same naming conventions as we already have
> in <ts/ts.h>? So e.g. instead we'd have TS.HTTP_READ_REQUEST_HDR_HOOK (I
> ditched the TS_ prefix intentionally, since TS. sort of becomes our prefix).
That seemed a bit ugly compared to the Lua conventions I have seen. Not that
I've seen all that many :)
>
> Also, perhaps we should be a bit more "explicit" on the method names for
> adding a hook remap? E.g.
>
> TS.HttpHookAdd()
> TS.HttpSsnHookAdd()
> TS.HttpTxnHookAdd()
I think that TSHttpTxnHookAdd() and TSHttpSsnHookAdd() might end up being a
member functions. But I agree that a more explicit name is better.
Actually we could go further and break out the hooks into discrete functions,
eg:
TS.HttpReadRequestHeader(function(foo1, foo2)
-- do stuff
end)
>
> and perhaps e.g.
>
> TS.DoRemap()
>
> (or some such).
>
> This again maps to what we would use in C/C++. Even if we only implement the
> HttpHookAdd() for now, it avoids confusion further down the road I think?
I'm not sure about this. I agree that paralleling the C API has documentation
and familiarity benefits, but the Lua API can be higher level and more
"natural".
>
> Cheers,
>
> -- leif
>