Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have the AS factory return the created AS
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 27 Mar 2016 12:10:01 +0000 (14:10 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 27 Mar 2016 12:10:01 +0000 (14:10 +0200)
src/bindings/lua/lua_host.cpp
src/bindings/lua/lua_platf.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp

index a67f272..666ede6 100644 (file)
@@ -57,6 +57,7 @@ sg_host_t sglua_check_host(lua_State * L, int index)
 static int l_host_get_by_name(lua_State * L)
 {
   const char *name = luaL_checkstring(L, 1);
+  lua_remove(L, 1); /* remove the args from the stack */
   XBT_DEBUG("Getting host by name...");
   sg_host_t host = sg_host_by_name(name);
   if (host == nullptr)
@@ -69,8 +70,6 @@ static int l_host_get_by_name(lua_State * L)
   lua_setmetatable(L, -2);                /* table userdatum */
   lua_setfield(L, -2, HOST_FIELDNAME);  /* table -- put the userdata as field of the table */
 
-  /* remove the args from the stack */
-  lua_remove(L, 1);
   return 1;
 }
 
index c371d70..4c4c123 100644 (file)
@@ -484,9 +484,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");
index 8cfb69d..1932e5a 100644 (file)
@@ -788,7 +788,7 @@ static void surf_config_models_setup()
  * @param AS_id name of this autonomous system. Must be unique in the platform
  * @param wanted_routing_type one of Full, Floyd, Dijkstra or similar. Full list in the variable routing_models, in src/surf/surf_routing.c
  */
-void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
+simgrid::s4u::As * sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
 {
   if (!surf_parse_models_setup_already_called) {
     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
@@ -854,6 +854,8 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
   simgrid::surf::asCreatedCallbacks(new_as);
   if (TRACE_is_enabled())
     sg_instr_AS_begin(AS);
+
+  return new_as;
 }
 
 /**
index 79e42b7..3d21302 100644 (file)
@@ -200,7 +200,7 @@ void routing_cluster_add_backbone(Link* bb);
 XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
 XBT_PUBLIC(void) sg_platf_end(void); // Finish the creation of the platform
 
-XBT_PUBLIC(void) sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS); // Begin description of new AS
+XBT_PUBLIC(simgrid::s4u::As*) sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS); // Begin description of new AS
 XBT_PUBLIC(void) sg_platf_new_AS_seal(void);                     // That AS is fully described
 
 XBT_PUBLIC(void) sg_platf_new_host   (sg_platf_host_cbarg_t   host);   // Add an host   to the currently described AS