问题
I am currently using Windows
on my default development system and Linux
on my server where I deploy my Lua scripts. For Windows
there are only several 32 bit interpreters like Lua for Windows one I currently use (at least as far as i know). On the server the interpreter is running the scripts on 64 bits.
Now my question is: Is it possible to check on which architecture the script is running (probably similar to the _ENV
variable for the version)?
If there is any 64 bit Windows Lua interpreter feel free to leave a comment on this matter. Thank you in advance.
回答1:
If you can get the executable that runs the script, you can probably look at its header on Windows and Linux to check if it's 32bit or 64bit application; here are suggestions on how to do it on Windows.
I'm also interested in simpler ways to do it from a Lua script (and the one that works with Lua and LuaJIT interpreters), as I ran into a case when I'd like to reference different paths depending on whether 32bit or 64bit library needs to be loaded without the user having to specify those paths.
回答2:
This is how to determine your OS bitness, not your compiler bitness (you can run 32-bit Lua.exe on Windows 64-bit).
local arch
if (os.getenv"os" or ""):match"^Windows" then
print"Your system is Windows"
arch = os.getenv"PROCESSOR_ARCHITECTURE"
else
print"Your system is Linux"
arch = io.popen"uname -m":read"*a"
end
if (arch or ""):match"64" then
print"Your system is 64-bit"
else
print"Your system is 32-bit"
end
回答3:
Why would you need that knowledge?
Normally there's nothing you can do on Lua side that would depend on underlying host architecture. To perform something specific to the host, you would need to write some native code, but then you will know the architecture you will be compiling for.
There's one possible way though (maybe there's more). You can compile dummy function with string.dump()
and analyze bytecode header. The header is different between Lua versions, so you should check the version first to know location of "system parameters" field. If Lua interpreter wasn't altered, then the field that stores size_t
size in bytes would be different for 32- and 64-bit host.
来源:https://stackoverflow.com/questions/48093429/determine-whether-lua-compiler-runs-32-or-64-bit