Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use new/delete for s_xbt_cfgelm_t
[simgrid.git] / src / bindings / lua / lua_platf.cpp
index c371d70..7775b95 100644 (file)
@@ -22,7 +22,7 @@ extern "C" {
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(lua_platf, "Lua bindings (platform module)");
 
-#define PLATF_MODULE_NAME "simgrid.platf"
+#define PLATF_MODULE_NAME "simgrid.engine"
 #define AS_FIELDNAME   "__simgrid_as"
 
 /* ********************************************************************************* */
@@ -338,11 +338,10 @@ int console_add_route(lua_State *L) {
   type = lua_gettable(L,-2);
   lua_ensure(type == LUA_TSTRING,
       "Attribute 'links' must be specified for any route and must be a string (different links separated by commas or single spaces.");
-  route.link_list = new std::vector<Link*>();
   xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
   if (xbt_dynar_is_empty(names)) {
     /* unique name */
-    route.link_list->push_back(Link::byName(lua_tostring(L, -1)));
+    route.link_list.push_back(Link::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
     unsigned int cpt;
@@ -350,7 +349,7 @@ int console_add_route(lua_State *L) {
     xbt_dynar_foreach(names, cpt, name) {
       if (strlen(name)>0) {
         Link *link = Link::byName(name);
-        route.link_list->push_back(link);
+        route.link_list.push_back(link);
       }
     }
   }
@@ -414,11 +413,10 @@ int console_add_ASroute(lua_State *L) {
 
   lua_pushstring(L,"links");
   lua_gettable(L,-2);
-  ASroute.link_list = new std::vector<Link*>();
   xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n");
   if (xbt_dynar_is_empty(names)) {
     /* unique name with no comma */
-    ASroute.link_list->push_back(Link::byName(lua_tostring(L, -1)));
+    ASroute.link_list.push_back(Link::byName(lua_tostring(L, -1)));
   } else {
     // Several names separated by , \t\r\n
     unsigned int cpt;
@@ -426,7 +424,7 @@ int console_add_ASroute(lua_State *L) {
     xbt_dynar_foreach(names, cpt, name) {
       if (strlen(name)>0) {
         Link *link = Link::byName(name);
-        ASroute.link_list->push_back(link);
+        ASroute.link_list.push_back(link);
       }
     }
   }
@@ -484,9 +482,17 @@ int console_AS_open(lua_State *L) {
  s_sg_platf_AS_cbarg_t AS;
  AS.id = id;
  AS.routing = mode_int;
- sg_platf_new_AS_begin(&AS);
+ simgrid::s4u::As *new_as = sg_platf_new_AS_begin(&AS);
 
- return 0;
+ /* Build a Lua representation of the new AS on the stack */
+ lua_newtable(L);
+ simgrid::s4u::As **lua_as = (simgrid::s4u::As **) lua_newuserdata(L, sizeof(simgrid::s4u::As *)); /* table userdatum */
+ *lua_as = new_as;
+ luaL_getmetatable(L, PLATF_MODULE_NAME); /* table userdatum metatable */
+ lua_setmetatable(L, -2);                 /* table userdatum */
+ lua_setfield(L, -2, AS_FIELDNAME);       /* table -- put the userdata as field of the table */
+
+ return 1;
 }
 int console_AS_seal(lua_State *L) {
   XBT_DEBUG("Sealing AS");