Files
DevilutionX/Source/lua/modules/audio.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

32 lines
750 B
C++

#include "lua/modules/audio.hpp"
#include <sol/sol.hpp>
#include "effects.h"
#include "lua/metadoc.hpp"
namespace devilution {
namespace {
bool IsValidSfx(int16_t psfx)
{
return psfx >= 0 && psfx <= static_cast<int16_t>(SfxID::LAST);
}
} // namespace
sol::table LuaAudioModule(sol::state_view &lua)
{
sol::table table = lua.create_table();
LuaSetDocFn(table,
"playSfx", "(id: number)",
[](int16_t psfx) { if (IsValidSfx(psfx)) PlaySFX(static_cast<SfxID>(psfx)); });
LuaSetDocFn(table,
"playSfxLoc", "(id: number, x: number, y: number)",
[](int16_t psfx, int x, int y) { if (IsValidSfx(psfx)) PlaySfxLoc(static_cast<SfxID>(psfx), { x, y }); });
return table;
}
} // namespace devilution