mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Actually check for SIGINT + Windows support
This commit is contained in:
parent
d3045d21bc
commit
c689c2dfcc
1 changed files with 13 additions and 4 deletions
17
CLI/Repl.cpp
17
CLI/Repl.cpp
|
@ -19,6 +19,7 @@
|
|||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
@ -47,17 +48,24 @@ enum class CompileFormat
|
|||
constexpr int MaxTraversalLimit = 50;
|
||||
|
||||
// Ctrl-C handling
|
||||
#ifndef _WIN32
|
||||
void sigint_callback(lua_State* L, int k) {
|
||||
lua_callbacks(L)->interrupt = NULL;
|
||||
luaL_error(L, "Execution interrupted");
|
||||
};
|
||||
lua_State* repl_lua_state = NULL;
|
||||
#ifndef _WIN32
|
||||
static void handle_sig(int signum) {
|
||||
if(repl_lua_state != NULL) {
|
||||
if(signum == SIGINT && repl_lua_state != NULL) {
|
||||
lua_callbacks(repl_lua_state)->interrupt = &sigint_callback;
|
||||
}
|
||||
}
|
||||
#else
|
||||
BOOL WINAPI handle_sig(DWORD signal) {
|
||||
if(signal == CTRL_C_EVENT && repl_lua_state != NULL) {
|
||||
lua_callbacks(repl_lua_state)->interrupt = &sigint_callback;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct GlobalOptions
|
||||
|
@ -510,10 +518,11 @@ static void runRepl()
|
|||
|
||||
setupState(L);
|
||||
|
||||
// FIXME: add corresponding windows functionality
|
||||
#ifndef _WIN32
|
||||
repl_lua_state = L;
|
||||
#ifndef _WIN32
|
||||
signal(SIGINT, handle_sig);
|
||||
#else
|
||||
SetConsoleCtrlHandler(handle_sig, TRUE);
|
||||
#endif
|
||||
|
||||
luaL_sandboxthread(L);
|
||||
|
|
Loading…
Add table
Reference in a new issue