[cvslog] Module eggdrop1.7: Change committed

cvslog cvs at tsss.org
Sun Oct 14 12:00:04 CST 2001


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.7
Commit time: 2001-10-14 16:59:41 UTC
Commited by: stdarg <stdarg at techmonkeys.org>

Modified files:
     src/script.c src/script_api.h src/mod/tclscript.mod/tclscript.c

Log message:

Added a convenience function, made normal c functions easy to wrap, added a SCRIPT_USER type (handle <--> struct userrec *)

---------------------- diff included ----------------------
Index: eggdrop1.7/src/mod/tclscript.mod/tclscript.c
diff -u eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.1 eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.2
--- eggdrop1.7/src/mod/tclscript.mod/tclscript.c:1.1	Sat Oct 13 23:46:56 2001
+++ eggdrop1.7/src/mod/tclscript.mod/tclscript.c	Sun Oct 14 11:59:31 2001
@@ -209,6 +209,14 @@
 		sprintf(str, "%#x", v->ptr);
 		result = Tcl_NewStringObj(str, -1);
 	}
+	else if (v->type & SCRIPT_USER) {
+		char *handle;
+		struct userrec *u = (struct userrec *)v->ptr;
+
+		if (u) handle = u->handle;
+		else handle = "*";
+		result = Tcl_NewStringObj(handle, -1);
+	}
 	else {
 		result = Tcl_NewStringObj("unsupported return type", -1);
 	}
@@ -270,6 +278,17 @@
 			arg = (void *)cback;
 			break;
 		}
+		case 'U': { /* User. */
+			struct userrec *u;
+			char *handle;
+
+			handle = Tcl_GetStringFromObj(objptr, NULL);
+			if (handle) u = get_user_by_handle(userlist, handle);
+			else u = NULL;
+
+			arg = (void *)u;
+			break;
+		}
 		case 'l': { /* Length of previous string or byte-array. */
 			arg = (void *)len;
 			i--; /* Doesn't take up a Tcl object. */
@@ -340,15 +359,24 @@
 
 	memset(&retval, 0, sizeof(retval));
 
+	al = (void **)argstack.args->stack; /* Argument list shortcut name. */
+
 	/* If they don't want their client data, bump the pointer. */
-	al = (void **)argstack.args->stack; /* Just a short cut name. */
 	if (!(cmd->flags & SCRIPT_WANTS_CD)) {
 		al++;
 		argstack.args->len--;
 	}
 
-	if (cmd->pass_array) cmd->callback(&retval, argstack.args->len, al);
-	else cmd->callback(&retval, al[0], al[1], al[2], al[3], al[4]);
+	if (cmd->flags & SCRIPT_COMPLEX) {
+		if (cmd->pass_array) cmd->callback(&retval, argstack.args->len, al);
+		else cmd->callback(&retval, al[0], al[1], al[2], al[3], al[4]);
+	}
+	else {
+		retval.type = cmd->retval_type;
+		retval.len = -1;
+		if (cmd->pass_array) retval.intval = cmd->callback(&retval, argstack.args->len, al);
+		else retval.intval = cmd->callback(al[0], al[1], al[2], al[3], al[4]);
+	}
 
 	my_err = retval.type & SCRIPT_ERROR;
 	retval.flags |= SCRIPT_STATIC; /* We don't want to segfault. */
Index: eggdrop1.7/src/script.c
diff -u eggdrop1.7/src/script.c:1.1 eggdrop1.7/src/script.c:1.2
--- eggdrop1.7/src/script.c:1.1	Sat Oct 13 23:44:36 2001
+++ eggdrop1.7/src/script.c	Sun Oct 14 11:59:30 2001
@@ -80,3 +80,27 @@
 	}
 	return(0);
 }
+
+int script_create_simple_cmd_table(script_simple_command_t *table)
+{
+	script_command_t *cmd;
+	char *class;
+
+	/* First entry gives the class. */
+	class = table->name;
+	table++;
+
+	while (table->name) {
+		cmd = (script_command_t *)calloc(1, sizeof(*cmd));
+		cmd->class = class;
+		cmd->name = table->name;
+		cmd->callback = table->callback;
+		cmd->nargs = strlen(table->syntax);
+		cmd->syntax = table->syntax;
+		cmd->syntax_error = table->syntax_error;
+		cmd->retval_type = table->retval_type;
+		create_cmd(create_cmd_h, cmd);
+		table++;
+	}
+	return(0);
+}
Index: eggdrop1.7/src/script_api.h
diff -u eggdrop1.7/src/script_api.h:1.1 eggdrop1.7/src/script_api.h:1.2
--- eggdrop1.7/src/script_api.h:1.1	Sat Oct 13 23:44:36 2001
+++ eggdrop1.7/src/script_api.h	Sun Oct 14 11:59:30 2001
@@ -9,6 +9,7 @@
 
 /* Flags for commands. */
 #define SCRIPT_WANTS_CD	1
+#define SCRIPT_COMPLEX	2
 
 /* Flags for linked variables. */
 #define SCRIPT_READ_ONLY	1
@@ -22,7 +23,12 @@
 #define SCRIPT_VARRAY	32
 #define SCRIPT_POINTER	64
 #define SCRIPT_CALLBACK	128
-#define SCRIPT_ERROR	256
+
+/* Eggdrop specific types. */
+#define SCRIPT_USER	256
+
+/* Error bit. */
+#define SCRIPT_ERROR	512
 
 typedef struct script_callback_b {
 	int (*callback)();
@@ -68,7 +74,16 @@
 	int pass_array; /* Want an array of stuff? */
 	char *syntax; /* Argument types. */
 	char *syntax_error; /* Error to print when called incorrectly. */
+	int retval_type; /* Limited return value type, for simple stuff. */
 	int flags;
 } script_command_t;
+
+typedef struct script_simple_command_b {
+	char *name;
+	Function callback;
+	char *syntax;
+	char *syntax_error;
+	int retval_type;
+} script_simple_command_t;
 
 #endif
----------------------- End of diff -----------------------



More information about the Changes mailing list