Page 1 of 1

Is there a Lua function to identify which computer I'm using?

Posted: Wed Jun 22, 2022 6:51 am
by Sap123
Is there a Lua function to identify which computer I'm using?

getOs() is the closest I've found. It returns "mac" for both computers.

Use case: I have a 27" Mac and a 13" Macbook Air. I'd like my window layout scripts to check which computer (or maximum possible screen resolution?) they are working with and layout the window differently depending on that.


Long time lurker, first time poster. Love this client :)

Thanks!

Re: Is there a Lua function to identify which computer I'm using?

Posted: Wed Jun 22, 2022 1:31 pm
by demonnic
Taken and modified slightly from https://gist.github.com/h1k3r/089d43771bdf811eefe8 to assume instead that 'hostname' is in the path
Code: [show] | [select all] lua
function getHostname()
    local f = io.popen ("hostname")
    local hostname = f:read("*a") or ""
    f:close()
    hostname =string.gsub(hostname, "\n$", "")
    return hostname
end

On windows this will very briefly pop up a command window, but on MacOS it shouldn't do that.

That being said, you could skip over all that and just check Mudlet's window size using getMainWindowSize and adjust accordingly. Unless they're the same resolution, in which case yeah, go with the hostname option.

Re: Is there a Lua function to identify which computer I'm using?

Posted: Wed Jun 22, 2022 3:03 pm
by Jor'Mox
If that doesn't work how you want, you could always just make a tiny text file for each computer, and then read the contents.

Re: Is there a Lua function to identify which computer I'm using?

Posted: Wed Jun 22, 2022 3:08 pm
by Sap123
Brilliant thanks - this works perfectly!