From 8e7217e74fbe5da0a9c1fee03d191b5a0266cedd Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Wed, 3 Oct 2012 02:54:08 +0200 Subject: [PATCH] Full Lua 5.2 compatibility and adherance to modules-create-no-globals --- doc/us/examples.html | 2 +- src/lfs.c | 20 +++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/doc/us/examples.html b/doc/us/examples.html index 65a6623..d6d32fc 100644 --- a/doc/us/examples.html +++ b/doc/us/examples.html @@ -65,7 +65,7 @@ attributes for each file inside it.

-require"lfs"
+local lfs = require"lfs"
 
 function attrdir (path)
     for file in lfs.dir(path) do
diff --git a/src/lfs.c b/src/lfs.c
index 8234711..8aa7412 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -56,20 +56,14 @@
 #include 
 #endif
 
-#define LUA_COMPAT_ALL
-#include "lua.h"
-#include "lauxlib.h"
-#include "lualib.h"
+#include 
+#include 
+#include 
+
 #include "lfs.h"
 
-/*
- * ** compatibility with Lua 5.2
- * */
-#if (LUA_VERSION_NUM == 502)
-#undef luaL_register
-#define luaL_register(L,n,f) \
-                { if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); }
-
+#if LUA_VERSION_NUM < 502
+#  define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
 #endif
 
 /* Define 'strerror' for systems that do not implement it */
@@ -881,7 +875,7 @@ static const struct luaL_Reg fslib[] = {
 int luaopen_lfs (lua_State *L) {
         dir_create_meta (L);
         lock_create_meta (L);
-        luaL_register (L, "lfs", fslib);
+        luaL_newlib (L, fslib);
         set_info (L);
         return 1;
 }