httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian McCallister <bri...@apache.org>
Subject [mod_wombat] UserData Metatables
Date Sun, 06 May 2007 05:54:14 GMT
I am leaning towards changing all the userdata types (request_rec,  
server_rec, conn_rec, apr_table_t) in mod_wombat to have anonymous  
metatables rather than the current setup where they share a metatable.

The benefit of going to a per-instance metatable is that we can curry  
the relevant struct onto the relevant CFunctions when we push the  
metatable. This would allow much saner dispatch of functions,  
indxeing of properties etc. The current scheme is kind of broken in  
that you can only have one of each type at a time.

The drawback is that we lose the ~"type safety" of being able to use  
luaL_checkuserdata(...) to  pop userdata with a specific metatable  
out of the stack.

This would do arbitrary lookups on userdata as though it were a lua  
table:

r.headers_in, r.status, etc.

It may be possible, depending on the exact semantics, to use __index  
and __newindex overloading with the OO syntax:

r:headers_in
r:status

to maintain the current setup of a single metatable, but I am not  
sure exactly how this behaves. Hopefully I will have a chance to play  
with it tomorrow and see. If it passes the userdata instances to  
__index then we can dispatch in __index and be in pretty good shape.  
I have a funny feeling it is going to not work though as it really  
wants a function invocation for the : syntax.

-Brian

Mime
View raw message