[grilo-plugins] Revert "lua-factory: change grl.callback(), grl.fetch() and grl.unzip()"



commit fd58add90946a2677d26c352dc1d6e962bf5ab94
Author: Victor Toso <me victortoso com>
Date:   Tue Mar 8 22:41:51 2016 +0100

    Revert "lua-factory: change grl.callback(), grl.fetch() and grl.unzip()"
    
    In order to keep the previous API between Lua sources and Lua-Factory.
    
    This reverts commit d809be39ed2bbd4c410be7aa527b36902362511a.
    
    After applying this patch, it will break the lua sources due the API
    change.  We are not passing callback as argument anymore. Lua sources
    should use grl.callback().
    
    This is not 100% revert as we are keeping a few changes to grl.fetch and
    to grl.unzip:
    * Both those functions are still using a lua function as callback which
      was a string before d809be39;
    * Both this functions now can handle userdata as the last argument;
    * For grl.fetch, the second argument is still an optional table for
      GrlNetWc;
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763046

 src/lua-factory/grl-lua-common.h  |    2 -
 src/lua-factory/grl-lua-factory.c |   12 +++------
 src/lua-factory/grl-lua-library.c |   47 ++++++++-----------------------------
 3 files changed, 14 insertions(+), 47 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-common.h b/src/lua-factory/grl-lua-common.h
index 0000f53..9137461 100644
--- a/src/lua-factory/grl-lua-common.h
+++ b/src/lua-factory/grl-lua-common.h
@@ -83,7 +83,6 @@ typedef struct _OperationSpec {
   GrlMedia *media;
   gpointer user_data;
   guint error_code;
-  gboolean callback_done;
   guint lua_source_waiting_ops;
 } OperationSpec;
 
@@ -92,7 +91,6 @@ gpointer grl_lua_library_load_goa_data (lua_State *L);
 
 void grl_lua_library_push_grl_media (lua_State *L, GrlMedia *media);
 void grl_lua_library_push_grl_options (lua_State *L, guint operation_id, GrlOperationOptions *options, GList 
*keys);
-void grl_lua_library_push_grl_callback (lua_State *L, OperationSpec *os);
 
 /* grl-lua-library-operations */
 void grl_lua_operations_init_priv_state (lua_State *L);
diff --git a/src/lua-factory/grl-lua-factory.c b/src/lua-factory/grl-lua-factory.c
index 1cf2978..61a2d65 100644
--- a/src/lua-factory/grl-lua-factory.c
+++ b/src/lua-factory/grl-lua-factory.c
@@ -1527,8 +1527,7 @@ grl_lua_factory_source_search (GrlSource *source,
 
   lua_pushstring (L, text);
   grl_lua_library_push_grl_options (L, ss->operation_id, ss->options, ss->keys);
-  grl_lua_library_push_grl_callback (L, os);
-  if (!grl_lua_operations_pcall (L, 3, os, &err)) {
+  if (!grl_lua_operations_pcall (L, 2, os, &err)) {
     if (err != NULL) {
       GRL_WARNING ("calling search function failed: %s", err->message);
       g_error_free (err);
@@ -1559,8 +1558,7 @@ grl_lua_factory_source_browse (GrlSource *source,
 
   grl_lua_library_push_grl_media (L, bs->container);
   grl_lua_library_push_grl_options (L, bs->operation_id, bs->options, bs->keys);
-  grl_lua_library_push_grl_callback (L, os);
-  if (!grl_lua_operations_pcall (L, 3, os, &err)) {
+  if (!grl_lua_operations_pcall (L, 2, os, &err)) {
     if (err != NULL) {
       GRL_WARNING ("calling browse function failed: %s", err->message);
       g_error_free (err);
@@ -1594,8 +1592,7 @@ grl_lua_factory_source_query (GrlSource *source,
 
   lua_pushstring (L, query);
   grl_lua_library_push_grl_options (L, qs->operation_id, qs->options, qs->keys);
-  grl_lua_library_push_grl_callback (L, os);
-  if (!grl_lua_operations_pcall (L, 3, os, &err)) {
+  if (!grl_lua_operations_pcall (L, 2, os, &err)) {
     if (err != NULL) {
       GRL_WARNING ("calling query function failed: %s", err->message);
       g_error_free (err);
@@ -1627,8 +1624,7 @@ grl_lua_factory_source_resolve (GrlSource *source,
 
   grl_lua_library_push_grl_media (L, rs->media);
   grl_lua_library_push_grl_options (L, rs->operation_id, rs->options, rs->keys);
-  grl_lua_library_push_grl_callback (L, os);
-  if (!grl_lua_operations_pcall (L, 3, os, &err)) {
+  if (!grl_lua_operations_pcall (L, 2, os, &err)) {
     if (err != NULL) {
       GRL_WARNING ("calling resolve function failed: %s", err->message);
       g_error_free (err);
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index 4f5dec7..8dc8172 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -908,7 +908,6 @@ grl_l_fetch (lua_State *L)
 
   luaL_argcheck (L, (lua_isstring (L, 1) || lua_istable (L, 1)), 1,
                  "expecting url as string or an array of urls");
-
   luaL_argcheck (L, (lua_isfunction (L, 2) || lua_istable (L, 2)), 2,
                  "expecting callback function or network parameters");
 
@@ -958,13 +957,12 @@ grl_l_fetch (lua_State *L)
   }
 
   if (!verify_plaintext_fetch (L, urls, num_urls)) {
-    GRL_WARNING ("Source is broken, it makes plaintext network queries but "
-                 "does not set the 'net:plaintext' tag");
+    GRL_WARNING ("Source '%s' is broken, it makes plaintext network queries but "
+                 "does not set the 'net:plaintext' tag", grl_source_get_id (os->source));
 
     luaL_unref (L, LUA_REGISTRYINDEX, lua_userdata);
     luaL_unref (L, LUA_REGISTRYINDEX, lua_callback);
     lua_gc (L, LUA_GCCOLLECT, 0);
-
     g_free (urls);
     return 0;
   }
@@ -998,7 +996,7 @@ grl_l_fetch (lua_State *L)
 }
 
 /**
-* callback
+* grl.callback
 *
 * @media: (table) The media content to be returned.
 * @count: (integer) Number of media remaining to the application.
@@ -1009,25 +1007,20 @@ grl_l_callback (lua_State *L)
 {
   gint nparam;
   gint count = 0;
-  OperationSpec **p;
   OperationSpec *os;
   GrlMedia *media;
 
   GRL_DEBUG ("grl.callback()");
 
-  g_return_val_if_fail (lua_isuserdata(L, lua_upvalueindex(1)), 0);
-  p = lua_touserdata (L, lua_upvalueindex(1));
-  os = *p;
-
   nparam = lua_gettop (L);
-
-  if (os->callback_done) {
+  os = grl_lua_operations_get_current_op (L);
+  if (os == NULL) {
     luaL_error (L, "Source is broken as callback was called "
                 "after the operation has been finalized");
     return 0;
   }
 
-  media = os->media;
+  media = (os->op_type == LUA_RESOLVE) ? os->media : NULL;
 
   if (nparam > 0) {
     media = grl_util_build_media (L, media);
@@ -1046,9 +1039,8 @@ grl_l_callback (lua_State *L)
 
   /* finishing callback */
   if (count == 0)
-    os->callback_done = TRUE;
+    grl_lua_operations_set_source_state (L, LUA_SOURCE_FINALIZED, os);
 
-  grl_lua_operations_set_source_state (L, LUA_SOURCE_FINALIZED, os);
   return 0;
 }
 
@@ -1407,6 +1399,7 @@ gint
 luaopen_grilo (lua_State *L)
 {
   static const luaL_Reg library_fn[] = {
+    {"callback", &grl_l_callback},
     {"fetch", &grl_l_fetch},
     {"debug", &grl_l_debug},
     {"warning", &grl_l_warning},
@@ -1486,7 +1479,7 @@ grl_util_operation_spec_gc (lua_State *L)
   OperationSpec **userdata = lua_touserdata (L, 1);
   OperationSpec *os = *userdata;
 
-  if (os->callback_done == FALSE) {
+  if (grl_lua_operations_get_current_op (L)) {
 
     const char *type;
     switch (os->op_type) {
@@ -1519,11 +1512,10 @@ grl_util_operation_spec_gc (lua_State *L)
     }
   }
 
-  g_slice_free (OperationSpec, os);
+  grl_lua_operations_set_source_state (L, LUA_SOURCE_FINALIZED, os);
   *userdata = NULL;
   return 0;
 }
-
 /**
  * push_operation_spec_userdata
  *
@@ -1553,25 +1545,6 @@ push_operation_spec_userdata (lua_State *L, OperationSpec *os)
 }
 
 /**
- * grl_lua_library_push_grl_callback
- *
- * Pushes two C closures on top of the lua stack, representing the
- * callback and the options for the current operation.
- *
- * @L: LuaState where the data is stored.
- * @os: OperationSpec the current operation.
- * @return: Nothing.
- **/
-void
-grl_lua_library_push_grl_callback (lua_State *L, OperationSpec *os)
-{
-  /* push the OperationSpec userdata */
-  push_operation_spec_userdata (L, os);
-  /* use this userdata as an upvalue for the callback */
-  lua_pushcclosure (L, grl_l_callback, 1);
-}
-
-/**
  * grl_lua_library_save_goa_data
  *
  * @L: LuaState where the data will be stored.


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