Skip to content

Commit

Permalink
Added MojoSetup.info.machine string (maps to "uname -m").
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 18, 2010
1 parent ce9d0a1 commit 33fef76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docs.txt
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lua_glue.c
Expand Up @@ -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();
Expand All @@ -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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion platform_unix.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions platform_windows.c
Expand Up @@ -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);
Expand Down

0 comments on commit 33fef76

Please sign in to comment.