Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have the AS factory return the created AS
[simgrid.git] / src / bindings / lua / lua_host.cpp
index 804b672..666ede6 100644 (file)
@@ -7,10 +7,12 @@
 /* SimGrid Lua bindings                                                     */
 
 #include "lua_private.h"
-#include <lauxlib.h>
 #include <simgrid/host.h>
+extern "C" {
+#include <lauxlib.h>
+}
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_host, bindings, "Lua bindings (host module)");
+XBT_LOG_NEW_DEFAULT_CATEGORY(lua_host, "Lua bindings (host module)");
 
 #define HOST_MODULE_NAME "simgrid.host"
 #define HOST_FIELDNAME   "__simgrid_host"
@@ -55,21 +57,19 @@ 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) {
+  if (host == nullptr)
     XBT_ERROR("sg_get_host_by_name failed, requested hostname: %s", name);
-  }
+
   lua_newtable(L);                        /* table */
-  sg_host_t *lua_host = (sg_host_t *) lua_newuserdata(L, sizeof(sg_host_t));
-                                          /* table userdatum */
+  sg_host_t *lua_host = (sg_host_t *) lua_newuserdata(L, sizeof(sg_host_t)); /* table userdatum */
   *lua_host = host;
   luaL_getmetatable(L, HOST_MODULE_NAME); /* table userdatum metatable */
   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;
 }