1. Laurens Rodriguez
  2. love

Commits

Laurens Rodriguez  committed f7ea448

kdblib.c: fixes from Lua 5.2.2

  • Participants
  • Parent commits f968423
  • Branches dev

Comments (0)

Files changed (1)

File src/libraries/killa/kdblib.c

View file
  • Ignore whitespace
 }
 
 
-#define gethooktable(L)	killaL_getsubtable(L, KILLA_REGISTRYINDEX, HOOKKEY);
+#define gethooktable(L)	killaL_getsubtable(L, KILLA_REGISTRYINDEX, HOOKKEY)
 
 
 static void hookf (killa_State *L, killa_Debug *ar) {
   static const char *const hooknames[] =
     {"call", "return", "line", "count", "tail call"};
   gethooktable(L);
-  killa_rawgetp(L, -1, L);
+  killa_pushthread(L);
+  killa_rawget(L, -2);
   if (killa_isfunction(L, -1)) {
     killa_pushstring(L, hooknames[(int)ar->event]);
     if (ar->currentline >= 0)
     count = killaL_optint(L, arg+3, 0);
     func = hookf; mask = makemask(smask, count);
   }
-  gethooktable(L);
+  if (gethooktable(L) == 0) {  /* creating hook table? */
+    killa_pushstring(L, "k");
+    killa_setfield(L, -2, "__mode");  /** hooktable.__mode = "k" */
+    killa_pushvalue(L, -1);
+    killa_setmetatable(L, -2);  /* setmetatable(hooktable) = hooktable */
+  }
+  killa_pushthread(L1); killa_xmove(L1, L, 1);
   killa_pushvalue(L, arg+1);
-  killa_rawsetp(L, -2, L1);  /* set new hook */
-  killa_pop(L, 1);  /* remove hook table */
+  killa_rawset(L, -3);  /* set new hook */
   killa_sethook(L1, func, mask, count);  /* set hooks */
   return 0;
 }
     killa_pushliteral(L, "external hook");
   else {
     gethooktable(L);
-    killa_rawgetp(L, -1, L1);   /* get hook */
+    killa_pushthread(L1); killa_xmove(L1, L, 1);
+    killa_rawget(L, -2);   /* get hook */
     killa_remove(L, -2);  /* remove hook table */
   }
   killa_pushstring(L, unmakemask(mask, buff));