+ {"__gc", Task_gc},
+ {"__tostring", Task_tostring},
+ {0, 0}
+};
+
+/**
+ * Host
+ */
+static m_host_t checkHost(lua_State * L, int index)
+{
+ m_host_t *pi, ht;
+ luaL_checktype(L, index, LUA_TTABLE);
+ lua_getfield(L, index, "__simgrid_host");
+ pi = (m_host_t *) luaL_checkudata(L, -1, HOST_MODULE_NAME);
+ if (pi == NULL)
+ luaL_typerror(L, index, HOST_MODULE_NAME);
+ ht = *pi;
+ if (!ht)
+ luaL_error(L, "null Host");
+ lua_pop(L, 1);
+ return ht;
+}
+
+static int Host_get_by_name(lua_State * L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ DEBUG0("Getting Host from name...");
+ m_host_t msg_host = MSG_get_host_by_name(name);
+ if (!msg_host) {
+ luaL_error(L, "null Host : MSG_get_host_by_name failled");
+ }
+ lua_newtable(L); /* create a table, put the userdata on top of it */
+ m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t));
+ *lua_host = msg_host;
+ luaL_getmetatable(L, HOST_MODULE_NAME);
+ lua_setmetatable(L, -2);
+ lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */
+ /* remove the args from the stack */
+ lua_remove(L, 1);
+ return 1;
+}
+
+
+static int Host_get_name(lua_State * L)
+{
+ m_host_t ht = checkHost(L, -1);
+ lua_pushstring(L, MSG_host_get_name(ht));
+ return 1;
+}
+
+static int Host_number(lua_State * L)
+{
+ lua_pushnumber(L, MSG_get_host_number());
+ return 1;
+}
+
+static int Host_at(lua_State * L)
+{
+ int index = luaL_checkinteger(L, 1);
+ m_host_t host = MSG_get_host_table()[index - 1]; // lua indexing start by 1 (lua[1] <=> C[0])
+ lua_newtable(L); /* create a table, put the userdata on top of it */
+ m_host_t *lua_host = (m_host_t *) lua_newuserdata(L, sizeof(m_host_t));
+ *lua_host = host;
+ luaL_getmetatable(L, HOST_MODULE_NAME);
+ lua_setmetatable(L, -2);
+ lua_setfield(L, -2, "__simgrid_host"); /* put the userdata as field of the table */
+ return 1;
+
+}
+
+static int Host_self(lua_State * L)
+{
+ m_host_t host = MSG_host_self();
+ lua_newtable(L);
+ m_host_t *lua_host =(m_host_t *)lua_newuserdata(L,sizeof(m_host_t));
+ *lua_host = host;
+ luaL_getmetatable(L, HOST_MODULE_NAME);
+ lua_setmetatable(L, -2);
+ lua_setfield(L, -2, "__simgrid_host");
+ return 1;
+
+}
+
+static int Host_get_property_value(lua_State * L)
+{
+ m_host_t ht = checkHost(L, -2);
+ const char *prop = luaL_checkstring(L, -1);
+ lua_pushstring(L,MSG_host_get_property_value(ht,prop));
+ return 1;
+}
+
+/* ********************************************************************************* */
+/* lua_stub_generator functions */
+/* ********************************************************************************* */
+
+xbt_dict_t process_function_set;
+xbt_dynar_t process_list;
+xbt_dict_t machine_set;
+static s_process_t process;
+
+void s_process_free(void *process)
+{
+ s_process_t *p = (s_process_t *) process;
+ int i;
+ for (i = 0; i < p->argc; i++)
+ free(p->argv[i]);
+ free(p->argv);
+ free(p->host);
+}
+
+static int gras_add_process_function(lua_State * L)
+{
+ const char *arg;
+ const char *process_host = luaL_checkstring(L, 1);
+ const char *process_function = luaL_checkstring(L, 2);
+
+ if (xbt_dict_is_empty(machine_set)
+ || xbt_dict_is_empty(process_function_set)
+ || xbt_dynar_is_empty(process_list)) {
+ process_function_set = xbt_dict_new();
+ process_list = xbt_dynar_new(sizeof(s_process_t), s_process_free);
+ machine_set = xbt_dict_new();
+ }
+
+ xbt_dict_set(machine_set, process_host, NULL, NULL);
+ xbt_dict_set(process_function_set, process_function, NULL, NULL);
+
+ process.argc = 1;
+ process.argv = xbt_new(char *, 1);
+ process.argv[0] = xbt_strdup(process_function);
+ process.host = strdup(process_host);
+
+ lua_pushnil(L);
+ while (lua_next(L, 3) != 0) {
+ arg = lua_tostring(L, -1);
+ process.argc++;
+ process.argv =
+ xbt_realloc(process.argv, (process.argc) * sizeof(char *));
+ process.argv[(process.argc) - 1] = xbt_strdup(arg);
+
+ DEBUG2("index = %f , arg = %s \n", lua_tonumber(L, -2),
+ lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+ //add to the process list
+ xbt_dynar_push(process_list, &process);
+
+ return 0;
+
+}
+
+
+static int gras_generate(lua_State * L)
+{
+ const char *project_name = luaL_checkstring(L, 1);
+ generate_sim(project_name);
+ generate_rl(project_name);
+ generate_makefile_local(project_name);
+ return 0;
+}
+
+/***********************************
+ * Tracing
+ **********************************/
+static int trace_start(lua_State *L)
+{
+ TRACE_start();
+ return 1;
+}
+
+static int trace_category(lua_State * L)
+{
+ TRACE_category(luaL_checkstring(L, 1));
+ return 1;
+}
+
+static int trace_set_task_category(lua_State *L)
+{
+ TRACE_msg_set_task_category(checkTask(L, -2), luaL_checkstring(L, -1));
+ return 1;
+}
+
+static int trace_end(lua_State *L)
+{
+ TRACE_end();
+ return 1;
+}
+//***********Register Methods *******************************************//
+/*
+ * Host Methods
+ */
+static const luaL_reg Host_methods[] = {
+ {"getByName", Host_get_by_name},
+ {"name", Host_get_name},
+ {"number", Host_number},
+ {"at", Host_at},
+ {"self",Host_self},
+ {"getPropValue",Host_get_property_value},
+ // Bypass XML Methods
+ {"new", console_add_host},
+ {"setFunction", console_set_function},
+ {0, 0}
+};
+
+static int Host_gc(lua_State * L)
+{
+ m_host_t ht = checkHost(L, -1);
+ if (ht)
+ ht = NULL;
+ return 0;
+}
+
+static int Host_tostring(lua_State * L)
+{
+ lua_pushfstring(L, "Host :%p", lua_touserdata(L, 1));
+ return 1;
+}
+
+static const luaL_reg Host_meta[] = {
+ {"__gc", Host_gc},
+ {"__tostring", Host_tostring},
+ {0, 0}