mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Disallow requiring love.graphics and love.window in threads.
This commit is contained in:
@@ -1064,6 +1064,13 @@ lua_State *luax_getpinnedthread(lua_State *L)
|
||||
return thread;
|
||||
}
|
||||
|
||||
extern "C" int luax_module_threaderror(lua_State *L)
|
||||
{
|
||||
// Module name is the first param in the stack.
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
return luaL_error(L, "The %s module cannot be used in thread code.", name);
|
||||
}
|
||||
|
||||
void luax_markdeprecated(lua_State *L, int level, const char *name, APIType api)
|
||||
{
|
||||
luax_markdeprecated(L, level, name, api, DEPRECATED_NO_REPLACEMENT, nullptr);
|
||||
|
||||
@@ -493,6 +493,14 @@ lua_State *luax_insistpinnedthread(lua_State *L);
|
||||
**/
|
||||
lua_State *luax_getpinnedthread(lua_State *L);
|
||||
|
||||
/**
|
||||
* Lua C function to use with luax_preload when the given module should not
|
||||
* be allowed on a thread. Must be called from the thread's code.
|
||||
**/
|
||||
extern "C" {
|
||||
int luax_module_threaderror(lua_State *L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a function as deprecated. Should only be called inside wrapper function
|
||||
* code.
|
||||
|
||||
@@ -68,6 +68,10 @@ void LuaThread::threadFunction()
|
||||
lua_pop(L, 1);
|
||||
#endif // LOVE_BUILD_STANDALONE
|
||||
|
||||
// We might want to add more input-related modules to this list.
|
||||
luax_preload(L, luax_module_threaderror, "love.window");
|
||||
luax_preload(L, luax_module_threaderror, "love.graphics");
|
||||
|
||||
luax_require(L, "love.thread");
|
||||
lua_pop(L, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user