mirror of https://github.com/bjornbytes/lovr.git
Get closure on that lovr.event memory leak;
This commit is contained in:
parent
8518e32ae2
commit
fdb363df4b
|
@ -2,6 +2,8 @@
|
||||||
#include "event/event.h"
|
#include "event/event.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
static int pollRef;
|
||||||
|
|
||||||
static int nextEvent(lua_State* L) {
|
static int nextEvent(lua_State* L) {
|
||||||
Event* event = lovrEventPoll();
|
Event* event = lovrEventPoll();
|
||||||
|
|
||||||
|
@ -44,6 +46,11 @@ const luaL_Reg lovrEvent[] = {
|
||||||
int l_lovrEventInit(lua_State* L) {
|
int l_lovrEventInit(lua_State* L) {
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_register(L, NULL, lovrEvent);
|
luaL_register(L, NULL, lovrEvent);
|
||||||
|
|
||||||
|
// Store nextEvent in the registry to avoid creating a closure every time we poll for events.
|
||||||
|
lua_pushcfunction(L, nextEvent);
|
||||||
|
pollRef = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
|
|
||||||
map_init(&EventTypes);
|
map_init(&EventTypes);
|
||||||
map_set(&EventTypes, "quit", EVENT_QUIT);
|
map_set(&EventTypes, "quit", EVENT_QUIT);
|
||||||
lovrEventInit();
|
lovrEventInit();
|
||||||
|
@ -56,7 +63,7 @@ int l_lovrEventClear(lua_State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int l_lovrEventPoll(lua_State* L) {
|
int l_lovrEventPoll(lua_State* L) {
|
||||||
lua_pushcclosure(L, nextEvent, 0);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, pollRef);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue