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

Post Reply
Sap123
Posts: 2
Joined: Wed Jun 22, 2022 6:42 am

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

Post 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!

User avatar
demonnic
Posts: 884
Joined: Sat Dec 05, 2009 3:19 pm

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

Post 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.

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

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

Post 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.

Sap123
Posts: 2
Joined: Wed Jun 22, 2022 6:42 am

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

Post by Sap123 »

Brilliant thanks - this works perfectly!

Post Reply