mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Clean up code style and fix stack reservation issues
This commit is contained in:
parent
c689c2dfcc
commit
ad508f558e
1 changed files with 32 additions and 24 deletions
56
CLI/Repl.cpp
56
CLI/Repl.cpp
|
@ -19,14 +19,13 @@
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include <csignal>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
LUAU_FASTFLAG(DebugLuauTimeTracing)
|
LUAU_FASTFLAG(DebugLuauTimeTracing)
|
||||||
|
|
||||||
|
@ -48,23 +47,31 @@ enum class CompileFormat
|
||||||
constexpr int MaxTraversalLimit = 50;
|
constexpr int MaxTraversalLimit = 50;
|
||||||
|
|
||||||
// Ctrl-C handling
|
// Ctrl-C handling
|
||||||
void sigint_callback(lua_State* L, int k) {
|
static void sigintCallback(lua_State* L, int gc)
|
||||||
lua_callbacks(L)->interrupt = NULL;
|
{
|
||||||
|
if (gc >= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lua_callbacks(L)->interrupt = NULL;
|
||||||
|
|
||||||
|
lua_rawcheckstack(L, 1); // reserve space for error string
|
||||||
luaL_error(L, "Execution interrupted");
|
luaL_error(L, "Execution interrupted");
|
||||||
};
|
}
|
||||||
lua_State* repl_lua_state = NULL;
|
|
||||||
#ifndef _WIN32
|
static lua_State* replState = NULL;
|
||||||
static void handle_sig(int signum) {
|
|
||||||
if(signum == SIGINT && repl_lua_state != NULL) {
|
#ifdef _WIN32
|
||||||
lua_callbacks(repl_lua_state)->interrupt = &sigint_callback;
|
BOOL WINAPI sigintHandler(DWORD signal)
|
||||||
}
|
{
|
||||||
|
if (signal == CTRL_C_EVENT && replState
|
||||||
|
lua_callbacks(replState)->interrupt = &sigintCallback;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
BOOL WINAPI handle_sig(DWORD signal) {
|
static void sigintHandler(int signum)
|
||||||
if(signal == CTRL_C_EVENT && repl_lua_state != NULL) {
|
{
|
||||||
lua_callbacks(repl_lua_state)->interrupt = &sigint_callback;
|
if (signum == SIGINT && replState)
|
||||||
}
|
lua_callbacks(replState)->interrupt = &sigintCallback;
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -518,12 +525,13 @@ static void runRepl()
|
||||||
|
|
||||||
setupState(L);
|
setupState(L);
|
||||||
|
|
||||||
repl_lua_state = L;
|
// setup Ctrl+C handling
|
||||||
#ifndef _WIN32
|
replState = L;
|
||||||
signal(SIGINT, handle_sig);
|
#ifdef _WIN32
|
||||||
#else
|
SetConsoleCtrlHandler(sigintHandler, TRUE);
|
||||||
SetConsoleCtrlHandler(handle_sig, TRUE);
|
#else
|
||||||
#endif
|
signal(SIGINT, sigintHandler);
|
||||||
|
#endif
|
||||||
|
|
||||||
luaL_sandboxthread(L);
|
luaL_sandboxthread(L);
|
||||||
runReplImpl(L);
|
runReplImpl(L);
|
||||||
|
|
Loading…
Add table
Reference in a new issue