mirror of
https://github.com/love2d/love.git
synced 2026-08-17 02:58:31 +02:00
Updated the Lua wrapper code for modules to account for cases where the module's instance is removed from memory completely and recreated during the program's lifetime.
This commit is contained in:
@@ -27,6 +27,11 @@ namespace love
|
||||
namespace keyboard
|
||||
{
|
||||
|
||||
Keyboard::Keyboard()
|
||||
{
|
||||
moduleType = M_KEYBOARD;
|
||||
}
|
||||
|
||||
bool Keyboard::getConstant(const char *in, Keyboard::Key &out)
|
||||
{
|
||||
return keys.find(in, out);
|
||||
|
||||
@@ -244,6 +244,7 @@ public:
|
||||
KEY_MAX_ENUM = 512
|
||||
};
|
||||
|
||||
Keyboard();
|
||||
virtual ~Keyboard() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,17 +29,17 @@ namespace love
|
||||
namespace keyboard
|
||||
{
|
||||
|
||||
static Keyboard *instance = nullptr;
|
||||
#define instance() (Module::getInstance<Keyboard>(Module::M_KEYBOARD))
|
||||
|
||||
int w_setKeyRepeat(lua_State *L)
|
||||
{
|
||||
instance->setKeyRepeat(luax_toboolean(L, 1));
|
||||
instance()->setKeyRepeat(luax_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_hasKeyRepeat(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->hasKeyRepeat());
|
||||
luax_pushboolean(L, instance()->hasKeyRepeat());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -57,20 +57,20 @@ int w_isDown(lua_State *L)
|
||||
}
|
||||
keylist[counter] = Keyboard::KEY_MAX_ENUM;
|
||||
|
||||
luax_pushboolean(L, instance->isDown(keylist));
|
||||
luax_pushboolean(L, instance()->isDown(keylist));
|
||||
delete[] keylist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setTextInput(lua_State *L)
|
||||
{
|
||||
instance->setTextInput(luax_toboolean(L, 1));
|
||||
instance()->setTextInput(luax_toboolean(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_hasTextInput(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->hasTextInput());
|
||||
luax_pushboolean(L, instance()->hasTextInput());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ static const luaL_Reg functions[] =
|
||||
|
||||
extern "C" int luaopen_love_keyboard(lua_State *L)
|
||||
{
|
||||
Keyboard *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
luax_catchexcept(L, [&](){ instance = new love::keyboard::sdl::Keyboard(); });
|
||||
|
||||
Reference in New Issue
Block a user