Greetings people,

just forwarding this here, along with a patch by Dennis Schridde with
compatibility fixes ( Lua 5.1 -> Lua 5.2).

( i added him on CC too since he is not on the list ).

---------- Forwarded message ----------
From: Dennis Schridde <[email protected]>
Date: Sat, Sep 8, 2012 at 1:30 AM
Subject: [PATCH] Edje r76321 Lua 5.2 compatibility
To: [email protected]


Hi!

I ported Edje r76321 to compile and run with Lua 5.2. Please find the patch
attached. Please CC me, as I am not on the list (drakevr just proxied this
email for me).

The changes have been tested with lua_script.edc and I could not notice a
change in behaviour and only minor changes in the console output (minor
differences in timestamps and coordinates).

Necessary changes for Lua 5.2 compatibility were:
* lua_objlen was renamed to lua_rawlen
* luaL_register was removed, as Lua discourages modules setting globals now.
  I replaced it with one of two ways (depending on the context):
  - Where libname is NULL, I simply call luaL_setfuncs. There is no change in
functionality.
  - Where libname was not NULL, I create a global table and call luaL_setfuncs
on it.
   This gets the job done, but is not equivalent to luaL_register. If you want
to be stricter (in case you load the same module multiple times, for example),
luaL_requiref should be called with a luaopen_* function, which should call
luaL_newlib. The result of luaL_requiref should then be set via lua_setglobal.

Necessary changes for Lua 5.1 compatibility were:
* table.getn(t) was replaced by the #t operator

Best regards,
Dennis


-- 
Regards,

Alex-P. Natsios
(a.k.a Drakevr)
Index: src/examples/lua_script.edc
===================================================================
--- src/examples/lua_script.edc	(revision 76321)
+++ src/examples/lua_script.edc	(working copy)
@@ -67,7 +67,7 @@
             d = edje.size();
             D.clip:geom(10, 10, d.w - 20, d.h - 20);
             c = D.clip:clipees();
-            for i=1,table.getn(c),1 do
+            for i=1,#c,1 do
                d = c[i]:geom();
                print("lua::" .. i .. " geom = " .. d.x .. "," .. d.y .. " " .. d.w .. "x" .. d.h);
             end
Index: src/lib/edje_lua2.c
===================================================================
--- src/lib/edje_lua2.c	(revision 76321)
+++ src/lib/edje_lua2.c	(working copy)
@@ -985,7 +985,11 @@
         int i, n;
         const char *str;
         luaL_checktype(L, 3, LUA_TTABLE);                    // Stack usage [-0, +0, v]
+#if LUA_VERSION_NUM >= 502
+        n = lua_rawlen(L, 3);                                // Stack usage [-0, +0, -]
+#else
         n = lua_objlen(L, 3);                                // Stack usage [-0, +0, -]
+#endif
         emsg = alloca(sizeof(Edje_Message_String_Set) + ((n - 1) * sizeof(char *)));
         emsg->count = n;
         for (i = 1; i <= n; i ++)
@@ -1003,7 +1007,11 @@
         Edje_Message_Int_Set *emsg;
         int i, n;
         luaL_checktype(L, 3, LUA_TTABLE);                    // Stack usage [-0, +0, v]
+#if LUA_VERSION_NUM >= 502
+        n = lua_rawlen(L, 3);                                // Stack usage [-0, +0, -]
+#else
         n = lua_objlen(L, 3);                                // Stack usage [-0, +0, -]
+#endif
         emsg = alloca(sizeof(Edje_Message_Int_Set) + ((n - 1) * sizeof(int)));
         emsg->count = n;
         for (i = 1; i <= n; i ++)
@@ -1020,7 +1028,11 @@
         Edje_Message_Float_Set *emsg;
         int i, n;
         luaL_checktype(L, 3, LUA_TTABLE);                    // Stack usage [-0, +0, v]
+#if LUA_VERSION_NUM >= 502
+        n = lua_rawlen(L, 3);                                // Stack usage [-0, +0, -]
+#else
         n = lua_objlen(L, 3);                                // Stack usage [-0, +0, -]
+#endif
         emsg = alloca(sizeof(Edje_Message_Float_Set) + ((n - 1) * sizeof(double)));
         emsg->count = n;
         for (i = 1; i <= n; i ++)
@@ -1057,7 +1069,11 @@
         const char *str = luaL_checkstring(L, 3);            // Stack usage [-0, +0, v]
         if (!str) return 0;
         luaL_checktype(L, 4, LUA_TTABLE);                    // Stack usage [-0, +0, v]
+#if LUA_VERSION_NUM >= 502
+        n = lua_rawlen(L, 4);                                // Stack usage [-0, +0, -]
+#else
         n = lua_objlen(L, 4);                                // Stack usage [-0, +0, -]
+#endif
         emsg = alloca(sizeof(Edje_Message_String_Int_Set) + ((n - 1) * sizeof(int)));
         emsg->str = (char *)str;
         emsg->count = n;
@@ -1077,7 +1093,11 @@
         const char *str = luaL_checkstring(L, 3);            // Stack usage [-0, +0, v]
         if (!str) return 0;
         luaL_checktype(L, 4, LUA_TTABLE);                    // Stack usage [-0, +0, v]
+#if LUA_VERSION_NUM >= 502
+        n = lua_rawlen(L, 4);                                // Stack usage [-0, +0, -]
+#else
         n = lua_objlen(L, 4);
+#endif
         emsg = alloca(sizeof(Edje_Message_String_Float_Set) + ((n - 1) * sizeof(double)));
         emsg->str = (char *)str;
         emsg->count = n;
@@ -3734,7 +3754,11 @@
 {
    lua_pushnil(L);                                   // Stack usage [-0, +1, -]
    luaL_newmetatable(L, "bogan");                    // Stack usage [-0, +1, m]
+#if LUA_VERSION_NUM >= 502
+   luaL_setfuncs(L, _elua_bogan_funcs, 0);           // Stack usage [-0, +0, e]
+#else
    luaL_register(L, 0, _elua_bogan_funcs);           // Stack usage [-1, +1, m]
+#endif
    lua_setmetatable(L, -2);                          // Stack usage [-1, +0, -]
    lua_pop(L, 1);                                    // Stack usage [-1, +0, -]
 }
@@ -3746,14 +3770,25 @@
 _elua_add_functions(lua_State *L, const char *api, const luaL_Reg *funcs, const char *meta, const char *parent, const char *base)  // Stack usage [-3, +5, m]  if inheriting [-6, +11, em]
 {
    // Create an api table, fill it full of the methods.
+#if LUA_VERSION_NUM >= 502
+   lua_newtable(L);                           // Stack usage [-0, +1, e]
+   lua_pushvalue(L, -1);                      // Stack usage [-0, +1, -]
+   lua_setglobal(L, api);                     // Stack usage [-1, +0, e]
+   luaL_setfuncs(L, funcs, 0);                // Stack usage [-0, +0, e]
+#else
    luaL_register(L, api, funcs);              // Stack usage [-0, +1, m]
+#endif
    // Set the api metatable to the bogan metatable.
    luaL_getmetatable(L, "bogan");             // Stack usage [-0, +1, -]
    lua_setmetatable(L, -2);                   // Stack usage [-1, +0, -]
    // Creat a meta metatable.
    luaL_newmetatable(L, meta);                // Stack usage [-0, +1, m]
    // Put the gc functions in the metatable.
+#if LUA_VERSION_NUM >= 502
+   luaL_setfuncs(L, _elua_edje_gc_funcs, 0);  // Stack usage [-0, +0, e]
+#else
    luaL_register(L, 0, _elua_edje_gc_funcs);  // Stack usage [-1, +1, m]
+#endif
    // Create an __index entry in the metatable, make it point to the api table.
    lua_pushliteral(L, "__index");             // Stack usage [-0, +1, m]
    lua_pushvalue(L, -3);                      // Stack usage [-0, +1, -]
@@ -3821,14 +3856,29 @@
 
    for (l = _elua_libs; l->func; l++)                                                      // Currently * 4
      {
+#if LUA_VERSION_NUM >= 502
+        luaL_requiref(L, l->name, l->func, 1);                                             // Stack usage [-0, +1, e]
+#else
         lua_pushcfunction(L, l->func);                                                     // Stack usage [-0, +1, m]
         lua_pushstring(L, l->name);                                                        // Stack usage [-0, +1, m]
         lua_call(L, 1, 0);                                                                 // Stack usage [-2, +0, e]
+#endif
      }
 
+#if LUA_VERSION_NUM >= 502
+   lua_newtable(L);                                                                        // Stack usage [-0, +1, e]
+   lua_pushvalue(L, -1);                                                                   // Stack usage [-0, +1, -]
+   lua_setglobal(L, _elua_edje_api);                                                       // Stack usage [-1, +0, e]
+   luaL_setfuncs(L, _elua_edje_funcs, 0);                                                  // Stack usage [-0, +0, e]
+#else
    luaL_register(L, _elua_edje_api, _elua_edje_funcs);                                     // Stack usage [-0, +1, m]
+#endif
    luaL_newmetatable(L, _elua_edje_meta);                                                  // Stack usage [-0, +1, m]
+#if LUA_VERSION_NUM >= 502
+   luaL_setfuncs(L, _elua_edje_gc_funcs, 0);                                               // Stack usage [-0, +0, e]
+#else
    luaL_register(L, 0, _elua_edje_gc_funcs);                                               // Stack usage [-1, +1, m]
+#endif
 
    _elua_add_functions(L, _elua_evas_api, _elua_evas_funcs, _elua_evas_meta, NULL, NULL);  // Stack usage [-3, +5, m]
 
@@ -3873,18 +3923,33 @@
 
    for (l = _elua_libs; l->func; l++)                             // Currently * 4
      {
+#if LUA_VERSION_NUM >= 502
+        luaL_requiref(L, l->name, l->func, 1);                    // Stack usage [-0, +1, e]
+#else
         lua_pushcfunction(L, l->func);                            // Stack usage [-0, +1, m]
         lua_pushstring(L, l->name);                               // Stack usage [-0, +1, m]
         lua_call(L, 1, 0);                                        // Stack usage [-2, +0, m]
+#endif
      }
 
    _elua_bogan_protect(L);                                        // Stack usage [+3, -3, m]
 
+#if LUA_VERSION_NUM >= 502
+   lua_newtable(L);                                               // Stack usage [-0, +1, e]
+   lua_pushvalue(L, -1);                                          // Stack usage [-0, +1, -]
+   lua_setglobal(L, _elua_edje_api);                              // Stack usage [-1, +0, e]
+   luaL_setfuncs(L, _elua_edje_funcs, 0);                         // Stack usage [-0, +0, e]
+#else
    luaL_register(L, _elua_edje_api, _elua_edje_funcs);            // Stack usage [-0, +1, m]
+#endif
    luaL_getmetatable(L, "bogan");                                 // Stack usage [-0, +1, -]
    lua_setmetatable(L, -2);                                       // Stack usage [-1, +0, -]
    luaL_newmetatable(L, _elua_edje_meta);                         // Stack usage [-0, +1, m]
+#if LUA_VERSION_NUM >= 502
+   luaL_setfuncs(L, _elua_edje_gc_funcs, 0);                      // Stack usage [-0, +0, e]
+#else
    luaL_register(L, 0, _elua_edje_gc_funcs);                      // Stack usage [-1, +1, m]
+#endif
 
    lua_pop(L, 2);                                                 // Stack usage [-n, +0, -]
 
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to