diff --git a/daemon/bindings.c b/daemon/bindings.c
index 5ed40a3c43f09e0acf8660235d993856398cc89b..cbb181837053f11d9240d3caa644fb626ae9a158 100644
--- a/daemon/bindings.c
+++ b/daemon/bindings.c
@@ -20,14 +20,14 @@
 #include "daemon/bindings.h"
 
 /** @internal Compatibility wrapper for Lua 5.0 - 5.2 */
-#if LUA_VERSION_NUM < 502
+#if LUA_VERSION_NUM >= 502
+#define register_lib(L, name, lib) \
+	luaL_newlib((L), (lib))
+#else
 #define lua_rawlen(L, obj) \
 	lua_objlen((L), (obj))
 #define register_lib(L, name, lib) \
 	luaL_openlib((L), (name), (lib), 0)
-#else
-#define register_lib(L, name, lib) \
-	luaL_newlib((L), (lib))
 #endif
 
 /** List loaded modules */
diff --git a/daemon/engine.c b/daemon/engine.c
index 791936d32783eb26d99f763d57358d7d678aa8e4..4011407908784c4aec85d90a4d620f558591f6d9 100644
--- a/daemon/engine.c
+++ b/daemon/engine.c
@@ -321,11 +321,11 @@ int engine_unregister(struct engine *engine, const char *name)
 void engine_lualib(struct engine *engine, const char *name, lua_CFunction lib_cb)
 {
 	if (engine != NULL) {
-#if LUA_VERSION_NUM < 502
-		lib_cb(engine->L);
-#else
+#if LUA_VERSION_NUM >= 502
 		luaL_requiref(engine->L, name, lib_cb, 1);
 		lua_pop(engine->L, 1);
+#else
+		lib_cb(engine->L);
 #endif
 	}
 }