XBT_DEBUG("Getting Host from name...");
msg_host_t msg_host = MSG_host_by_name(name);
if (!msg_host) {
- luaL_error(L, "null Host : MSG_get_host_by_name failed");
+ XBT_ERROR("MSG_get_host_by_name failed, requested hostname: %s", name);
}
lua_newtable(L); /* create a table, put the userdata on top of it */
msg_host_t *lua_host = (msg_host_t *) lua_newuserdata(L, sizeof(msg_host_t));
static int l_host_number(lua_State * L)
{
xbt_dynar_t hosts = MSG_hosts_as_dynar();
- lua_pushnumber(L, xbt_dynar_length(hosts));
+ lua_pushinteger(L, xbt_dynar_length(hosts));
xbt_dynar_free(&hosts);
return 1;
}
return 1;
}
-/**
- * \brief Returns the host where the current process is located.
- * \param L a Lua state
- * \return number of values returned to Lua
- *
- * - Return value (host): the current host
- */
-static int l_host_self(lua_State * L)
-{
- /* -- */
- msg_host_t host = MSG_host_self();
- lua_newtable(L);
- /* table */
- msg_host_t* lua_host = (msg_host_t*) lua_newuserdata(L, sizeof(msg_host_t));
- /* table ud */
- *lua_host = host;
- luaL_getmetatable(L, HOST_MODULE_NAME);
- /* table ud mt */
- lua_setmetatable(L, -2);
- /* table ud */
- lua_setfield(L, -2, "__simgrid_host");
- /* table */
- return 1;
-}
-
/**
* \brief Returns the value of a host property.
* \param L a Lua state
return 1;
}
-/**
- * \brief Makes the current process sleep for a while.
- * \param L a Lua state
- * \return number of values returned to Lua
- *
- * - Argument 1 (number): duration of the sleep
- */
-static int l_host_sleep(lua_State *L)
-{
- int time = luaL_checknumber(L, 1);
- MSG_process_sleep(time);
- return 0;
-}
-
/**
* \brief Destroys a host.
* \param L a Lua state
{"name", l_host_get_name},
{"number", l_host_number},
{"at", l_host_at},
- {"self", l_host_self},
{"get_prop_value", l_host_get_property_value},
- {"sleep", l_host_sleep},
{"destroy", l_host_destroy},
// Bypass XML Methods
- {"set_function", console_set_function},
{"set_property", console_host_set_property},
{NULL, NULL}
};
lua_getglobal(L, "simgrid"); /* simgrid */
luaL_newlib(L, host_functions); /* simgrid simgrid.host */
lua_setfield(L, -2, "host"); /* simgrid */
+ lua_getfield(L, -1, "host"); /* simgrid simgrid.host */
/* create the metatable for host, add it to the Lua registry */
- luaL_newmetatable(L, HOST_MODULE_NAME); /* simgrid mt */
+ luaL_newmetatable(L, HOST_MODULE_NAME); /* simgrid simgrid.host mt */
/* fill the metatable */
- luaL_setfuncs(L, host_meta, 0); /* simgrid mt */
+ luaL_setfuncs(L, host_meta, 0); /* simgrid simgrid.host mt */
/**
* Copy the table and push it onto the stack.
* Required for the lua_setfield call below.
*/
- lua_getfield(L, -2, "host"); /* simgrid mt simgrid.host */
+ lua_getfield(L, -3, "host"); /* simgrid simgrid.host mt simgrid.host */
/* metatable.__index = simgrid.host
* we put the host functions inside the host userdata itself:
* this allows to write my_host:method(args) for
* simgrid.host.method(my_host, args) */
- lua_setfield(L, -2, "__index"); /* simgrid mt */
+ lua_setfield(L, -2, "__index"); /* simgrid simgrid.host mt */
- lua_setmetatable(L, -2); /* simgrid */
- lua_pop(L, 1);
+ lua_setmetatable(L, -2); /* simgrid simgrid.host */
+ lua_pop(L, 2); /* -- */
}