Some cleanup for is64bit() to make it look a bit like the other os functions
This commit is contained in:
parent
b2e7af94cf
commit
3737111c68
@ -1,67 +0,0 @@
|
||||
|
||||
--
|
||||
--Windows
|
||||
--AMD64 or IA64 or x86 according to --http://msdn.microsoft.com/en-us/library/aa384274(VS.85).aspx
|
||||
--
|
||||
local function windows_is_64_bit()
|
||||
--works on 64 bit windows running a 32 bit binary
|
||||
local arch = os.getenv("PROCESSOR_ARCHITECTURE")
|
||||
if string.find(arch,'AMD64') or string.find(arch,'IA64') then
|
||||
--64 bit executable running on 64 bit windows
|
||||
return true
|
||||
else
|
||||
--if running under wow then the above returns X86, so check using this
|
||||
--function defined in host.c
|
||||
return host.windows_is_64bit_running_under_wow()
|
||||
end
|
||||
end
|
||||
|
||||
local function get_result_of_command(cmd)
|
||||
local pipe = io.popen(cmd)
|
||||
local result = pipe:read('*a')
|
||||
pipe:close()
|
||||
return result
|
||||
end
|
||||
|
||||
local function linux_is_64_bit()
|
||||
--works on 64bit Debian running a 32 bit binary
|
||||
local contents= get_result_of_command('uname -m')
|
||||
local t64 =
|
||||
{
|
||||
'x86_64'
|
||||
,'ia64'
|
||||
,'amd64'
|
||||
,'powerpc64'
|
||||
,'sparc64'
|
||||
}
|
||||
for _,v in ipairs(t64) do
|
||||
if contents:find(v) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
local function macosx_is_64_bit()
|
||||
--works on mac mini 10.6 as well as others
|
||||
local contents= get_result_of_command('echo $HOSTTYPE')
|
||||
--PPC64 is this correct?
|
||||
if string.find(contents,'x86_64') or string.find(contents,'PPC64') then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
host.is64bit = function()
|
||||
local host_os = _OS
|
||||
|
||||
if host_os == 'linux' or host_os == 'bsd' or host_os == 'solaris' or host_os == 'haiku' then
|
||||
--I assume these are correct only tested with 'linux'
|
||||
return linux_is_64_bit()
|
||||
elseif host_os == 'macosx' then
|
||||
return macosx_is_64_bit()
|
||||
elseif host_os == 'windows' then
|
||||
return windows_is_64_bit()
|
||||
else
|
||||
error('unknown host platform, please contact premake')
|
||||
end
|
||||
end
|
@ -77,7 +77,49 @@
|
||||
return (os.get():lower() == id:lower())
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Determine if the current system is running a 64-bit architecture
|
||||
--
|
||||
|
||||
local _64BitHostTypes = {
|
||||
"x86_64",
|
||||
"ia64",
|
||||
"amd64",
|
||||
"ppc64",
|
||||
"powerpc64",
|
||||
"sparc64"
|
||||
}
|
||||
|
||||
function os.is64bit()
|
||||
-- Call the native code implementation. If this returns true then
|
||||
-- we're 64-bit, otherwise do more checking locally
|
||||
if (os._is64bit()) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- Identify the system
|
||||
local arch
|
||||
if _OS == "windows" then
|
||||
arch = os.getenv("PROCESSOR_ARCHITECTURE")
|
||||
elseif _OS == "macosx" then
|
||||
arch = os.outputof("echo $HOSTTYPE")
|
||||
else
|
||||
arch = os.outputof("uname -m")
|
||||
end
|
||||
|
||||
-- Check our known 64-bit identifiers
|
||||
arch = arch:lower()
|
||||
for _, hosttype in ipairs(_64BitHostTypes) do
|
||||
if arch:find(hosttype) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- The os.matchdirs() and os.matchfiles() functions
|
||||
@ -182,6 +224,18 @@
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Run a shell command and return the output.
|
||||
--
|
||||
|
||||
function os.outputof(cmd)
|
||||
local pipe = io.popen(cmd)
|
||||
local result = pipe:read('*a')
|
||||
pipe:close()
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Remove a directory, along with any contained files or subdirectories.
|
||||
--
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* \file host.c
|
||||
* \brief Functions to query the specifics of the operating environment.
|
||||
* \author Copyright (c) 2011 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
|
||||
/**
|
||||
* Determine if we're running under 64-bit Windows.
|
||||
*/
|
||||
int windows_is_64bit_running_under_wow(struct lua_State* L)
|
||||
{
|
||||
#if PLATFORM_WINDOWS
|
||||
typedef BOOL (WINAPI * wow_func_sig)(HANDLE,PBOOL);
|
||||
|
||||
BOOL is_wow = FALSE;
|
||||
wow_func_sig func = (wow_func_sig)GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
|
||||
if (func)
|
||||
{
|
||||
if(! func(GetCurrentProcess(),&is_wow))
|
||||
luaL_error(L, "IsWow64Process returned an error");
|
||||
}
|
||||
#else
|
||||
int is_wow = 0;
|
||||
#endif
|
||||
lua_pushboolean(L, is_wow);
|
||||
return 1;
|
||||
}
|
@ -52,10 +52,9 @@ int os_getversion(lua_State* L)
|
||||
|
||||
void getversion(struct OsVersionInfo* info)
|
||||
{
|
||||
OSVERSIONINFOEX versionInfo;
|
||||
SYSTEM_INFO systemInfo;
|
||||
OSVERSIONINFOEX versionInfo = {0};
|
||||
SYSTEM_INFO systemInfo = {0};
|
||||
|
||||
ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
|
||||
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
||||
GetVersionEx((OSVERSIONINFO*)&versionInfo);
|
||||
|
||||
@ -63,7 +62,6 @@ void getversion(struct OsVersionInfo* info)
|
||||
info->minorversion = versionInfo.dwMinorVersion;
|
||||
info->revision = versionInfo.wServicePackMajor;
|
||||
|
||||
ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
|
||||
GetSystemInfo(&systemInfo);
|
||||
|
||||
if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0)
|
||||
|
30
src/host/os_is64bit.c
Executable file
30
src/host/os_is64bit.c
Executable file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* \file os_is64bit.c
|
||||
* \brief Native code-side checking for a 64-bit architecture.
|
||||
* \author Copyright (c) 2011 Jason Perkins and the Premake project
|
||||
*/
|
||||
|
||||
#include "premake.h"
|
||||
|
||||
int os_is64bit(lua_State* L)
|
||||
{
|
||||
// If this code returns true, then the platform is 64-bit. If it
|
||||
// returns false, the platform might still be 64-bit, but more
|
||||
// checking will need to be done on the Lua side of things.
|
||||
#if PLATFORM_WINDOWS
|
||||
typedef BOOL (WINAPI* WowFuncSig)(HANDLE, PBOOL);
|
||||
WowFuncSig func = (WowFuncSig)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
|
||||
if (func)
|
||||
{
|
||||
BOOL isWow = FALSE;
|
||||
if (func(GetCurrentProcess(), &isWow))
|
||||
{
|
||||
lua_pushboolean(L, isWow);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
}
|
@ -36,6 +36,7 @@ static const luaL_Reg path_functions[] = {
|
||||
static const luaL_Reg os_functions[] = {
|
||||
{ "chdir", os_chdir },
|
||||
{ "copyfile", os_copyfile },
|
||||
{ "_is64bit", os_is64bit },
|
||||
{ "isdir", os_isdir },
|
||||
{ "getcwd", os_getcwd },
|
||||
{ "getversion", os_getversion },
|
||||
@ -57,12 +58,6 @@ static const luaL_Reg string_functions[] = {
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static const luaL_Reg host_functions[] =
|
||||
{
|
||||
{ "windows_is_64bit_running_under_wow", windows_is_64bit_running_under_wow },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
@ -77,7 +72,6 @@ int main(int argc, const char** argv)
|
||||
luaL_register(L, "path", path_functions);
|
||||
luaL_register(L, "os", os_functions);
|
||||
luaL_register(L, "string", string_functions);
|
||||
luaL_register(L, "host", host_functions);
|
||||
|
||||
/* push the application metadata */
|
||||
lua_pushstring(L, LUA_COPYRIGHT);
|
||||
|
@ -56,6 +56,7 @@ int os_chdir(lua_State* L);
|
||||
int os_copyfile(lua_State* L);
|
||||
int os_getcwd(lua_State* L);
|
||||
int os_getversion(lua_State* L);
|
||||
int os_is64bit(lua_State* L);
|
||||
int os_isdir(lua_State* L);
|
||||
int os_isfile(lua_State* L);
|
||||
int os_matchdone(lua_State* L);
|
||||
@ -68,6 +69,5 @@ int os_pathsearch(lua_State* L);
|
||||
int os_rmdir(lua_State* L);
|
||||
int os_uuid(lua_State* L);
|
||||
int string_endswith(lua_State* L);
|
||||
int windows_is_64bit_running_under_wow(struct lua_State* l);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user