- if(xbt_dynar_is_empty(host_list_d))
- host_list_d = xbt_dynar_new(sizeof(p_host_attr), &xbt_free_ref);
-
- p_host_attr host;
- const char * id;
- const char *power_trace;
- const char *state_trace;
- double power,power_scale;
- int state_initial;
- //get values from the table passed as argument
- if (lua_istable(L,-1)) {
-
- // get Id Value
- lua_pushstring(L,"id");
- lua_gettable(L, -2 );
- id = lua_tostring(L,-1);
- lua_pop(L,1);
-
- // get power value
- lua_pushstring(L,"power");
- lua_gettable(L, -2 );
- power = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- //get power_scale
- lua_pushstring(L,"power_scale");
- lua_gettable(L, -2 );
- power_scale = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- //get power_trace
- lua_pushstring(L,"power_trace");
- lua_gettable(L, -2 );
- power_trace = lua_tostring(L,-1);
- lua_pop(L,1);
-
- //get state initial
- lua_pushstring(L,"state_initial");
- lua_gettable(L, -2 );
- state_initial = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- //get trace state
- lua_pushstring(L,"state_trace");
- lua_gettable(L, -2 );
- state_trace = lua_tostring(L,-1);
- lua_pop(L,1);
-
- } else {
- ERROR0("Bad Arguments to create host, Should be a table with named arguments");
- return -1;
- }
-
- host = malloc(sizeof(host_attr));
- host->id = id;
- host->power_peak = power;
- host->power_scale = power_scale;
- host->power_trace = power_trace;
- host->state_initial = state_initial;
- host->state_trace = state_trace;
- host->function = NULL;
- xbt_dynar_push(host_list_d, &host);
-
- return 0;
-}
-
-/**
- * add link to platform links list
- */
-static int Link_new(lua_State *L) // (id,bandwidth,latency)
-{
- if(xbt_dynar_is_empty(link_list_d))
- link_list_d = xbt_dynar_new(sizeof(p_link_attr), &xbt_free_ref);
-
- const char* id;
- double bandwidth,latency;
- const char* bandwidth_trace;
- const char* latency_trace;
- const char* state_trace;
- int state_initial,policy;
-
- //get values from the table passed as argument
- if (lua_istable(L,-1)) {
- // get Id Value
- lua_pushstring(L,"id");
- lua_gettable(L, -2 );
- id = lua_tostring(L,-1);
- lua_pop(L,1);
-
- // get bandwidth value
- lua_pushstring(L,"bandwidth");
- lua_gettable(L, -2 );
- bandwidth = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- //get latency value
- lua_pushstring(L,"latency");
- lua_gettable(L, -2 );
- latency = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- /*Optional Arguments */
-
- //get bandwidth_trace value
- lua_pushstring(L,"bandwidth_trace");
- lua_gettable(L, -2 );
- bandwidth_trace = lua_tostring(L,-1);
- lua_pop(L,1);
-
- //get latency_trace value
- lua_pushstring(L,"latency_trace");
- lua_gettable(L, -2 );
- latency_trace = lua_tostring(L,-1);
- lua_pop(L,1);
-
- //get state_trace value
- lua_pushstring(L,"state_trace");
- lua_gettable(L, -2 );
- state_trace = lua_tostring(L,-1);
- lua_pop(L,1);
-
- //get state_initial value
- lua_pushstring(L,"state_initial");
- lua_gettable(L, -2 );
- state_initial = lua_tonumber(L,-1);
- lua_pop(L,1);
-
-
- //get policy value
- lua_pushstring(L,"policy");
- lua_gettable(L, -2 );
- policy = lua_tonumber(L,-1);
- lua_pop(L,1);
-
- } else {
- ERROR0("Bad Arguments to create link, Should be a table with named arguments");
- return -1;
- }
-
- p_link_attr link = malloc(sizeof(link_attr));
- link->id = id;
- link->bandwidth = bandwidth;
- link->latency = latency;
- link->bandwidth_trace = bandwidth_trace;
- link->latency_trace = latency_trace;
- link->state_trace = state_trace;
- link->state_initial= state_initial;
- link->policy = policy;
- xbt_dynar_push(link_list_d,&link);
- return 0;