lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In Lua 5.2, I found I had to change the way I loaded standard libraries.

John

--- a/datalog.c
+++ b/datalog.c
@@ -72,7 +72,11 @@ dl_lua(dl_db_t L)
 }

 static const luaL_Reg lualibs[] = {
+#if LUA_VERSION_NUM < 502
  {"", luaopen_base},
+#else
+  {"_G", luaopen_base},
+#endif
  {LUA_TABLIBNAME, luaopen_table},
  {LUA_STRLIBNAME, luaopen_string},
  {NULL, NULL}
@@ -82,11 +86,16 @@ DATALOG_API dl_db_t
 dl_open(void)
 {
  lua_State *L = luaL_newstate();
-  const luaL_Reg *lib = lualibs;
-  for (; lib->func; lib++) {   /* Load libraries used by the */
-    lua_pushcfunction(L, lib->func); /* Lua datalog program. */
+  const luaL_Reg *lib = lualibs; /* Load libraries used by the */
+  for (; lib->func; lib++) {    /* Lua datalog program. */
+#if LUA_VERSION_NUM < 502
+    lua_pushcfunction(L, lib->func);
    lua_pushstring(L, lib->name);
    lua_call(L, 1, 0);
+#else
+    luaL_requiref(L, lib->name, lib->func, 1);
+    lua_pop(L, 1);             /* remove lib */
+#endif
  }
  if (dl_lua(L))               /* Load the Lua program. */
    return NULL;