# HG changeset patch # User Myhailo Danylenko # Date 1237175890 -7200 # Node ID 524fde5be49abd30309abd05be227c3dcdb86cde # Parent 54957980a83a4038afeca9e4f40e3bcb662a344b Yesno completion in C diff -r 54957980a83a -r 524fde5be49a examples/beep.lua --- a/examples/beep.lua Mon Mar 16 05:31:24 2009 +0200 +++ b/examples/beep.lua Mon Mar 16 05:58:10 2009 +0200 @@ -15,7 +15,7 @@ hooks_d['hook-message-in'].beep = nil print ( "Beep on message is disabled" ) end - end, boolean_cid ) + end, 'yesno' ) commands_help['beep'] = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables beeping on all messages.\nIf state is omitted, prints current state." diff -r 54957980a83a -r 524fde5be49a examples/mcabberrc.lua --- a/examples/mcabberrc.lua Mon Mar 16 05:31:24 2009 +0200 +++ b/examples/mcabberrc.lua Mon Mar 16 05:58:10 2009 +0200 @@ -87,6 +87,7 @@ -- COMMON SUPPORT ROUTINES +-- unused :/ function shell_escape ( str ) if str then return "'" .. str:gsub ( "'", "'\\''" ) .. "'" @@ -115,22 +116,6 @@ end end -function online ( jid ) - local info = main.buddy_info ( jid ) - if not info then - return false - end - for resource, params in pairs ( info.resources ) do - if params.status ~= '_' then - return true - end - end - return false -end - --- XXX to C -boolean_cid = main.add_category { 'enable', 'disable', 'yes', 'no', 'true', 'false', 'on', 'off' } - -- COMMANDS -- Help strings should not contain command, only arguments. This is necessary to support soft aliases. @@ -264,15 +249,15 @@ dopath 'marking' --- FORMS (XEP-0004) +-- DATA FORMS (XEP-0004) dopath 'xep0004' --- DISCO (XEP-0030) +-- SERVICE DISCOVERY (XEP-0030) dopath 'xep0030' --- IBB (XEP-0047) +-- IN-BOUND BYTESTREAMS (XEP-0047) dopath 'xep0047' diff -r 54957980a83a -r 524fde5be49a examples/transports.lua --- a/examples/transports.lua Mon Mar 16 05:31:24 2009 +0200 +++ b/examples/transports.lua Mon Mar 16 05:58:10 2009 +0200 @@ -3,6 +3,19 @@ -- XXX: to option? transport_jids = { 'icq.jabber.kiev.ua', 'mrim.unixzone.org.ua' } +function online ( jid ) + local info = main.buddy_info ( jid ) + if not info then + return false + end + for resource, params in pairs ( info.resources ) do + if params.status ~= '_' then + return true + end + end + return false +end + hooks_d['hook-status-change'].transports = function ( args ) for k, jid in pairs ( transport_jids ) do diff -r 54957980a83a -r 524fde5be49a examples/xep0163.lua --- a/examples/xep0163.lua Mon Mar 16 05:31:24 2009 +0200 +++ b/examples/xep0163.lua Mon Mar 16 05:58:10 2009 +0200 @@ -266,7 +266,7 @@ else enable_tune ( enable ) end - end, boolean_cid ) + end, 'yesno' ) main.command ( 'mood', function ( args ) args = main.parse_args ( args ) diff -r 54957980a83a -r 524fde5be49a main.c --- a/main.c Mon Mar 16 05:31:24 2009 +0200 +++ b/main.c Mon Mar 16 05:58:10 2009 +0200 @@ -515,7 +515,7 @@ /// completion type /// Built-it completion types can be specified as string, instead of id. /// G: -static const string2enum_t lua_completion_type[] = { +static string2enum_t lua_completion_type[] = { // not const, we need to modify yesno { "cmd", COMPL_CMD }, { "jid", COMPL_JID }, { "urljid", COMPL_URLJID }, @@ -537,8 +537,10 @@ { "color", COMPL_COLOR }, { "otr", COMPL_OTR }, { "ortpolicy", COMPL_OTRPOLICY }, + { "yesno", 0 }, { NULL, 0 }, }; +#define MLUA_YESNO_POS ( 21 ) typedef struct { int reference; @@ -1058,6 +1060,20 @@ lua_register (lua, "dopath", lua_global_dopath); lua_register (lua, "print", lua_global_print ); + { + int cid = compl_new_category (); + + if (cid) { + const string2enum_t *word = lua_yesno; + lua_completion_type[MLUA_YESNO_POS].value = cid; + lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid); + while (word->string) { + compl_add_category_word (cid, word->string); + ++word; + } + } + } + cmd_add ("lua", "Evaluate lua string", 0, 0, (void (*) (char *p)) do_lua, lua); #ifdef LLM_LOG_HANDLER