diff --git a/luaa.c b/luaa.c index acfdd3b4..c647fc45 100644 --- a/luaa.c +++ b/luaa.c @@ -56,6 +56,8 @@ #include +#include /* for gethostname() */ + #ifdef WITH_DBUS extern const struct luaL_Reg awesome_dbus_lib[]; #endif @@ -255,6 +257,7 @@ luaA_fixups(lua_State *L) * startup. * @field composite_manager_running True if a composite manager is running. * @field unix_signal Table mapping between signal numbers and signal identifiers. + * @field hostname The hostname of the computer on which we are running. * @table awesome */ static int @@ -303,6 +306,17 @@ luaA_awesome_index(lua_State *L) return 1; } + if(A_STREQ(buf, "hostname")) + { + /* No good way to handle failures... */ + char hostname[256] = ""; + gethostname(&hostname[0], countof(hostname)); + hostname[countof(hostname) - 1] = '\0'; + + lua_pushstring(L, hostname); + return 1; + } + return luaA_default_index(L); } diff --git a/tests/test-spawn-snid.lua b/tests/test-spawn-snid.lua index 1bfb706a..06adc968 100644 --- a/tests/test-spawn-snid.lua +++ b/tests/test-spawn-snid.lua @@ -8,6 +8,8 @@ local manage_called, c_snid client.connect_signal("manage", function(c) manage_called = true c_snid = c.startup_id + assert(c.machine == awesome.hostname, + tostring(c.machine) .. " ~= " .. tostring(awesome.hostname)) end)