804 { "eventsid", COMPL_EVENTSID }, |
804 { "eventsid", COMPL_EVENTSID }, |
805 { "pgp", COMPL_PGP }, |
805 { "pgp", COMPL_PGP }, |
806 { "color", COMPL_COLOR }, |
806 { "color", COMPL_COLOR }, |
807 { "otr", COMPL_OTR }, |
807 { "otr", COMPL_OTR }, |
808 { "ortpolicy", COMPL_OTRPOLICY }, |
808 { "ortpolicy", COMPL_OTRPOLICY }, |
|
809 { "module", COMPL_MODULE }, |
809 { "yesno", 0 }, |
810 { "yesno", 0 }, |
810 { NULL, 0 }, |
811 { NULL, 0 }, |
811 }; |
812 }; |
812 #define MLUA_YESNO_POS ( 21 ) |
813 #define MLUA_YESNO_POS ( 22 ) |
|
814 |
|
815 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |
|
816 /// completion sorting order |
|
817 /// Sorting order for completion category. |
|
818 /// G: |
|
819 static const string2enum_t lua_completion_sortorder[] = { |
|
820 { "sort", COMPL_FLAGS_SORT }, |
|
821 { "direct", COMPL_FLAGS_SORT }, |
|
822 { "reverse", COMPL_FLAGS_REVERSE }, |
|
823 { "append", COMPL_FLAGS_APPEND }, |
|
824 { "prepend", COMPL_FLAGS_PREPEND }, |
|
825 { NULL, 0 }, |
|
826 }; |
|
827 #endif |
813 |
828 |
814 typedef struct { |
829 typedef struct { |
815 int cbref; |
830 int cbref; |
816 int parse_args; |
831 int parse_args; |
817 #ifdef MCABBER_API_HAVE_CMD_ID |
832 #ifdef MCABBER_API_HAVE_CMD_ID |
964 return 1; |
979 return 1; |
965 } |
980 } |
966 |
981 |
967 /// main.add_category |
982 /// main.add_category |
968 /// Adds completion category. |
983 /// Adds completion category. |
969 /// A: table (values are used as words for completion, optional) |
984 /// A: table (values are used as words for completion, optional), argument enum value (completion sorting order, optional) |
970 /// R: integer (category id, in fact completion type) or nil |
985 /// R: integer (category id, in fact completion type) or nil |
971 static int lua_main_add_category (lua_State *L) |
986 static int lua_main_add_category (lua_State *L) |
972 { |
987 { |
973 guint cid; |
988 guint cid; |
974 |
989 int top = lua_gettop ( L ); |
975 if (lua_gettop (L) > 0) { |
990 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |
976 luaL_argcheck (L, lua_type (L, 1) == LUA_TTABLE, 1, "table expected"); |
991 if ( top > 1 ) |
977 cid = compl_new_category (); |
992 cid = compl_new_category ( luaL_checkenum ( L, 2, lua_completion_sortorder ) ); |
978 if (cid) { |
993 else |
979 lua_pushnil (L); |
994 cid = compl_new_category ( COMPL_FLAGS_SORT ); |
980 while (lua_next (L, 1)) { |
995 #else |
981 char *word = to_utf8 (luaL_checkstring (L, -1)); |
996 cid = compl_new_category (); |
982 if (word) { |
997 #endif |
983 compl_add_category_word (cid, word); |
998 if ( cid ) { |
984 g_free (word); |
999 if ( ( top > 0 ) && ( lua_type ( L, 1 ) == LUA_TTABLE ) ) { |
|
1000 lua_pushnil ( L ); |
|
1001 while ( lua_next ( L, 1 ) ) { |
|
1002 char * word = to_utf8 ( lua_tostring ( L, 4 ) ); |
|
1003 if ( word ) { |
|
1004 compl_add_category_word ( cid, word ); |
|
1005 g_free ( word ); |
985 } |
1006 } |
986 lua_pop (L, 1); |
1007 lua_pop ( L, 1 ); |
987 } |
1008 } |
988 } |
1009 } |
|
1010 |
|
1011 lua_added_categories = g_slist_prepend ( lua_added_categories, (gpointer) ((gsize) cid) ); |
|
1012 lua_pushinteger ( L, cid ); |
989 } else |
1013 } else |
990 cid = compl_new_category (); |
1014 lua_pushnil ( L ); |
991 |
|
992 if (cid) { |
|
993 lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) ((gsize) cid)); |
|
994 lua_pushinteger (L, cid); |
|
995 } else |
|
996 lua_pushnil (L); |
|
997 |
1015 |
998 return 1; |
1016 return 1; |
999 } |
1017 } |
1000 |
1018 |
1001 /// main.del_category |
1019 /// main.del_category |
1052 if (top > 2) { // parse flag provided |
1070 if (top > 2) { // parse flag provided |
1053 parse = lua_toboolean (L, 3); |
1071 parse = lua_toboolean (L, 3); |
1054 |
1072 |
1055 if (top > 3) { // Completions provided |
1073 if (top > 3) { // Completions provided |
1056 if (lua_type (L, 4) == LUA_TTABLE) { |
1074 if (lua_type (L, 4) == LUA_TTABLE) { |
|
1075 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |
|
1076 cid = compl_new_category (COMPL_FLAGS_SORT); |
|
1077 #else |
1057 cid = compl_new_category (); |
1078 cid = compl_new_category (); |
|
1079 #endif |
1058 if (cid) { |
1080 if (cid) { |
1059 lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) ((gsize) cid)); |
1081 lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) ((gsize) cid)); |
1060 lua_pushnil (L); |
1082 lua_pushnil (L); |
1061 while (lua_next (L, 4)) { |
1083 while (lua_next (L, 4)) { |
1062 char *word = to_utf8 (luaL_checkstring (L, -1)); |
1084 char *word = to_utf8 (luaL_checkstring (L, -1)); |
1762 lua_pop (lua, 1); // XXX |
1784 lua_pop (lua, 1); // XXX |
1763 lua_register (lua, "dopath", lua_global_dopath); |
1785 lua_register (lua, "dopath", lua_global_dopath); |
1764 lua_register (lua, "print", lua_global_print ); |
1786 lua_register (lua, "print", lua_global_print ); |
1765 |
1787 |
1766 { |
1788 { |
|
1789 #ifdef MCABBER_API_HAVE_COMPL_FLAGS |
|
1790 int cid = compl_new_category (COMPL_FLAGS_PREPEND); |
|
1791 #else |
1767 int cid = compl_new_category (); |
1792 int cid = compl_new_category (); |
|
1793 #endif |
1768 |
1794 |
1769 if (cid) { |
1795 if (cid) { |
1770 const string2enum_t *word = lua_yesno; |
1796 const string2enum_t *word = lua_yesno; |
1771 lua_completion_type[MLUA_YESNO_POS].value = cid; |
1797 lua_completion_type[MLUA_YESNO_POS].value = cid; |
1772 lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) ((gsize) cid)); |
1798 lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) ((gsize) cid)); |