mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 10:07:19 +02:00
Bug #832
- gcc feature prevents one from using _L task under cygwin compiles again
This commit is contained in:
parent
38c4bd3760
commit
8920f5c10c
2 changed files with 37 additions and 37 deletions
70
src/API.cpp
70
src/API.cpp
|
@ -135,17 +135,17 @@ static int api_task_set (lua_State* L)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
API::API ()
|
API::API ()
|
||||||
: _L (NULL)
|
: _state (NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
API::~API ()
|
API::~API ()
|
||||||
{
|
{
|
||||||
if (_L)
|
if (_state)
|
||||||
{
|
{
|
||||||
lua_close (_L);
|
lua_close (_state);
|
||||||
_L = NULL;
|
_state = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,16 +153,16 @@ API::~API ()
|
||||||
void API::initialize ()
|
void API::initialize ()
|
||||||
{
|
{
|
||||||
// Initialize Lua.
|
// Initialize Lua.
|
||||||
_L = lua_open ();
|
_state = lua_open ();
|
||||||
luaL_openlibs (_L); // TODO Error handling
|
luaL_openlibs (_state); // TODO Error handling
|
||||||
|
|
||||||
// Register all the API functions in Lua global space.
|
// Register all the API functions in Lua global space.
|
||||||
lua_pushcfunction (_L, api_task_header_message); lua_setglobal (_L, "task_header_message");
|
lua_pushcfunction (_state, api_task_header_message); lua_setglobal (_state, "task_header_message");
|
||||||
lua_pushcfunction (_L, api_task_footnote_message); lua_setglobal (_L, "task_footnote_message");
|
lua_pushcfunction (_state, api_task_footnote_message); lua_setglobal (_state, "task_footnote_message");
|
||||||
lua_pushcfunction (_L, api_task_debug_message); lua_setglobal (_L, "task_debug_message");
|
lua_pushcfunction (_state, api_task_debug_message); lua_setglobal (_state, "task_debug_message");
|
||||||
lua_pushcfunction (_L, api_task_exit); lua_setglobal (_L, "task_exit");
|
lua_pushcfunction (_state, api_task_exit); lua_setglobal (_state, "task_exit");
|
||||||
lua_pushcfunction (_L, api_task_get); lua_setglobal (_L, "task_get");
|
lua_pushcfunction (_state, api_task_get); lua_setglobal (_state, "task_get");
|
||||||
lua_pushcfunction (_L, api_task_set); lua_setglobal (_L, "task_set");
|
lua_pushcfunction (_state, api_task_set); lua_setglobal (_state, "task_set");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -173,26 +173,26 @@ bool API::callProgramHook (
|
||||||
loadFile (file);
|
loadFile (file);
|
||||||
|
|
||||||
// Get function.
|
// Get function.
|
||||||
lua_getglobal (_L, function.c_str ());
|
lua_getglobal (_state, function.c_str ());
|
||||||
if (!lua_isfunction (_L, -1))
|
if (!lua_isfunction (_state, -1))
|
||||||
{
|
{
|
||||||
lua_pop (_L, 1);
|
lua_pop (_state, 1);
|
||||||
throw format (STRING_API_NOFUNC, function);
|
throw format (STRING_API_NOFUNC, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make call.
|
// Make call.
|
||||||
if (lua_pcall (_L, 0, 2, 0) != 0)
|
if (lua_pcall (_state, 0, 2, 0) != 0)
|
||||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
|
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_state, -1));
|
||||||
|
|
||||||
// Call successful - get return values.
|
// Call successful - get return values.
|
||||||
if (!lua_isnumber (_L, -2))
|
if (!lua_isnumber (_state, -2))
|
||||||
throw format (STRING_API_ERROR_FAIL, function);
|
throw format (STRING_API_ERROR_FAIL, function);
|
||||||
|
|
||||||
if (!lua_isstring (_L, -1) && !lua_isnil (_L, -1))
|
if (!lua_isstring (_state, -1) && !lua_isnil (_state, -1))
|
||||||
throw format (STRING_API_ERROR_NORET, function);
|
throw format (STRING_API_ERROR_NORET, function);
|
||||||
|
|
||||||
int rc = lua_tointeger (_L, -2);
|
int rc = lua_tointeger (_state, -2);
|
||||||
const char* message = lua_tostring (_L, -1);
|
const char* message = lua_tostring (_state, -1);
|
||||||
|
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
|
@ -205,7 +205,7 @@ bool API::callProgramHook (
|
||||||
throw std::string (message);
|
throw std::string (message);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop (_L, 1);
|
lua_pop (_state, 1);
|
||||||
return rc == 0 ? true : false;
|
return rc == 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,29 +221,29 @@ bool API::callTaskHook (
|
||||||
_current = task;
|
_current = task;
|
||||||
|
|
||||||
// Get function.
|
// Get function.
|
||||||
lua_getglobal (_L, function.c_str ());
|
lua_getglobal (_state, function.c_str ());
|
||||||
if (!lua_isfunction (_L, -1))
|
if (!lua_isfunction (_state, -1))
|
||||||
{
|
{
|
||||||
lua_pop (_L, 1);
|
lua_pop (_state, 1);
|
||||||
throw format (STRING_API_NOFUNC, function);
|
throw format (STRING_API_NOFUNC, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare args.
|
// Prepare args.
|
||||||
lua_pushnumber (_L, _current.id);
|
lua_pushnumber (_state, _current.id);
|
||||||
|
|
||||||
// Make call.
|
// Make call.
|
||||||
if (lua_pcall (_L, 1, 2, 0) != 0)
|
if (lua_pcall (_state, 1, 2, 0) != 0)
|
||||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
|
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_state, -1));
|
||||||
|
|
||||||
// Call successful - get return values.
|
// Call successful - get return values.
|
||||||
if (!lua_isnumber (_L, -2))
|
if (!lua_isnumber (_state, -2))
|
||||||
throw format (STRING_API_ERROR_FAIL, function);
|
throw format (STRING_API_ERROR_FAIL, function);
|
||||||
|
|
||||||
if (!lua_isstring (_L, -1) && !lua_isnil (_L, -1))
|
if (!lua_isstring (_state, -1) && !lua_isnil (_state, -1))
|
||||||
throw format (STRING_API_ERROR_NORET, function);
|
throw format (STRING_API_ERROR_NORET, function);
|
||||||
|
|
||||||
int rc = lua_tointeger (_L, -2);
|
int rc = lua_tointeger (_state, -2);
|
||||||
const char* message = lua_tostring (_L, -1);
|
const char* message = lua_tostring (_state, -1);
|
||||||
|
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
|
@ -256,7 +256,7 @@ bool API::callTaskHook (
|
||||||
throw std::string (message);
|
throw std::string (message);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop (_L, 1);
|
lua_pop (_state, 1);
|
||||||
return rc == 0 ? true : false;
|
return rc == 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ void API::loadFile (const std::string& file)
|
||||||
if (std::find (_loaded.begin (), _loaded.end (), file) == _loaded.end ())
|
if (std::find (_loaded.begin (), _loaded.end (), file) == _loaded.end ())
|
||||||
{
|
{
|
||||||
// Load the file, if possible.
|
// Load the file, if possible.
|
||||||
if (luaL_loadfile (_L, file.c_str ()) || lua_pcall (_L, 0, 0, 0))
|
if (luaL_loadfile (_state, file.c_str ()) || lua_pcall (_state, 0, 0, 0))
|
||||||
throw format (STRING_API_ERROR, lua_tostring (_L, -1));
|
throw format (STRING_API_ERROR, lua_tostring (_state, -1));
|
||||||
|
|
||||||
// Mark this as _loaded, so as to not bother again.
|
// Mark this as _loaded, so as to not bother again.
|
||||||
_loaded.push_back (file);
|
_loaded.push_back (file);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#define INCLUDED_API
|
#define INCLUDED_API
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
#include <../cmake.h>
|
#include <cmake.h>
|
||||||
#ifdef HAVE_LIBLUA
|
#ifdef HAVE_LIBLUA
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -58,7 +58,7 @@ private:
|
||||||
void loadFile (const std::string&);
|
void loadFile (const std::string&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lua_State* _L;
|
lua_State* _state;
|
||||||
std::vector <std::string> _loaded;
|
std::vector <std::string> _loaded;
|
||||||
|
|
||||||
// Context for the API.
|
// Context for the API.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue