Files
DevilutionX/Source/lua/modules/render.cpp
T
Gleb Mazovetskiy 17e6da40f8 Lua: Improve function/property handling
1. Follows advice from
   https://sol2.readthedocs.io/en/latest/functions.html to use
   `set_function` when binding functions.
2. Adds autocomplete support for userdata methods.
3. Simplifies property bindings and improves string handling.
2025-07-20 17:46:35 +02:00

26 lines
802 B
C++

#include "lua/modules/render.hpp"
#include <sol/sol.hpp>
#include "engine/dx.h"
#include "engine/render/text_render.hpp"
#include "lua/metadoc.hpp"
#include "utils/display.h"
namespace devilution {
sol::table LuaRenderModule(sol::state_view &lua)
{
sol::table table = lua.create_table();
LuaSetDocFn(table, "string", "(text: string, x: integer, y: integer)",
"Renders a string at the given coordinates",
[](std::string_view text, int x, int y) { DrawString(GlobalBackBuffer(), text, { x, y }); });
LuaSetDocFn(table, "screen_width", "()",
"Returns the screen width", []() { return gnScreenWidth; });
LuaSetDocFn(table, "screen_height", "()",
"Returns the screen height", []() { return gnScreenHeight; });
return table;
}
} // namespace devilution