mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-26 15:47: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 ()
|
||||
: _L (NULL)
|
||||
: _state (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
API::~API ()
|
||||
{
|
||||
if (_L)
|
||||
if (_state)
|
||||
{
|
||||
lua_close (_L);
|
||||
_L = NULL;
|
||||
lua_close (_state);
|
||||
_state = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,16 +153,16 @@ API::~API ()
|
|||
void API::initialize ()
|
||||
{
|
||||
// Initialize Lua.
|
||||
_L = lua_open ();
|
||||
luaL_openlibs (_L); // TODO Error handling
|
||||
_state = lua_open ();
|
||||
luaL_openlibs (_state); // TODO Error handling
|
||||
|
||||
// Register all the API functions in Lua global space.
|
||||
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");
|
||||
lua_pushcfunction (_state, api_task_header_message); lua_setglobal (_state, "task_header_message");
|
||||
lua_pushcfunction (_state, api_task_footnote_message); lua_setglobal (_state, "task_footnote_message");
|
||||
lua_pushcfunction (_state, api_task_debug_message); lua_setglobal (_state, "task_debug_message");
|
||||
lua_pushcfunction (_state, api_task_exit); lua_setglobal (_state, "task_exit");
|
||||
lua_pushcfunction (_state, api_task_get); lua_setglobal (_state, "task_get");
|
||||
lua_pushcfunction (_state, api_task_set); lua_setglobal (_state, "task_set");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -173,26 +173,26 @@ bool API::callProgramHook (
|
|||
loadFile (file);
|
||||
|
||||
// Get function.
|
||||
lua_getglobal (_L, function.c_str ());
|
||||
if (!lua_isfunction (_L, -1))
|
||||
lua_getglobal (_state, function.c_str ());
|
||||
if (!lua_isfunction (_state, -1))
|
||||
{
|
||||
lua_pop (_L, 1);
|
||||
lua_pop (_state, 1);
|
||||
throw format (STRING_API_NOFUNC, function);
|
||||
}
|
||||
|
||||
// Make call.
|
||||
if (lua_pcall (_L, 0, 2, 0) != 0)
|
||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
|
||||
if (lua_pcall (_state, 0, 2, 0) != 0)
|
||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_state, -1));
|
||||
|
||||
// Call successful - get return values.
|
||||
if (!lua_isnumber (_L, -2))
|
||||
if (!lua_isnumber (_state, -2))
|
||||
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);
|
||||
|
||||
int rc = lua_tointeger (_L, -2);
|
||||
const char* message = lua_tostring (_L, -1);
|
||||
int rc = lua_tointeger (_state, -2);
|
||||
const char* message = lua_tostring (_state, -1);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ bool API::callProgramHook (
|
|||
throw std::string (message);
|
||||
}
|
||||
|
||||
lua_pop (_L, 1);
|
||||
lua_pop (_state, 1);
|
||||
return rc == 0 ? true : false;
|
||||
}
|
||||
|
||||
|
@ -221,29 +221,29 @@ bool API::callTaskHook (
|
|||
_current = task;
|
||||
|
||||
// Get function.
|
||||
lua_getglobal (_L, function.c_str ());
|
||||
if (!lua_isfunction (_L, -1))
|
||||
lua_getglobal (_state, function.c_str ());
|
||||
if (!lua_isfunction (_state, -1))
|
||||
{
|
||||
lua_pop (_L, 1);
|
||||
lua_pop (_state, 1);
|
||||
throw format (STRING_API_NOFUNC, function);
|
||||
}
|
||||
|
||||
// Prepare args.
|
||||
lua_pushnumber (_L, _current.id);
|
||||
lua_pushnumber (_state, _current.id);
|
||||
|
||||
// Make call.
|
||||
if (lua_pcall (_L, 1, 2, 0) != 0)
|
||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
|
||||
if (lua_pcall (_state, 1, 2, 0) != 0)
|
||||
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_state, -1));
|
||||
|
||||
// Call successful - get return values.
|
||||
if (!lua_isnumber (_L, -2))
|
||||
if (!lua_isnumber (_state, -2))
|
||||
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);
|
||||
|
||||
int rc = lua_tointeger (_L, -2);
|
||||
const char* message = lua_tostring (_L, -1);
|
||||
int rc = lua_tointeger (_state, -2);
|
||||
const char* message = lua_tostring (_state, -1);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
|
@ -256,7 +256,7 @@ bool API::callTaskHook (
|
|||
throw std::string (message);
|
||||
}
|
||||
|
||||
lua_pop (_L, 1);
|
||||
lua_pop (_state, 1);
|
||||
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 ())
|
||||
{
|
||||
// Load the file, if possible.
|
||||
if (luaL_loadfile (_L, file.c_str ()) || lua_pcall (_L, 0, 0, 0))
|
||||
throw format (STRING_API_ERROR, lua_tostring (_L, -1));
|
||||
if (luaL_loadfile (_state, file.c_str ()) || lua_pcall (_state, 0, 0, 0))
|
||||
throw format (STRING_API_ERROR, lua_tostring (_state, -1));
|
||||
|
||||
// Mark this as _loaded, so as to not bother again.
|
||||
_loaded.push_back (file);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue