@@ -431,6 +431,36 @@ static int32 get_title(lua_State* state)
431431 return 0 ;
432432}
433433
434+ // ------------------------------------------------------------------------------
435+ // / -name: console.getoriginaltitle
436+ // / -ver: 1.9.11
437+ // / -ret: string
438+ // / Returns the original console title text.
439+ // /
440+ // / This internally calls the system API GetConsoleOriginalTitleW, and returns
441+ // / what the operating system considers to be the original title.
442+ static int32 get_original_title (lua_State* state)
443+ {
444+ assert (!is_test_harness ());
445+
446+ wstr<16 > title;
447+ title.reserve (4096 );
448+
449+ DWORD len = GetConsoleOriginalTitleW (title.data (), title.size ());
450+ if (len || GetLastError () == ERROR_SUCCESS)
451+ {
452+ str<> out;
453+ // GetConsoleOriginalTitleW says it NUL terminates the buffer, but in
454+ // practice it actually does not (at least in Win11 24H2 26100.7623).
455+ to_utf8 (out, wstr_iter (title.c_str (), len));
456+
457+ lua_pushstring (state, out.c_str ());
458+ return 1 ;
459+ }
460+
461+ return 0 ;
462+ }
463+
434464// ------------------------------------------------------------------------------
435465// / -name: console.settitle
436466// / -ver: 1.1.32
@@ -1377,6 +1407,7 @@ void console_lua_initialise(lua_state& lua, bool lua_interpreter)
13771407 { " getcursorpos" , &get_cursor_pos },
13781408 { " getlinetext" , &get_line_text },
13791409 { " gettitle" , &get_title },
1410+ { " getoriginaltitle" , &get_original_title },
13801411 { " settitle" , &set_title },
13811412 { " islinedefaultcolor" , &is_line_default_color },
13821413 { " linehascolor" , &line_has_color },
0 commit comments