From: Martin Quinson Date: Sun, 27 Mar 2016 12:10:01 +0000 (+0200) Subject: have the AS factory return the created AS X-Git-Tag: v3_13~255 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c86f2e0ead80fa2d306d5cb38201ff45f3a209c7 have the AS factory return the created AS --- diff --git a/src/bindings/lua/lua_host.cpp b/src/bindings/lua/lua_host.cpp index a67f272a95..666ede6c1a 100644 --- a/src/bindings/lua/lua_host.cpp +++ b/src/bindings/lua/lua_host.cpp @@ -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; } diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index c371d70083..4c4c123c04 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -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"); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 8cfb69d991..1932e5a89a 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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; } /** diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 79e42b7909..3d21302f1a 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -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