+/**
+ * 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 const luaL_reg Host_methods[] = {
+ {"getByName", Host_get_by_name},
+ {"name", Host_get_name},
+ {"number", Host_number},
+ {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}
+};
+