Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move this debugging function to lua_utils.c
authorChristophe Thiéry <christopho128@gmail.com>
Wed, 9 Nov 2011 19:22:14 +0000 (20:22 +0100)
committerChristophe Thiéry <christopho128@gmail.com>
Wed, 9 Nov 2011 19:22:14 +0000 (20:22 +0100)
src/bindings/lua/lua_utils.c
src/bindings/lua/lua_utils.h
src/bindings/lua/simgrid_lua.c

index 3f1f523..24bd4ab 100644 (file)
@@ -6,6 +6,7 @@
 
 /* SimGrid Lua helper functions                                             */
 
 
 /* SimGrid Lua helper functions                                             */
 
+#include <lauxlib.h>
 #include "lua_utils.h"
 #include "xbt.h"
 #include "xbt/log.h"
 #include "lua_utils.h"
 #include "xbt.h"
 #include "xbt/log.h"
@@ -137,6 +138,39 @@ void sglua_stack_dump(const char* msg, lua_State* L)
   }
 }
 
   }
 }
 
+/**
+ * \brief Like luaL_checkudata, with additional debug logs.
+ *
+ * This function is for debugging purposes only.
+ *
+ * \param L a lua state
+ * \param ud index of the userdata to check in the stack
+ * \param tname key of the metatable of this userdata in the registry
+ */
+void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
+{
+  XBT_DEBUG("Checking the userdata: ud = %d", ud);
+  sglua_stack_dump("my_checkudata: ", L);
+  void* p = lua_touserdata(L, ud);
+  lua_getfield(L, LUA_REGISTRYINDEX, tname);
+  const void* correct_mt = lua_topointer(L, -1);
+
+  int has_mt = lua_getmetatable(L, ud);
+  XBT_DEBUG("Checking the userdata: has metatable ? %d", has_mt);
+  const void* actual_mt = NULL;
+  if (has_mt) {
+    actual_mt = lua_topointer(L, -1);
+    lua_pop(L, 1);
+  }
+  XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt);
+  sglua_stack_dump("my_checkudata: ", L);
+
+  if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
+    luaL_typerror(L, ud, tname);
+  lua_pop(L, 2);
+  return p;
+}
+
 /**
  * @brief Writes the specified data into a memory buffer.
  *
 /**
  * @brief Writes the specified data into a memory buffer.
  *
index a57eebc..1633201 100644 (file)
@@ -25,6 +25,7 @@ typedef struct s_sglua_buffer {
 const char* sglua_tostring(lua_State* L, int index);
 const char* sglua_keyvalue_tostring(lua_State* L, int key_index, int value_index);
 void sglua_stack_dump(const char *msg, lua_State* L);
 const char* sglua_tostring(lua_State* L, int index);
 const char* sglua_keyvalue_tostring(lua_State* L, int key_index, int value_index);
 void sglua_stack_dump(const char *msg, lua_State* L);
+void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname);
 const char* sglua_get_spaces(int length);
 int sglua_memory_writer(lua_State* L, const void* source, size_t size, void* userdata);
 
 const char* sglua_get_spaces(int length);
 int sglua_memory_writer(lua_State* L, const void* source, size_t size, void* userdata);
 
index e919383..1cee499 100644 (file)
@@ -25,40 +25,6 @@ int luaopen_simgrid(lua_State *L);
 static void register_c_functions(lua_State *L);
 static int run_lua_code(int argc, char **argv);
 
 static void register_c_functions(lua_State *L);
 static int run_lua_code(int argc, char **argv);
 
-
-/**
- * \brief Like luaL_checkudata, with additional debug logs.
- *
- * This function is for debugging purposes only.
- *
- * \param L a lua state
- * \param ud index of the userdata to check in the stack
- * \param tname key of the metatable of this userdata in the registry
- */
-static void* my_checkudata(lua_State* L, int ud, const char* tname)
-{
-  XBT_DEBUG("Checking the userdata: ud = %d", ud);
-  sglua_stack_dump("my_checkudata: ", L);
-  void* p = lua_touserdata(L, ud);
-  lua_getfield(L, LUA_REGISTRYINDEX, tname);
-  const void* correct_mt = lua_topointer(L, -1);
-
-  int has_mt = lua_getmetatable(L, ud);
-  XBT_DEBUG("Checking the userdata: has metatable ? %d", has_mt);
-  const void* actual_mt = NULL;
-  if (has_mt) {
-    actual_mt = lua_topointer(L, -1);
-    lua_pop(L, 1);
-  }
-  XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt);
-  sglua_stack_dump("my_checkudata: ", L);
-
-  if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
-    luaL_typerror(L, ud, tname);
-  lua_pop(L, 2);
-  return p;
-}
-
 /* ********************************************************************************* */
 /*                                simgrid.task API                                   */
 /* ********************************************************************************* */
 /* ********************************************************************************* */
 /*                                simgrid.task API                                   */
 /* ********************************************************************************* */