aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2020-12-10 12:44:01 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2020-12-10 12:44:01 +0100
commit6409b67ea2d36b8572ebefb764bf88dd0d18ea66 (patch)
tree00a81d1cc81b4d7350b6796effb7ef6318023d2d /src
parent33109e6110a22695d2203dda339695ba723ebc00 (diff)
downloadlite-xl-6409b67ea2d36b8572ebefb764bf88dd0d18ea66.tar.gz
lite-xl-6409b67ea2d36b8572ebefb764bf88dd0d18ea66.zip
Add core:restart function to restart the editor
Diffstat (limited to 'src')
-rw-r--r--src/main.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 1704a6f1..010f16a5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -89,8 +89,9 @@ int main(int argc, char **argv) {
init_window_icon();
ren_init(window);
-
- lua_State *L = luaL_newstate();
+ lua_State *L;
+init_lua:
+ L = luaL_newstate();
luaL_openlibs(L);
api_load_libs(L);
@@ -117,7 +118,7 @@ int main(int argc, char **argv) {
lua_setglobal(L, "EXEFILE");
- (void) luaL_dostring(L,
+ const char *init_lite_code = \
"local core\n"
"xpcall(function()\n"
" SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n"
@@ -153,8 +154,18 @@ int main(int argc, char **argv) {
" pcall(core.on_error, err)\n"
" end\n"
" os.exit(1)\n"
- "end)");
+ "end)\n"
+ "return core and core.restart_request\n";
+ if (luaL_loadstring(L, init_lite_code)) {
+ fprintf(stderr, "internal error when starting the application\n");
+ exit(1);
+ }
+ lua_pcall(L, 0, 1, 0);
+ if (lua_toboolean(L, -1)) {
+ lua_close(L);
+ goto init_lua;
+ }
lua_close(L);
SDL_DestroyWindow(window);