Added MojoSetup.info.machine string (maps to "uname -m").
authorRyan C. Gordon <icculus@icculus.org>
Sat, 18 Dec 2010 03:20:53 -0500
changeset 803 45de4213b858
parent 802 c18c8fc916dd
child 804 1f3629906694
Added MojoSetup.info.machine string (maps to "uname -m").
docs.txt
lua_glue.c
platform_unix.c
platform_windows.c
--- a/docs.txt	Fri Dec 17 20:43:41 2010 -0500
+++ b/docs.txt	Sat Dec 18 03:20:53 2010 -0500
@@ -1280,6 +1280,21 @@
 
     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
--- a/lua_glue.c	Fri Dec 17 20:43:41 2010 -0500
+++ b/lua_glue.c	Sat Dec 18 03:20:53 2010 -0500
@@ -1733,6 +1733,7 @@
     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 @@
     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 @@
             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 @@
         lua_setfield(luaState, -2, "archive");
     lua_setglobal(luaState, MOJOSETUP_NAMESPACE);
 
+    free(osmachine);
     free(osversion);
     free(ostype);
     free(locale);
--- a/platform_unix.c	Fri Dec 17 20:43:41 2010 -0500
+++ b/platform_unix.c	Sat Dec 18 03:20:53 2010 -0500
@@ -466,7 +466,7 @@
 } // MojoPlatform_ostype
 
 
-char *MojoPlatform_osVersion()
+char *MojoPlatform_osVersion(void)
 {
 #if PLATFORM_MACOSX
     SInt32 ver, major, minor, patch;
@@ -520,6 +520,15 @@
 } // 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);
--- a/platform_windows.c	Fri Dec 17 20:43:41 2010 -0500
+++ b/platform_windows.c	Sat Dec 18 03:20:53 2010 -0500
@@ -884,6 +884,13 @@
 } // 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);