Skip to content

Commit

Permalink
Readd core.get_screen_info()
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Jan 8, 2023
1 parent 1611add commit c63412a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/menu_lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ GUI
will be added to fieldname value is set to formname itself
* if `is_file_select` is `true`, a file and not a folder will be selected
* returns nil or selected file/folder
* `core.get_screen_info()`: DEPRECATED, use below 2 functions instead.
* `core.get_active_renderer()`: Ex: "OpenGL 4.6".
* `core.get_window_info()`: Same as server-side `get_player_window_information` API.

Expand Down
26 changes: 26 additions & 0 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,31 @@ int ModApiMainMenu::l_get_window_info(lua_State *L)
return 1;
}

/******************************************************************************/
int ModApiMainMenu::l_get_screen_info(lua_State *L)
{
lua_newtable(L);
int top = lua_gettop(L);
lua_pushstring(L,"density");
lua_pushnumber(L,RenderingEngine::getDisplayDensity());
lua_settable(L, top);

const v2u32 &window_size = RenderingEngine::getWindowSize();
lua_pushstring(L,"window_width");
lua_pushnumber(L, window_size.X);
lua_settable(L, top);

lua_pushstring(L,"window_height");
lua_pushnumber(L, window_size.Y);
lua_settable(L, top);

lua_pushstring(L, "render_info");
lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
lua_settable(L, top);
return 1;
}
/******************************************************************************/

int ModApiMainMenu::l_get_active_renderer(lua_State *L)
{
lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
Expand Down Expand Up @@ -1099,6 +1124,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(download_file);
API_FCT(gettext);
API_FCT(get_video_drivers);
API_FCT(get_screen_info);
API_FCT(get_window_info);
API_FCT(get_active_renderer);
API_FCT(get_min_supp_proto);
Expand Down
2 changes: 2 additions & 0 deletions src/script/lua_api/l_mainmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class ModApiMainMenu: public ModApiBase

static int l_set_formspec_prepend(lua_State *L);

static int l_get_screen_info(lua_State *L);

static int l_get_window_info(lua_State *L);

static int l_get_active_renderer(lua_State *L);
Expand Down

0 comments on commit c63412a

Please sign in to comment.