diff --git a/src/API.cpp b/src/API.cpp index 41ea099eb..f4018bdf1 100644 --- a/src/API.cpp +++ b/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); diff --git a/src/API.h b/src/API.h index e0b5a3c39..9b7bfe2b5 100644 --- a/src/API.h +++ b/src/API.h @@ -28,7 +28,7 @@ #define INCLUDED_API #define L10N // Localization complete. -#include <../cmake.h> +#include #ifdef HAVE_LIBLUA #include @@ -58,7 +58,7 @@ private: void loadFile (const std::string&); public: - lua_State* _L; + lua_State* _state; std::vector _loaded; // Context for the API.