mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 00:43:07 +02:00
Hooks
- Removed obsolete field hook.
This commit is contained in:
parent
48eb4757f8
commit
bac4610580
2 changed files with 0 additions and 58 deletions
57
src/API.cpp
57
src/API.cpp
|
@ -258,63 +258,6 @@ bool API::callTaskHook (
|
|||
return rc == 0 ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool API::callFieldHook (
|
||||
const std::string& file,
|
||||
const std::string& function,
|
||||
const std::string& name,
|
||||
std::string& value)
|
||||
{
|
||||
loadFile (file);
|
||||
|
||||
// Get function.
|
||||
lua_getglobal (L, function.c_str ());
|
||||
if (!lua_isfunction (L, -1))
|
||||
{
|
||||
lua_pop (L, 1);
|
||||
throw std::string ("The Lua function '") + function + "' was not found.";
|
||||
}
|
||||
|
||||
// Prepare args.
|
||||
lua_pushstring (L, name.c_str ());
|
||||
lua_pushstring (L, value.c_str ());
|
||||
|
||||
// Make call.
|
||||
if (lua_pcall (L, 2, 3, 0) != 0)
|
||||
throw std::string ("Error calling '") + function + "' - " + lua_tostring (L, -1) + ".";
|
||||
|
||||
// Call successful - get return values.
|
||||
if (!lua_isstring (L, -3))
|
||||
throw std::string ("Error: '") + function + "' did not return a modified value.";
|
||||
|
||||
if (!lua_isnumber (L, -2))
|
||||
throw std::string ("Error: '") + function + "' did not return a success indicator.";
|
||||
|
||||
if (!lua_isstring (L, -1) && !lua_isnil (L, -1))
|
||||
throw std::string ("Error: '") + function + "' did not return a message or nil.";
|
||||
|
||||
const char* new_value = lua_tostring (L, -3);
|
||||
int rc = lua_tointeger (L, -2);
|
||||
const char* message = lua_tostring (L, -1);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
// Overwrite with the modified value.
|
||||
value = new_value;
|
||||
|
||||
if (message)
|
||||
context.footnote (std::string ("Warning: ") + message);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (message)
|
||||
throw std::string (message);
|
||||
}
|
||||
|
||||
lua_pop (L, 1);
|
||||
return rc == 0 ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void API::loadFile (const std::string& file)
|
||||
{
|
||||
|
|
|
@ -52,7 +52,6 @@ public:
|
|||
void initialize ();
|
||||
bool callProgramHook (const std::string&, const std::string&);
|
||||
bool callTaskHook (const std::string&, const std::string&, Task&);
|
||||
bool callFieldHook (const std::string&, const std::string&, const std::string&, std::string&);
|
||||
|
||||
private:
|
||||
void loadFile (const std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue