--- a/src/x509.c Sat Nov 20 20:04:11 2010 -0800 +++ b/src/x509.c Sat Nov 20 20:04:11 2010 -0800 @@ -264,6 +264,13 @@ return 0; } +int meth_tostring(lua_State *L) +{ + X509 *cert = luasec_to_x509(L, 1); + lua_pushfstring(L, "X509 certificate: %p", cert); + return 1; +} + int cert_from_pem(lua_State* L) { X509 *cert; @@ -283,7 +290,7 @@ /** * Certificate metamethods */ -static luaL_Reg meta[] = { +static luaL_Reg methods[] = { {"subject", meth_subject}, {"issuer", meth_issuer}, {"extensions", meth_extensions}, @@ -301,15 +308,24 @@ {NULL, NULL} }; +/** + * Context metamethods. + */ +static luaL_Reg meta[] = { + {"__gc", meth_destroy}, + {"__tostring", meth_tostring}, + {NULL, NULL} +}; + LUASEC_API int luaopen_ssl_x509(lua_State *L) { /* Register the functions and tables */ luaL_newmetatable(L, "SSL:Certificate"); + luaL_register(L, NULL, meta); + lua_newtable(L); - luaL_register(L, NULL, meta); + luaL_register(L, NULL, methods); lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, meth_destroy); - lua_setfield(L, -2, "__gc"); luaL_register(L, "ssl.x509", funcs); return 1;