mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Lua
- Created new scripts/extensions directory. - Added README for extensions. - Started priority.lua extension. - Implemented api_task_get and api_task_set DOM accessors. - Removed more obsolete API.
This commit is contained in:
parent
9d0037bc78
commit
2f4efb28d6
4 changed files with 86 additions and 70 deletions
|
@ -1 +1 @@
|
|||
install (DIRECTORY bash fish vim zsh add-ons DESTINATION ${TASK_DOCDIR}/scripts)
|
||||
install (DIRECTORY bash fish vim zsh add-ons extensions DESTINATION ${TASK_DOCDIR}/scripts)
|
||||
|
|
8
scripts/extensions/README
Normal file
8
scripts/extensions/README
Normal file
|
@ -0,0 +1,8 @@
|
|||
There are several types of extension:
|
||||
|
||||
- Hook-based
|
||||
- User Defined Attribute
|
||||
- Command
|
||||
- Format
|
||||
- DOM
|
||||
|
42
scripts/extensions/priority.lua
Normal file
42
scripts/extensions/priority.lua
Normal file
|
@ -0,0 +1,42 @@
|
|||
--------------------------------------------------------------------------------
|
||||
-- taskwarrior - a command line task list manager.
|
||||
--
|
||||
-- Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
|
||||
-- All rights reserved.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify it under
|
||||
-- the terms of the GNU General Public License as published by the Free Software
|
||||
-- Foundation; either version 2 of the License, or (at your option) any later
|
||||
-- version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
-- details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License along with
|
||||
-- this program; if not, write to the
|
||||
--
|
||||
-- Free Software Foundation, Inc.,
|
||||
-- 51 Franklin Street, Fifth Floor,
|
||||
-- Boston, MA
|
||||
-- 02110-1301
|
||||
-- USA
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Extension to implement 'priority' as a user-defined attribute.
|
||||
|
||||
-- Required for all extensions.
|
||||
function install ()
|
||||
return 'Priority', -- Name
|
||||
1.0, -- Version
|
||||
'uda', -- Type
|
||||
'Implements priority attribute', -- Description
|
||||
'Paul Beckingham', -- Author
|
||||
'paul@beckingham.net', -- Contact
|
||||
'© 2011, Göteborg Bit Factory' -- Copyright
|
||||
end
|
||||
|
||||
-- TODO Required for UDA extensions.
|
||||
|
104
src/API.cpp
104
src/API.cpp
|
@ -57,71 +57,6 @@ Task* the_task = NULL;
|
|||
|
||||
#ifdef HAVE_LIBLUA
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Returns a string representing the taskwarrior version number, such as
|
||||
// '1.9.0'.
|
||||
static int api_task_version (lua_State* L)
|
||||
{
|
||||
lua_pushstring (L, PACKAGE_VERSION);
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Returns a string representing the Lua version number, such as '5.1.4'.
|
||||
// Lua 5.2.0 has a 'lua_version' call, but 5.1.4 is the target.
|
||||
static int api_task_lua_version (lua_State* L)
|
||||
{
|
||||
// Convert "Lua 5.1.4" -> "5.1.4"
|
||||
std::string ver = LUA_RELEASE;
|
||||
lua_pushstring (L, ver.substr (4, std::string::npos).c_str ());
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Returns the type of OS that task is running on.
|
||||
static int api_task_os (lua_State* L)
|
||||
{
|
||||
#if defined (DARWIN)
|
||||
lua_pushstring (L, "darwin");
|
||||
#elif defined (SOLARIS)
|
||||
lua_pushstring (L, "solaris");
|
||||
#elif defined (CYGWIN)
|
||||
lua_pushstring (L, "cygwin");
|
||||
#elif defined (OPENBSD)
|
||||
lua_pushstring (L, "openbsd");
|
||||
#elif defined (HAIKU)
|
||||
lua_pushstring (L, "haiku");
|
||||
#elif defined (FREEBSD)
|
||||
lua_pushstring (L, "freebsd");
|
||||
#elif defined (LINUX)
|
||||
lua_pushstring (L, "linux");
|
||||
#else
|
||||
lua_pushstring (L, "unknown");
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static int api_task_feature (lua_State* L)
|
||||
{
|
||||
std::string name = luaL_checkstring (L, 1);
|
||||
bool value = false;
|
||||
|
||||
if (name == "readline")
|
||||
{
|
||||
#ifdef HAVE_READLINE
|
||||
value = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
else if (name == "lua")
|
||||
value = true;
|
||||
|
||||
lua_pushboolean (L, value ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static int api_task_header_message (lua_State* L)
|
||||
{
|
||||
|
@ -157,6 +92,39 @@ static int api_task_exit (lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DOM reads.
|
||||
static int api_task_get (lua_State* L)
|
||||
{
|
||||
std::string name = luaL_checkstring (L, 1);
|
||||
try
|
||||
{
|
||||
lua_pushstring (L, context.dom.get (name).c_str ());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// TODO Error!
|
||||
lua_pushstring (L, "");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DOM writes.
|
||||
static int api_task_set (lua_State* L)
|
||||
{
|
||||
std::string name = luaL_checkstring (L, 1);
|
||||
std::string value = luaL_checkstring (L, 2);
|
||||
|
||||
try
|
||||
{
|
||||
context.dom.set (name, value);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// TODO Error!
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
API::API ()
|
||||
: L (NULL)
|
||||
|
@ -181,14 +149,12 @@ void API::initialize ()
|
|||
luaL_openlibs (L); // TODO Error handling
|
||||
|
||||
// Register all the API functions in Lua global space.
|
||||
lua_pushcfunction (L, api_task_version); lua_setglobal (L, "task_version");
|
||||
lua_pushcfunction (L, api_task_lua_version); lua_setglobal (L, "task_lua_version");
|
||||
lua_pushcfunction (L, api_task_os); lua_setglobal (L, "task_os");
|
||||
lua_pushcfunction (L, api_task_feature); lua_setglobal (L, "task_feature");
|
||||
lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message");
|
||||
lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message");
|
||||
lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message");
|
||||
lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit");
|
||||
lua_pushcfunction (L, api_task_get); lua_setglobal (L, "task_get");
|
||||
lua_pushcfunction (L, api_task_set); lua_setglobal (L, "task_set");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue