aboutsummaryrefslogtreecommitdiffstats
path: root/lualdap/src
diff options
context:
space:
mode:
authorTomas Guisasola <tomas@luaforge.net>2003-12-02 14:25:09 +0000
committerTomas Guisasola <tomas@luaforge.net>2003-12-02 14:25:09 +0000
commitc46a6cdf769c066f76d0652a78d21f2bd12e07cd (patch)
tree27196a9e8e2551c6f56831d39175f12d1dc83886 /lualdap/src
parentMelhoria na pagina de apresentacao. (diff)
downloadlualdap-c46a6cdf769c066f76d0652a78d21f2bd12e07cd.tar.xz
lualdap-c46a6cdf769c066f76d0652a78d21f2bd12e07cd.zip
Acrescimo de arquivo com a licenca.
Acrescimo de metamethods para __tostring. Acrescimo da introducao no manual.
Diffstat (limited to 'lualdap/src')
-rwxr-xr-xlualdap/src/lualdap.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/lualdap/src/lualdap.c b/lualdap/src/lualdap.c
index e48087d..0de04a9 100755
--- a/lualdap/src/lualdap.c
+++ b/lualdap/src/lualdap.c
@@ -1,6 +1,7 @@
/*
** LuaLDAP
-** $Id: lualdap.c,v 1.25 2003-09-04 15:41:53 tomas Exp $
+** See Copyright Notice in license.html
+** $Id: lualdap.c,v 1.26 2003-12-02 14:25:09 tomas Exp $
*/
#include <stdlib.h>
@@ -810,6 +811,39 @@ static int lualdap_search (lua_State *L) {
/*
+** Return the name of the object's metatable.
+** This function is used by `tostring'.
+*/
+static int lualdap_conn_tostring (lua_State *L) {
+ char buff[100];
+ conn_data *conn = (conn_data *)lua_touserdata (L, 1);
+ if (conn->ld == NULL)
+ strcpy (buff, "closed");
+ else
+ sprintf (buff, "%p", conn);
+ lua_pushfstring (L, "%s (%s)", LUALDAP_CONNECTION_METATABLE, buff);
+ return 1;
+}
+
+
+/*
+** Return the name of the object's metatable.
+** This function is used by `tostring'.
+*/
+static int lualdap_search_tostring (lua_State *L) {
+ char buff[100];
+ search_data *search = (search_data *)lua_touserdata (L, 1);
+ luaL_argcheck (L,search->conn!=LUA_NOREF,1,LUALDAP_PREFIX"LDAP search is closed");
+ if (search->conn == LUA_NOREF)
+ strcpy (buff, "closed");
+ else
+ sprintf (buff, "%p", search);
+ lua_pushfstring (L, "%s (%s)", LUALDAP_SEARCH_METATABLE, buff);
+ return 1;
+}
+
+
+/*
** Create a metatable.
*/
static int lualdap_createmeta (lua_State *L) {
@@ -839,6 +873,10 @@ static int lualdap_createmeta (lua_State *L) {
lua_pushvalue (L, -2);
lua_settable (L, -3);
+ lua_pushliteral (L, "__tostring");
+ lua_pushcfunction (L, lualdap_conn_tostring);
+ lua_settable (L, -3);
+
lua_pushliteral (L, "__metatable");
lua_pushliteral(L,LUALDAP_PREFIX"you're not allowed to get this metatable");
lua_settable (L, -3);
@@ -850,6 +888,10 @@ static int lualdap_createmeta (lua_State *L) {
lua_pushcfunction (L, lualdap_search_close);
lua_settable (L, -3);
+ lua_pushliteral (L, "__tostring");
+ lua_pushcclosure (L, lualdap_search_tostring, 1);
+ lua_settable (L, -3);
+
lua_pushliteral (L, "__metatable");
lua_pushliteral(L,LUALDAP_PREFIX"you're not allowed to get this metatable");
lua_settable (L, -3);