main.c
changeset 15 b224cbc7b8be
parent 14 ff13ba17fb6d
child 17 3a12759a22b1
equal deleted inserted replaced
14:ff13ba17fb6d 15:b224cbc7b8be
   217 		return 1;
   217 		return 1;
   218 	}
   218 	}
   219 }
   219 }
   220 
   220 
   221 /// main.bind
   221 /// main.bind
   222 /// Sets or gets alias.
   222 /// Sets or gets binding.
   223 /// You can specify nil as a command to unbind key.
   223 /// You can specify nil as a command to unbind key.
   224 /// If you omit keycode, it will return hash table of all bindings.
   224 /// If you omit keycode, it will return hash table of all bindings.
   225 /// A: string (keycode, optional), string (command, optional)
   225 /// A: string (keycode, optional), string (command, optional)
   226 /// R: string (command, optional)
   226 /// R: string (command, optional)
   227 static int lua_main_alias (lua_State *L)
   227 static int lua_main_binding (lua_State *L)
   228 {
   228 {
   229 	int top = lua_gettop (L);
   229 	int top = lua_gettop (L);
   230 	if (top > 0) {
   230 	if (top > 0) {
   231 		// just to be sure...
   231 		// just to be sure...
   232 		char *name = to_utf8 (luaL_checkstring (L, 1));
   232 		char *name = to_utf8 (luaL_checkstring (L, 1));
   549 /// A: table (values are used as words for completion, optional)
   549 /// A: table (values are used as words for completion, optional)
   550 /// R: integer (category id, in fact completion type) or nil
   550 /// R: integer (category id, in fact completion type) or nil
   551 static int lua_main_add_category (lua_State *L)
   551 static int lua_main_add_category (lua_State *L)
   552 {
   552 {
   553 	guint cid;
   553 	guint cid;
   554 	if (lua_gettop (L) > 0)
   554 	if (lua_gettop (L) > 0) {
   555 		luaL_argcheck (L, lua_type (L, 1) == LUA_TTABLE, 1, "table expected");
   555 		luaL_argcheck (L, lua_type (L, 1) == LUA_TTABLE, 1, "table expected");
   556 		cid = compl_new_category ();
   556 		cid = compl_new_category ();
   557 		if (cid) {
   557 		if (cid) {
   558 			lua_pushnil (L);
   558 			lua_pushnil (L);
   559 			while (lua_next (L, 3)) {
   559 			while (lua_next (L, 3)) {
   566 			}
   566 			}
   567 		}
   567 		}
   568 	} else
   568 	} else
   569 		cid = compl_new_category ();
   569 		cid = compl_new_category ();
   570 	if (cid) {
   570 	if (cid) {
   571 		lua_added_categories = g_slist_prepend (lua_added_categories, (gpoiner) cid);
   571 		lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid);
   572 		lua_pushinteger (L, cid);
   572 		lua_pushinteger (L, cid);
   573 	} else
   573 	} else
   574 		lua_pushnil (L);
   574 		lua_pushnil (L);
   575 	return 1;
   575 	return 1;
   576 }
   576 }
   627 
   627 
   628 		if (lua_gettop (L) > 2) { // Completions provided
   628 		if (lua_gettop (L) > 2) { // Completions provided
   629 			if (lua_type (L, 3) == LUA_TTABLE) {
   629 			if (lua_type (L, 3) == LUA_TTABLE) {
   630 				cid = compl_new_category ();
   630 				cid = compl_new_category ();
   631 				if (cid) {
   631 				if (cid) {
   632 					lua_added_categories = g_slist_prepend (lua_added_categories, (gpoiner) cid);
   632 					lua_added_categories = g_slist_prepend (lua_added_categories, (gpointer) cid);
   633 					lua_pushnil (L);
   633 					lua_pushnil (L);
   634 					while (lua_next (L, 3)) {
   634 					while (lua_next (L, 3)) {
   635 						char *word = to_utf8 (luaL_checkstring (L, -1));
   635 						char *word = to_utf8 (luaL_checkstring (L, -1));
   636 						compl_add_category_word (cid, word);
   636 						compl_add_category_word (cid, word);
   637 						lua_pop (L, 1);
   637 						lua_pop (L, 1);