- XBT_DEBUG("%sCopying metatable of userdata", get_spaces(indent));
- /* src: ... udata mt */
- move_value_impl(src, dst, "metatable");
- /* src: ... udata
- dst: visited ... udata mt */
+ XBT_DEBUG("%sCopying metatable of userdata (%p)", get_spaces(indent),
+ lua_topointer(src, -1));
+ /* src: ... udata mt */
+ lua_State* father = get_father(dst);
+
+ if (father != NULL) {
+ XBT_DEBUG("%sGet the metatable from my father", get_spaces(indent));
+ /* find the same metatable in the father state */
+ /* TODO find in visited_tables of src the pointer to the same
+ * metatable in the father world, then copy the metatable from the
+ * father world into dst
+ */
+ lua_pushstring(father, "simgrid.visited_tables");
+ /* father: ... "simgrid.visited_tables" */
+ lua_rawget(father, LUA_REGISTRYINDEX);
+ /* father: ... visited */
+ lua_pushlightuserdata(father, (void*) lua_topointer(src, -1));
+ /* father: ... visited pfathermt */
+ lua_gettable(father, -2);
+ /* father: ... visited mt */
+ move_value_impl(father, dst, "(father metatable)");
+ /* father: ... visited
+ dst: visited ... udata mt */
+ lua_pop(father, 1);
+ /* father: ... */
+ }
+ else {
+ XBT_DEBUG("%sI have no father", get_spaces(indent));
+ move_value_impl(src, dst, "metatable");
+ /* src: ... udata
+ dst: visited ... udata mt */
+ }