diff options
author | Remko Tronçon <git@el-tramo.be> | 2014-01-17 20:02:19 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2014-01-18 10:44:42 (GMT) |
commit | 85c46a0fcce3495fe94397d53791628a8ccc74c4 (patch) | |
tree | 233decfdbe1c221f3db2149f0f59d828173c102e /Sluift/main.cpp | |
parent | 09108f5ac3c1a6567730b5bbd0c847f8422ff4a2 (diff) | |
download | swift-85c46a0fcce3495fe94397d53791628a8ccc74c4.zip swift-85c46a0fcce3495fe94397d53791628a8ccc74c4.tar.bz2 |
Sluift: Allow blocking calls to be interrupted.
Change-Id: I3755e796fbddc038022bbf543c7b1c0529a9b0f9
Diffstat (limited to 'Sluift/main.cpp')
-rw-r--r-- | Sluift/main.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Sluift/main.cpp b/Sluift/main.cpp index 76ba572..505cc5c 100644 --- a/Sluift/main.cpp +++ b/Sluift/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Remko Tronçon + * Copyright (c) 2013-2014 Remko Tronçon * Licensed under the GNU General Public License. * See the COPYING file for more information. */ @@ -15,6 +15,7 @@ #include <boost/version.hpp> #include <boost/numeric/conversion/cast.hpp> #include <boost/assign/list_of.hpp> +#include <Sluift/globals.h> #include <Sluift/Console.h> #include <Sluift/StandardTerminal.h> #include <Sluift/sluift.h> @@ -48,6 +49,10 @@ static const luaL_Reg defaultLibraries[] = { {NULL, NULL} }; +static void handleInterruptSignal(int) { + Sluift::globals.interruptRequested = 1; +} + static void checkResult(lua_State* L, int result) { if (result && !lua_isnil(L, -1)) { const char* errorMessage = lua_tostring(L, -1); @@ -150,6 +155,9 @@ int main(int argc, char* argv[]) { // Run console if (arguments.count("interactive") || arguments.count("script") == 0) { + // Set up signal handler + signal(SIGINT, handleInterruptSignal); + // Import some useful functions into the global namespace lua_getglobal(L, "sluift"); std::vector<std::string> globalImports = boost::assign::list_of |