From 33fef76710ca914f046c742c9eba46bda5485558 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 18 Dec 2010 03:20:53 -0500 Subject: [PATCH] Added MojoSetup.info.machine string (maps to "uname -m"). --- docs.txt | 15 +++++++++++++++ lua_glue.c | 4 ++++ platform_unix.c | 11 ++++++++++- platform_windows.c | 7 +++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs.txt b/docs.txt index a74964c..7dbf872 100644 --- a/docs.txt +++ b/docs.txt @@ -1280,6 +1280,21 @@ Your config file is a Lua script, and as such, has access to all of Lua's Please note that this is the arch of the installer binary...you can run a 32-bit binary on an amd64 chip, in which case it will report "x86"! + You may have better luck with MojoSetup.info.machine. Maybe. + + + MojoSetup.info.machine + + This is a string (not a function!) of the current platform's machine type. + This string is arbitrary and platform specific, so it's only useful if + you know what you're looking for on a specific subset of your target + audience. + + For Unix-like systems, this string is the output of "uname -m". + + Please note that modern Intel Mac OS X systems can run 64-bit binaries + but may report themselves as "i386" here, for example, and also + seemlessly run PowerPC apps in an emulator. MojoSetup.info.ostype diff --git a/lua_glue.c b/lua_glue.c index 5eecc74..f8c4938 100644 --- a/lua_glue.c +++ b/lua_glue.c @@ -1733,6 +1733,7 @@ boolean MojoLua_initLua(void) char *locale = (envr != NULL) ? xstrdup(envr) : MojoPlatform_locale(); char *ostype = MojoPlatform_osType(); char *osversion = MojoPlatform_osVersion(); + char *osmachine = MojoPlatform_osMachine(); lua_Integer uid = (lua_Integer) MojoPlatform_getuid(); lua_Integer euid = (lua_Integer) MojoPlatform_geteuid(); lua_Integer gid = (lua_Integer) MojoPlatform_getgid(); @@ -1746,6 +1747,7 @@ boolean MojoLua_initLua(void) if (locale == NULL) locale = xstrdup("???"); if (ostype == NULL) ostype = xstrdup("???"); if (osversion == NULL) osversion = xstrdup("???"); + if (osmachine == NULL) osmachine = xstrdup("???"); assert(luaState == NULL); luaState = lua_newstate(MojoLua_alloc, NULL); // calls fatal() on failure. @@ -1796,6 +1798,7 @@ boolean MojoLua_initLua(void) set_string(luaState, locale, "locale"); set_string(luaState, PLATFORM_NAME, "platform"); set_string(luaState, PLATFORM_ARCH, "arch"); + set_string(luaState, osmachine, "machine"); set_string(luaState, ostype, "ostype"); set_string(luaState, osversion, "osversion"); set_string(luaState, GGui->name(), "ui"); @@ -1869,6 +1872,7 @@ boolean MojoLua_initLua(void) lua_setfield(luaState, -2, "archive"); lua_setglobal(luaState, MOJOSETUP_NAMESPACE); + free(osmachine); free(osversion); free(ostype); free(locale); diff --git a/platform_unix.c b/platform_unix.c index 0f3ec0b..c6e4d85 100644 --- a/platform_unix.c +++ b/platform_unix.c @@ -466,7 +466,7 @@ char *MojoPlatform_osType(void) } // MojoPlatform_ostype -char *MojoPlatform_osVersion() +char *MojoPlatform_osVersion(void) { #if PLATFORM_MACOSX SInt32 ver, major, minor, patch; @@ -520,6 +520,15 @@ char *MojoPlatform_osVersion() } // MojoPlatform_osversion +char *MojoPlatform_osMachine(void) +{ + struct utsname un; + if (uname(&un) == 0) + return xstrdup(un.machine); + return NULL; +} // MojoPlatform_osMachine + + void MojoPlatform_sleep(uint32 ticks) { usleep(ticks * 1000); diff --git a/platform_windows.c b/platform_windows.c index 7bd39ea..8fa5467 100644 --- a/platform_windows.c +++ b/platform_windows.c @@ -884,6 +884,13 @@ char *MojoPlatform_osVersion(void) } // MojoPlatform_osversion +char *MojoPlatform_osMachine(void) +{ + // !!! FIXME: return "x86" for win32 and "x64" (bleh!) for win64. + return NULL; +} // MojoPlatform_osMachine + + void MojoPlatform_sleep(uint32 ticks) { Sleep(ticks);