mirror of https://github.com/bjornbytes/lovr.git
Polyfill LUA_RIDX_MAINTHREAD;
Instead of using a static variable.
This commit is contained in:
parent
d4c8382306
commit
d340fc7aaa
|
@ -76,9 +76,8 @@ static HeadsetRenderData headsetRenderData;
|
|||
|
||||
static void renderHelper(void* userdata) {
|
||||
HeadsetRenderData* renderData = userdata;
|
||||
lua_State* L = renderData->L;
|
||||
#ifdef LOVR_HEADSET_HELPER_USES_REGISTRY
|
||||
// Emscripten and Oculus Mobile path
|
||||
lua_State* L = luax_getmainstate();
|
||||
lua_getglobal(L, "_lovrHeadsetRenderError");
|
||||
bool noError = lua_isnil(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
@ -91,9 +90,6 @@ static void renderHelper(void* userdata) {
|
|||
lua_pop(L, 1); // pop luax_getstack
|
||||
}
|
||||
#else
|
||||
// Normal path
|
||||
lua_State* L = renderData->L;
|
||||
lua_pushvalue(L, -1);
|
||||
lua_call(L, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
@ -279,8 +275,12 @@ static int l_lovrHeadsetRenderTo(lua_State* L) {
|
|||
}
|
||||
|
||||
headsetRenderData.ref = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
#endif
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
|
||||
headsetRenderData.L = lua_tothread(L, -1);
|
||||
lua_pop(L, 1);
|
||||
#else
|
||||
headsetRenderData.L = L;
|
||||
#endif
|
||||
lovrHeadsetDriver->renderTo(renderHelper, &headsetRenderData);
|
||||
return 0;
|
||||
}
|
||||
|
|
13
src/luax.c
13
src/luax.c
|
@ -301,12 +301,9 @@ int luax_pushLovrHeadsetRenderError(lua_State *L) {
|
|||
return haveRenderError;
|
||||
}
|
||||
|
||||
static lua_State *luax_mainstate;
|
||||
|
||||
lua_State *luax_getmainstate() {
|
||||
return luax_mainstate;
|
||||
}
|
||||
|
||||
void luax_setmainstate(lua_State *L) {
|
||||
luax_mainstate = L;
|
||||
#if LUA_VERSION_NUM < 502
|
||||
void luax_setmainthread(lua_State *L) {
|
||||
lua_pushthread(L);
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_MAINTHREAD);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,5 +28,10 @@ void luax_pushconf(lua_State* L);
|
|||
int luax_setconf(lua_State* L);
|
||||
Color luax_checkcolor(lua_State* L, int index);
|
||||
int luax_pushLovrHeadsetRenderError(lua_State *L);
|
||||
lua_State *luax_getmainstate(void);
|
||||
void luax_setmainstate(lua_State *L);
|
||||
|
||||
#if LUA_VERSION_NUM < 502
|
||||
#define LUA_RIDX_MAINTHREAD 1
|
||||
void luax_setmainthread(lua_State* L);
|
||||
#else
|
||||
#define luax_setmainthread
|
||||
#endif
|
||||
|
|
|
@ -70,7 +70,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
do {
|
||||
lua_State* L = luaL_newstate();
|
||||
luax_setmainstate(L);
|
||||
luax_setmainthread(L);
|
||||
luaL_openlibs(L);
|
||||
|
||||
lua_State* T = lovrInit(L, argc, argv);
|
||||
|
@ -92,7 +92,6 @@ int main(int argc, char** argv) {
|
|||
restart = lua_type(T, -1) == LUA_TSTRING && !strcmp(lua_tostring(T, -1), "restart");
|
||||
status = lua_tonumber(T, -1);
|
||||
lua_close(L);
|
||||
luax_setmainstate(NULL);
|
||||
#endif
|
||||
} while (restart);
|
||||
|
||||
|
|
Loading…
Reference in New Issue