Merge branch 'scripting-lua-unhook' (early part) into screen-scripting-soc
authorRui Guo <firemeteor.guo@gmail.com>
Mon, 15 Jun 2009 11:20:36 +0000 (15 19:20 +0800)
committerRui Guo <firemeteor.guo@gmail.com>
Mon, 15 Jun 2009 11:20:36 +0000 (15 19:20 +0800)
Requires further modification.

Conflicts:
src/lua.c
src/scripts/cmdcallback.lua

1  2 
src/lua.c
src/scripts/cmdcallback.lua

diff --cc src/lua.c
+++ b/src/lua.c
@@@ -79,16 -82,24 +82,29 @@@ static int LuaDispatch(void *handler, c
  static int LuaRegEvent(lua_State *L);
  static int LuaUnRegEvent(lua_State *L);
  static void LuaShowErr(lua_State *L);
 +struct binding lua_binding;
  
- typedef int lua_handler;
- #define LuaAllocHandler(a) a
- #define LuaFreeHandler(a)
+ enum
+ {
+   LUA_HANDLER_TYPE_N = 1,
+   LUA_HANDLER_TYPE_F
+ };
+ struct lua_handler
+ {
+   int type;
+   union
+   {
+     char *name;
+     int reference;
+   } u;
+   struct listener *listener;
+ };
  
 +void LuaPushHandler(lua_State *L, lua_handler lh);
 +void LuaHRef(lua_State *L, int key, int reg);
 +lua_handler LuaCheckHandler(lua_State *L, int idx, int ref);
 +
  /** Template {{{ */
  
  #define CHECK_TYPE(name, type) \
@@@ -684,8 -702,6 +753,7 @@@ static const luaL_reg screen_methods[] 
    {"command", screen_exec_command},
    {"append_msg", screen_append_msg},
    {"hook", LuaRegEvent},
-   {"unhook", LuaUnRegEvent},
 +  {"input", screen_input},
    {0, 0}
  };
  
@@@ -720,23 -734,8 +788,24 @@@ int LuaInit(void
    REGISTER(display);
    REGISTER(user);
    REGISTER(canvas);
+   REGISTER(callback);
  
 +  /* To store handler funcs */
 +  luaL_getmetatable(L, "screen");
 +  /* two kinds of info in this table:
 +   * _funckey[func]->key
 +   * _funckey[key]->refcnt */
 +  lua_pushstring(L, "_funckey");
 +  lua_newtable(L);
 +  lua_rawset(L, -3);
 +  /* two kinds of info in this table:
 +   * _keyfunc[key]->func
 +   * _keyfunc[func]->name */
 +  lua_pushstring(L, "_keyfunc");
 +  lua_newtable(L);
 +  lua_rawset(L, -3);
 +  lua_pop(L, 1);
 +
    return 0;
  }
  
@@@ -28,30 -28,10 +28,21 @@@ function cmd2(name, args
      return 0
  end
  
 -ticket2 = screen.hook("cmdexecuted", "cmd")
 +ticket1 = screen.hook("cmdexecuted", cmd1)
 +ticket2 = screen.hook("cmdexecuted", "cmd2")
  
  function unhook()
-   if ticket1 ~= nil then
-     screen.unhook(ticket1, cmd1)
-     ticket1 = nil
-   end
-   if ticket2 ~= nil then
-     screen.unhook(ticket2, "cmd2")
-     ticket2 = nil
-   end
+   ticket1:unhook()
+   ticket2:unhook()
  end
  
-   if screen.unhook(ticket1, "cmd1") == false then
-     error("unhook failed")
-   end
 +--A second unhook should faild
 +function debug_unhook()
++  ticket1:unhook()
 +end
 +    
 +--A second hook should faild
 +function debug_hook()
 +  ticket1=screen.hook("cmdexecuted", "cmd1")
 +end
 +