--- a/main.c Wed Feb 25 22:58:34 2009 +0200
+++ b/main.c Thu Feb 26 01:05:02 2009 +0200
@@ -322,6 +322,34 @@
// MCABBER COMMANDS
+/// completion type
+/// Built-it completion types can be specified as string, instead of id.
+/// G:
+static const string2enum_t lua_completion_type[] = {
+ { "cmd", COMPL_CMD },
+ { "jid", COMPL_JID },
+ { "urljid", COMPL_URLJID },
+ { "name", COMPL_NAME },
+ { "status", COMPL_STATUS },
+ { "filename", COMPL_FILENAME },
+ { "roster", COMPL_ROSTER },
+ { "buffer", COMPL_BUFFER },
+ { "group", COMPL_GROUP },
+ { "groupname", COMPL_GROUPNAME },
+ { "multiline", COMPL_MULTILINE },
+ { "room", COMPL_ROOM },
+ { "resource", COMPL_RESOURCE },
+ { "auth", COMPL_AUTH },
+ { "request", COMPL_REQUEST },
+ { "events", COMPL_EVENTS },
+ { "eventsid", COMPL_EVENTSID },
+ { "pgp", COMPL_PGP },
+ { "color", COMPL_COLOR },
+ { "otr", COMPL_OTR },
+ { "ortpolicy", COMPL_OTRPOLICY },
+ { NULL, 0 },
+};
+
typedef struct {
int reference;
lua_State *L;
@@ -366,11 +394,11 @@
/// Associates or breaks association between mcabber command name and lua function.
/// To unregister command omit function argument.
/// If you specify a third argument, table (even empty), function will return completion group id or nothing.
-/// You can also specify an integer instead of table, then no new id will be registered.
+/// You can also specify a string name (see completion type) instead of table, for non-builtin, you can just pass integer id.
/// Note, that for now there are no way to unregister completion group, so, resources can be exausted easily.
/// Also note, that it ignores keys in a completion table.
-/// A: string (command name), command function (optional), table (completions, optional)/integer (comletion group id, optional)
-/// R: integer (completion group id, optional) or nil
+/// A: string (command name), command function (optional), table (completions, optional)/completion type (or integer comletion group id, optional)
+/// R: completion type (integer completion group id or string for builtin types, optional)
static int lua_main_command (lua_State *L)
{
const char *name = luaL_checkstring (L, 1);
@@ -390,7 +418,7 @@
}
}
} else
- cid = luaL_checkinteger (L, 3);
+ cid = luaL_checkenum (L, 3, lua_completion_type);
}
cb = luaL_malloc (L, sizeof (lua_command_callback_t));
@@ -402,7 +430,7 @@
lua_added_commands = g_slist_prepend (lua_added_commands, g_strdup (name));
if (cid) {
- lua_pushinteger (L, cid);
+ luaL_pushenum (L, cid, lua_completion_type);
return 1;
}
} else { // Unregister