diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-05-17 11:40:43 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-05-17 11:40:43 +1000 |
| commit | d948585b00b4d08869417ee6169aae9ea39dde0a (patch) | |
| tree | 4104d5a6928e26b70d41c8326aaf1bfe4725aa2d /src/tangara/lua | |
| parent | 51bbb6a49544861edc957e0c91ceb1ac8349651b (diff) | |
| download | tangara-fw-d948585b00b4d08869417ee6169aae9ea39dde0a.tar.gz | |
add a lua binding for playing a sine wave
Diffstat (limited to 'src/tangara/lua')
| -rw-r--r-- | src/tangara/lua/bridge.cpp | 7 | ||||
| -rw-r--r-- | src/tangara/lua/lua_testing.cpp | 40 | ||||
| -rw-r--r-- | src/tangara/lua/lua_testing.hpp | 15 |
3 files changed, 59 insertions, 3 deletions
diff --git a/src/tangara/lua/bridge.cpp b/src/tangara/lua/bridge.cpp index f1b17636..51ad0b62 100644 --- a/src/tangara/lua/bridge.cpp +++ b/src/tangara/lua/bridge.cpp @@ -21,6 +21,7 @@ #include "lua/lua_filesystem.hpp" #include "lua/lua_queue.hpp" #include "lua/lua_screen.hpp" +#include "lua/lua_testing.hpp" #include "lua/lua_theme.hpp" #include "lua/lua_version.hpp" #include "lvgl.h" @@ -47,9 +48,8 @@ namespace lua { static constexpr char kBridgeKey[] = "bridge"; -static auto make_font_cb(const char* name, - int size, - int weight) -> const lv_font_t* { +static auto make_font_cb(const char* name, int size, int weight) + -> const lv_font_t* { if (std::string{"fusion"} == name) { if (size == 12) { return &font_fusion_12; @@ -87,6 +87,7 @@ auto Bridge::installBaseModules(lua_State* L) -> void { RegisterControlsModule(L); RegisterDatabaseModule(L); RegisterQueueModule(L); + RegisterTestingModule(L); RegisterFileSystemModule(L); RegisterVersionModule(L); RegisterThemeModule(L); diff --git a/src/tangara/lua/lua_testing.cpp b/src/tangara/lua/lua_testing.cpp new file mode 100644 index 00000000..36f632ce --- /dev/null +++ b/src/tangara/lua/lua_testing.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "lua_testing.hpp" + +#include "lauxlib.h" +#include "lua.h" + +#include "audio/audio_events.hpp" +#include "events/event_queue.hpp" + +namespace lua { + +static auto testing_tone(lua_State* L) -> int { + auto freq = luaL_checkinteger(L, 1); + events::Audio().Dispatch( + audio::PlaySineWave{.frequency = static_cast<uint32_t>(freq)}); + events::Audio().Dispatch(audio::TogglePlayPause{.set_to = true}); + return 0; +} + +static const struct luaL_Reg kTestingFuncs[] = { + {"tone", testing_tone}, + {NULL, NULL}, +}; + +static auto lua_testing(lua_State* state) -> int { + luaL_newlib(state, kTestingFuncs); + return 1; +} + +auto RegisterTestingModule(lua_State* L) -> void { + luaL_requiref(L, "testing", lua_testing, false); + lua_pop(L, 1); +} + +} // namespace lua diff --git a/src/tangara/lua/lua_testing.hpp b/src/tangara/lua/lua_testing.hpp new file mode 100644 index 00000000..5251a350 --- /dev/null +++ b/src/tangara/lua/lua_testing.hpp @@ -0,0 +1,15 @@ +/* + * Copyright 2024 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include "lua.hpp" + +namespace lua { + +auto RegisterTestingModule(lua_State*) -> void; + +} // namespace lua |
