From 68ff6dc2b57969ba52284646a84a03ee15529313 Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Fri, 9 Aug 2024 09:39:40 +0200 Subject: [PATCH] Add lua interrupt on F9 --- src/text_editor/lua_api.cpp | 9 +++++++++ src/text_editor/notes_bindings | 6 ++++-- src/text_editor/todo.txt | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 16a6455..605b6fe 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -184,6 +184,14 @@ int LuaGetCurrentBufferDir(lua_State *L) { return 1; } +static void HookLuaForceExit(lua_State *L, lua_Debug *debug) { + SDL_PumpEvents(); + int numkeys = 0; + const uint8_t *keys = SDL_GetKeyboardState(&numkeys); + if (keys[SDL_SCANCODE_F9] > 0) + luaL_error(L, "lua execution got interrupted"); +} + luaL_Reg LuaFunctions[] = { { "Open", LuaOpen}, { "ListBuffers", LuaListBuffers}, @@ -202,6 +210,7 @@ luaL_Reg LuaFunctions[] = { void InitLua() { LuaState = luaL_newstate(); luaL_openlibs(LuaState); + lua_sethook(LuaState, HookLuaForceExit, LUA_MASKCOUNT, 100000000); for (int i = 0; LuaFunctions[i].name; i += 1) { lua_pushcfunction(LuaState, LuaFunctions[i].func); diff --git a/src/text_editor/notes_bindings b/src/text_editor/notes_bindings index eafa19f..d9628cb 100644 --- a/src/text_editor/notes_bindings +++ b/src/text_editor/notes_bindings @@ -5,13 +5,15 @@ right_mouse :: ctrl exec word,alt go back ctrl mleft - add cursor -ctrl shift mleft - add cursor + set selection +ctrl shift mleft - add cursor and set selection alt mleft - alt ctrl mleft - alt shift mleft - +mright - destroy pointed at selection and copy | copy line alt mright - go back -mright - destroy pointed at selection and copy ctrl mright - load word shift mright - +alt shift mright - +alt ctrl mright - ctrl shift mright - exec word mmiddle - diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index be6cd5f..f83404c 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,7 +1,6 @@ - Remove pointers and use ViewIDs (enable array debug while doing this) - try using git grep for search for now, combine with fuzzy search buffer - lua maybe try heuristic matching paths from left? -- prevent lua from infinite looping - Append to console and change console directory - win32: change all stack buffers to arena