Skip to content

Commit

Permalink
GUIModule::getSystem lua API
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 8, 2023
1 parent cb68aed commit 419f943
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/audio/audio_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ UniquePtr<AudioModule> AudioModule::createInstance(AudioSystem& system,
void AudioModule::reflect(Engine& engine) {
LUMIX_MODULE(AudioModuleImpl, "audio")
.LUMIX_FUNC(AudioModule::setMasterVolume)
.function<(SoundHandle (AudioModule::*)(EntityRef, const Path&, bool))&AudioModule::play>("AudioModule::play", "AudioModule::play")
.function<(SoundHandle (AudioModule::*)(EntityRef, const Path&, bool))&AudioModule::play>("play", "AudioModule::play")
.LUMIX_FUNC(AudioModule::stop)
.LUMIX_FUNC(AudioModule::isEnd)
.LUMIX_FUNC(AudioModule::setFrequency)
Expand Down
5 changes: 2 additions & 3 deletions src/gui/gui_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ struct GUIModuleImpl final : GUIModule {
return intersect ? rect.entity : INVALID_ENTITY;
}

void enableCursor(bool enable) { m_system.enableCursor(enable); }

EntityPtr getRectAt(const Vec2& pos) const override { return getRectAtEx(pos, m_canvas_size, INVALID_ENTITY); }

bool isOver(const Vec2& pos, EntityRef e) override {
Expand Down Expand Up @@ -1232,6 +1230,7 @@ struct GUIModuleImpl final : GUIModule {

World& getWorld() override { return m_world; }
ISystem& getSystem() const override { return m_system; }
GUISystem* getSystemPtr() const { return &m_system; }

IAllocator& m_allocator;
World& m_world;
Expand Down Expand Up @@ -1317,7 +1316,7 @@ void GUIModule::reflect() {
.LUMIX_EVENT(GUIModule::mousedButtonUnhandled)
.LUMIX_FUNC(GUIModule::getRectAt)
.LUMIX_FUNC(GUIModule::isOver)
.LUMIX_FUNC(GUIModuleImpl::enableCursor)
.function<&GUIModuleImpl::getSystemPtr>("getSystem", "GUIModule::getSystem")
.LUMIX_CMP(RenderTarget, "gui_render_target", "GUI / Render taget")
.LUMIX_CMP(Text, "gui_text", "GUI / Text")
.icon(ICON_FA_FONT)
Expand Down
18 changes: 12 additions & 6 deletions src/lua_script/lua_script_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,13 +1343,19 @@ namespace Lumix
lua_setfield(L, -2, "new"); // [ module ]

for (const reflection::FunctionBase* f : module->functions) {
const char* c = f->decl_code;
while (*c != ':' && *c) ++c;
ASSERT(*c == ':');
c += 2;
lua_pushlightuserdata(L, (void*)f); // [module, f]
lua_pushcclosure(L, luaModuleMethodClosure, c, 1); // [module, fn]
lua_setfield(L, -2, c); // [module]
if (f->name) {
lua_pushcclosure(L, luaModuleMethodClosure, f->name, 1);
lua_setfield(L, -2, f->name); // [module]
}
else {
const char* c = f->decl_code;
while (*c != ':' && *c) ++c;
ASSERT(*c == ':');
c += 2;
lua_pushcclosure(L, luaModuleMethodClosure, c, 1);
lua_setfield(L, -2, c); // [module]
}
}
lua_pop(L, 1); // []

Expand Down

0 comments on commit 419f943

Please sign in to comment.