Files
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

57 lines
1.6 KiB
C++

#ifdef _DEBUG
#include "lua/modules/dev/quests.hpp"
#include <string>
#include <sol/sol.hpp>
#include "debug.h"
#include "lua/metadoc.hpp"
#include "utils/str_case.hpp"
#include "utils/str_cat.hpp"
namespace devilution {
namespace {
std::string DebugCmdSearchMonster(std::string_view name)
{
if (name.empty()) return "Missing monster name!";
AddDebugAutomapMonsterHighlight(AsciiStrToLower(name));
return StrCat("Added automap marker for monster ", name, ".");
}
std::string DebugCmdSearchItem(std::string_view name)
{
if (name.empty()) return "Missing item name!";
AddDebugAutomapItemHighlight(AsciiStrToLower(name));
return StrCat("Added automap marker for item ", name, ".");
}
std::string DebugCmdSearchObject(std::string_view name)
{
if (name.empty()) return "Missing object name!";
AddDebugAutomapObjectHighlight(AsciiStrToLower(name));
return StrCat("Added automap marker for object ", name, ".");
}
std::string DebugCmdClearSearch()
{
ClearDebugAutomapHighlights();
return "Removed all automap search markers.";
}
} // namespace
sol::table LuaDevSearchModule(sol::state_view &lua)
{
sol::table table = lua.create_table();
LuaSetDocFn(table, "clear", "()", "Clear search results from the map.", &DebugCmdClearSearch);
LuaSetDocFn(table, "item", "(name: string)", "Search the map for an item.", &DebugCmdSearchItem);
LuaSetDocFn(table, "monster", "(name: string)", "Search the map for a monster.", &DebugCmdSearchMonster);
LuaSetDocFn(table, "object", "(name: string)", "Search the map for an object.", &DebugCmdSearchObject);
return table;
}
} // namespace devilution
#endif // _DEBUG