--- a/src/ssl.c Sat Nov 20 20:04:11 2010 -0800 +++ b/src/ssl.c Sat Nov 20 20:04:11 2010 -0800 @@ -60,6 +60,16 @@ } /** + * Object information -- tostring metamethod + */ +static int meth_tostring(lua_State *L) +{ + p_ssl ssl = (p_ssl)lua_touserdata(L, 1); + lua_pushfstring(L, "SSL connection: %p", ssl); + return 1; +} + +/** * Perform the TLS/SSL handshake */ static int handshake(p_ssl ssl) @@ -455,7 +465,7 @@ /** * SSL metamethods */ -static luaL_Reg meta[] = { +static luaL_Reg methods[] = { {"close", meth_close}, {"getfd", meth_getfd}, {"dirty", meth_dirty}, @@ -483,6 +493,15 @@ }; /** + * Context metamethods. + */ +static luaL_Reg meta[] = { + {"__gc", meth_destroy}, + {"__tostring", meth_tostring}, + {NULL, NULL} +}; + +/** * Initialize modules */ LUASEC_API int luaopen_ssl_core(lua_State *L) @@ -499,11 +518,11 @@ /* Register the functions and tables */ luaL_newmetatable(L, "SSL:Connection"); + 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.core", funcs); lua_pushnumber(L, SOCKET_INVALID);