mirror of
https://github.com/libretro/devilutionX.git
synced 2026-11-08 17:21:59 -10:00
Fully migrates debug commands to Lua and organizes them into logical
groups.
The CLI `+` syntax now runs Lua, e.g.:
```bash
build/devilutionx '+dev.player.trn.plr("infra")'
```
Chat hotkeys run Lua code if they start with `/lua`, e.g.:
```ini
[NetMsg]
QuickMessage1=/lua message(dev.player.info())
```
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <sol/sol.hpp>
|
|
|
|
#include <string_view>
|
|
|
|
#include "utils/str_cat.hpp"
|
|
|
|
namespace devilution {
|
|
|
|
inline std::string LuaSignatureKey(std::string_view key)
|
|
{
|
|
return StrCat("__sig_", key);
|
|
}
|
|
|
|
inline std::string LuaDocstringKey(std::string_view key)
|
|
{
|
|
return StrCat("__doc_", key);
|
|
}
|
|
|
|
template <typename T>
|
|
void SetDocumented(sol::table &table, std::string_view key, std::string_view signature, std::string_view doc, T &&value)
|
|
{
|
|
table[key] = std::forward<T>(value);
|
|
table[LuaSignatureKey(key)] = signature;
|
|
table[LuaDocstringKey(key)] = doc;
|
|
}
|
|
|
|
template <typename T>
|
|
void SetWithSignature(sol::table &table, std::string_view key, std::string_view signature, T &&value)
|
|
{
|
|
table[key] = std::forward<T>(value);
|
|
table[LuaSignatureKey(key)] = signature;
|
|
}
|
|
|
|
inline std::optional<std::string> GetSignature(const sol::table &table, std::string_view key)
|
|
{
|
|
return table.get<std::optional<std::string>>(LuaSignatureKey(key));
|
|
}
|
|
|
|
inline std::optional<std::string> GetDocstring(const sol::table &table, std::string_view key)
|
|
{
|
|
return table.get<std::optional<std::string>>(LuaDocstringKey(key));
|
|
}
|
|
|
|
} // namespace devilution
|