mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Replaced internal calls to luaL_register (deprecated in Lua 5.2) with an alternative
This commit is contained in:
+22
-2
@@ -198,6 +198,18 @@ int luax_assert_nilerror(lua_State *L, int idx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void luax_setfuncs(lua_State *L, const luaL_Reg *l)
|
||||||
|
{
|
||||||
|
if (l == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (; l->name != 0; l++)
|
||||||
|
{
|
||||||
|
lua_pushcfunction(L, l->func);
|
||||||
|
lua_setfield(L, -2, l->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int luax_register_module(lua_State *L, const WrappedModule &m)
|
int luax_register_module(lua_State *L, const WrappedModule &m)
|
||||||
{
|
{
|
||||||
// Put a reference to the C++ module in Lua.
|
// Put a reference to the C++ module in Lua.
|
||||||
@@ -225,7 +237,8 @@ int luax_register_module(lua_State *L, const WrappedModule &m)
|
|||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
// Register all the functions.
|
// Register all the functions.
|
||||||
luaL_register(L, 0, m.functions);
|
if (m.functions != 0)
|
||||||
|
luax_setfuncs(L, m.functions);
|
||||||
|
|
||||||
// Register types.
|
// Register types.
|
||||||
if (m.types != 0)
|
if (m.types != 0)
|
||||||
@@ -283,7 +296,7 @@ int luax_register_type(lua_State *L, const char *tname, const luaL_Reg *f)
|
|||||||
lua_setfield(L, -2, "typeOf");
|
lua_setfield(L, -2, "typeOf");
|
||||||
|
|
||||||
if (f != 0)
|
if (f != 0)
|
||||||
luaL_register(L, 0, f);
|
luax_setfuncs(L, f);
|
||||||
|
|
||||||
lua_pop(L, 1); // Pops metatable.
|
lua_pop(L, 1); // Pops metatable.
|
||||||
return 0;
|
return 0;
|
||||||
@@ -323,6 +336,13 @@ int luax_register_searcher(lua_State *L, lua_CFunction f, int pos)
|
|||||||
|
|
||||||
lua_getfield(L, -1, "loaders");
|
lua_getfield(L, -1, "loaders");
|
||||||
|
|
||||||
|
// Lua 5.2 renamed package.loaders to package.searchers.
|
||||||
|
if (lua_isnil(L, -1))
|
||||||
|
{
|
||||||
|
lua_pop(L, 1);
|
||||||
|
lua_getfield(L, -1, "searchers");
|
||||||
|
}
|
||||||
|
|
||||||
if (lua_isnil(L, -1))
|
if (lua_isnil(L, -1))
|
||||||
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");
|
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");
|
||||||
|
|
||||||
|
|||||||
@@ -217,6 +217,14 @@ int luax_assert_function(lua_State *L, int idx);
|
|||||||
**/
|
**/
|
||||||
int luax_assert_nilerror(lua_State *L, int idx);
|
int luax_assert_nilerror(lua_State *L, int idx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all functions in the array l (see luaL_Reg) into the table at the
|
||||||
|
* top of the stack.
|
||||||
|
* Similar to Lua 5.2's luaL_setfuncs without the upvalues, and to Lua 5.1's
|
||||||
|
* luaL_register without the library name.
|
||||||
|
**/
|
||||||
|
void luax_setfuncs(lua_State *L, const luaL_Reg *l);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a module in the love table. The love table will be created if it does not exist.
|
* Register a module in the love table. The love table will be created if it does not exist.
|
||||||
* @param L The Lua state.
|
* @param L The Lua state.
|
||||||
|
|||||||
@@ -744,6 +744,8 @@ Image::Wrap Canvas::getWrap() const
|
|||||||
|
|
||||||
bool Canvas::loadVolatile()
|
bool Canvas::loadVolatile()
|
||||||
{
|
{
|
||||||
|
fbo = depth_stencil = img = 0;
|
||||||
|
|
||||||
// glTexImage2D is guaranteed to error in this case.
|
// glTexImage2D is guaranteed to error in this case.
|
||||||
if (width > gl.getMaxTextureSize() || height > gl.getMaxTextureSize())
|
if (width > gl.getMaxTextureSize() || height > gl.getMaxTextureSize())
|
||||||
{
|
{
|
||||||
@@ -764,6 +766,7 @@ bool Canvas::loadVolatile()
|
|||||||
void Canvas::unloadVolatile()
|
void Canvas::unloadVolatile()
|
||||||
{
|
{
|
||||||
strategy->deleteFBO(fbo, depth_stencil, img);
|
strategy->deleteFBO(fbo, depth_stencil, img);
|
||||||
|
fbo = depth_stencil = img = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
for (size_t i = 0; i < attachedCanvases.size(); i++)
|
||||||
attachedCanvases[i]->release();
|
attachedCanvases[i]->release();
|
||||||
|
|||||||
@@ -155,14 +155,14 @@ int w_Geometry_getVertexMap(lua_State *L)
|
|||||||
{
|
{
|
||||||
Geometry *g = luax_checkgeometry(L, 1);
|
Geometry *g = luax_checkgeometry(L, 1);
|
||||||
|
|
||||||
size_t elementcount = g->getElementCount();
|
size_t elemcount = g->getElementCount();
|
||||||
const uint16 *elements = g->getElementArray();
|
const uint16 *elements = g->getElementArray();
|
||||||
|
|
||||||
if (elementcount == 0 || elements == 0)
|
if (elemcount == 0 || elements == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lua_createtable(L, elementcount, 0);
|
lua_createtable(L, elemcount, 0);
|
||||||
for (size_t i = 0; i < elementcount; i++)
|
for (size_t i = 0; i < elemcount; i++)
|
||||||
{
|
{
|
||||||
lua_pushinteger(L, elements[i]);
|
lua_pushinteger(L, elements[i]);
|
||||||
lua_rawseti(L, -2, i + 1);
|
lua_rawseti(L, -2, i + 1);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ static const luaL_Reg modules[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK
|
#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK
|
||||||
int w__openConsole(lua_State * L);
|
int w__openConsole(lua_State *L);
|
||||||
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
|
#endif // LOVE_LEGENDARY_CONSOLE_IO_HACK
|
||||||
|
|
||||||
const char *love_version()
|
const char *love_version()
|
||||||
@@ -201,7 +201,7 @@ int luaopen_love(lua_State * L)
|
|||||||
|
|
||||||
#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK
|
#ifdef LOVE_LEGENDARY_CONSOLE_IO_HACK
|
||||||
|
|
||||||
int w__openConsole(lua_State * L)
|
int w__openConsole(lua_State *L)
|
||||||
{
|
{
|
||||||
static bool is_open = false;
|
static bool is_open = false;
|
||||||
if (is_open)
|
if (is_open)
|
||||||
|
|||||||
Reference in New Issue
Block a user