⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 luajit_install.html

📁 lua的即时编译器。支持lua 5.1.2版本
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Installing LuaJIT</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta name="Author" content="Mike Pall"><meta name="Copyright" content="Copyright (C) 2005-2007, Mike Pall"><meta name="Language" content="en"><link rel="stylesheet" type="text/css" href="bluequad.css" media="screen"><link rel="stylesheet" type="text/css" href="bluequad-print.css" media="print"><style type="text/css">table.build {  line-height: 1.2;}td.buildsys {  width: 10em;}td.buildcmd {  width: 10em;  font-family: Courier New, Courier, monospace;}tr.buildhead td {  font-family: inherit;  font-weight: bold;}</style></head><body><div id="site"><a href="http://luajit.org/"><span>Lua<span id="logo">JIT</span></span></a></div><div id="head"><h1>Installing LuaJIT</h1></div><div id="nav"><ul><li><a href="index.html">Index</a></li><li><a href="luajit.html">LuaJIT</a><ul><li><a href="luajit_features.html">Features</a></li><li><a class="current" href="luajit_install.html">Installation</a></li><li><a href="luajit_run.html">Running</a></li><li><a href="luajit_api.html">API Extensions</a></li><li><a href="luajit_intro.html">Introduction</a></li><li><a href="luajit_performance.html">Performance</a></li><li><a href="luajit_debug.html">Debugging</a></li><li><a href="luajit_changes.html">Changes</a></li></ul></li><li><a href="coco.html">Coco</a><ul><li><a href="coco_portability.html">Portability</a></li><li><a href="coco_api.html">API Extensions</a></li><li><a href="coco_changes.html">Changes</a></li></ul></li><li><a href="dynasm.html">DynASM</a><ul><li><a href="dynasm_features.html">Features</a></li><li><a href="dynasm_examples.html">Examples</a></li></ul></li><li><a href="http://luajit.org/download.html">Download <span class="ext">&raquo;</span></a></li></ul></div><div id="main"><p>LuaJIT is not much more difficult to install than Lua itself.Just unpack the distribution file, change into the newly createddirectory and follow the instructions below.</p><p class="indent">For the impatient: <b><tt>make&nbsp;linux&nbsp;&amp;&amp;&nbsp;sudo&nbsp;make&nbsp;install</tt></b><br>Replace <tt>linux</tt> with e.g. <tt>bsd</tt> or <tt>macosx</tt> depending on your OS.</p><p>In case you've missed this in <a href="luajit_features.html">Features</a>:LuaJIT only works on x86 (i386+) systems right now. Support forother architectures may be added in future versions.</p><h2>Configuring LuaJIT</h2><p>LuaJIT is (deliberately) <em>not</em> autoconfigured &mdash; thedefaults should work fine on most systems. But please check thesystem-specific instructions below.</p><p>The following three files hold all configuration information:</p><ul><li><tt>Makefile</tt> holds settings for installing LuaJIT.</li><li><tt>src/Makefile</tt> holds settings for compiling LuaJIT.</li><li><tt>src/luaconf.h</tt> sets a multitude of configurationvariables.</li></ul><p>If this is your first build then it's better not to give intothe temptation to tweak every little setting. The standardconfiguration provides sensible defaults (IMHO).</p><p>One particular setting you might want to change is the installationpath. Note that you need to modify both the top-level <tt>Makefile</tt>and <tt>src/luaconf.h</tt> (right at the start) to takeeffect.</p><p>If you have trouble getting Coco to work, you can disable it byuncommenting the <tt>COCOFLAGS= -DCOCO_DISABLE</tt> line in<tt>src/Makefile</tt>. But note that this effectively disablesyielding from coroutines for JIT compiled functions.</p><p>A few more settings need to be changed if you want to<a href="luajit_debug.html">Debug LuaJIT</a> <em>itself</em>.Application debugging can be turned on/off at runtime.</p><h3>Upgrading From Previous Versions</h3><p>It's important to keep the LuaJIT core and the add-on modules in sync.Be sure to delete any old versions of LuaJIT modules from theLua module search path (check the current directory, too!).</p><p>Lua files compiled to bytecode may be incompatible if the underlyingLua core has changed (like from Lua&nbsp;5.1 alpha to Lua&nbsp;5.1final between LuaJIT&nbsp;1.0.3 and LuaJIT&nbsp;1.1.0). The sameapplies to any<a href="http://lua-users.org/wiki/BuildingModules"><span class="ext">&raquo;</span>&nbsp;loadable C modules</a>(shared libraries, DLLs) which need to be recompiled with the newLua header files.</p><p>Compiled bytecode and loadable C modules are fully compatible andcan be freely exchanged between LuaJIT and the <em>same</em>version of Lua it is based on. Please verify that <tt>LUA_RELEASE</tt>in <tt>src/lua.h</tt> is the same in both distributions.</p><h2>Building LuaJIT</h2><h3>Makefile Targets</h3><p>The Makefiles have a number of targets for various operating systems:</p><table class="build"><tr class="buildhead"><td class="buildsys">System</td><td class="buildcmd">Build Command</td><td>Notes</td></tr><tr class="odd"><td>Linux i386</td><td class="buildcmd">make linux</td><td></td></tr><tr class="even"><td>BSD i386</td><td class="buildcmd">make bsd</td><td>FreeBSD, NetBSD or OpenBSD</td></tr><tr class="odd"><td>Mac OS X on Intel</td><td class="buildcmd">make macosx</td><td></td></tr><tr class="even"><td>Solaris x86</td><td class="buildcmd">make solaris</td><td>GCC only, SunCC miscompiles LuaJIT</td></tr><tr class="odd"><td>MinGW (Win32)</td><td class="buildcmd">make mingw</td><td>cross-MinGW: must be 1st in PATH</td></tr><tr class="even"><td>Cygwin</td><td class="buildcmd">make cygwin</td><td></td></tr><tr class="odd"><td>POSIX on x86</td><td class="buildcmd">make posix</td><td>Check <a href="coco_portability.html">Portability Req. for Coco</a>, too</td></tr><tr class="even"><td>Generic x86</td><td class="buildcmd">make generic</td><td>Check <a href="coco_portability.html">Portability Req. for Coco</a>, too</td></tr></table><p>You may want to enable interactive line editing for the stand-aloneexecutable. There are extra targets for Linux, BSD and Mac OS X:<tt>make&nbsp;linux_rl</tt>, <tt>make&nbsp;bsd_rl</tt>and <tt>make&nbsp;macosx_rl</tt>.</p><h3>MSVC (Win32)</h3><p>First check out <tt>etc\luavs.bat</tt> if it suits your needs. Then tryrunning it from the MSVC command prompt (start it from the toplevel directory).</p><p>Another option is to set up your own MSVC project:</p><p>Change to the <tt>src</tt> directoryand create a new DLL project for <tt>lua51.dll</tt>.Add all C files to it except for <tt>lua.c</tt>, <tt>luac.c</tt>and <tt>print.c</tt>. Add the <tt>..\dynasm</tt> directoryto the include path and build the DLL.</p><p>Next create a new EXE project for <tt>luajit.exe</tt>.Add <tt>lua.c</tt> to it and link with the import library<tt>lua51.lib</tt> created for <tt>lua51.dll</tt>. Buildthe executable.</p><h2>Installation</h2><h3>POSIX systems</h3><p>Run <tt>make&nbsp;install</tt> from the top-level directory.You probably need to be the root user before doing so, i.e. use<tt>sudo&nbsp;make&nbsp;install</tt> or <tt>su&nbsp;-&nbsp;root</tt>before the <tt>make&nbsp;install</tt>.</p><p>By default this installs only:<br><tt>&nbsp;&nbsp;/usr/local/bin/<strong>luajit</strong></tt> &mdash; The stand-alone executable.<br><tt>&nbsp;&nbsp;/usr/local/lib/lua/5.1</tt> &mdash; C module directory.<br><tt>&nbsp;&nbsp;/usr/local/share/lua/5.1</tt> &mdash; Lua module directory.<br><tt>&nbsp;&nbsp;/usr/local/share/lua/5.1/<strong>jit/*.lua</strong></tt> &mdash;<tt>jit.*</tt> modules.<br></p><p>The Lua docs and includes are not installed to avoid overwritingan existing Lua installation. In any case these are identicalto the version of Lua that LuaJIT is based on. If you wantto install them, edit the top-level makefile (look for <tt>###</tt>).</p><p>The stand-alone Lua bytecode compiler <tt>luac</tt> is neitherbuilt nor installed, for the same reason. If you really need it,you may be better off with <tt>luac</tt> built from the original Luadistribution (use the <em>same</em> version your copy of LuaJITis based on). This avoids dragging in most of LuaJIT which is notneeded for the pure bytecode compiler. You can also use the bare-bonesLua to bytecode translator <tt>luac.lua</tt> (look in the <tt>test</tt>directory of the original Lua distribution).</p><h3>Windows</h3><p>Copy <tt>luajit.exe</tt> and <tt>lua51.dll</tt>to a newly created directory (any location is ok). Add <tt>lua</tt>and <tt>lua\jit</tt> directories below it and copy all Lua filesfrom the <tt>jit</tt> directory of the distribution to the latter directory.</p><p>There are no hardcodedabsolute path names &mdash; all modules are loaded relative to thedirectory where <tt>luajit.exe</tt> is installed(see <tt>src/luaconf.h</tt>).</p><h2 id="embedding">Embedding LuaJIT</h2><p>It's strongly recommended that you build the stand-alone executablewith your toolchain and verify that it works <em>before</em> startingto embed LuaJIT into an application. The stand-alone executable isalso useful later on, when you want to experiment with code snippetsor try out some Lua files.</p><p>Please consult the Lua docs for general information about how toembed Lua into your application. The following list only showsthe additional steps needed for embedding LuaJIT:</p><ul><li>You need to add the LuaJIT library functions by running<tt>luaopen_jit()</tt> after all the other standard library functions.The modified <tt>src/linit.c</tt> used by the stand-alone executablealready does this for you.</li><li><em>Caveat:</em> LuaJIT is based on Lua 5.1 whichmeans the <tt>luaopen_*()</tt> functions <em>must not</em>be called directly. See <tt>src/linit.c</tt> for the proper way torun them. You'll get an error initializing the <tt>io</tt> libraryif you don't follow these instructions.</li><li>To use the optimizer (strongly recommended) you need to:<ul><li>Install the optimizer modules <tt>jit.opt</tt> and<tt>jit.opt_inline</tt> relative to the Lua module path(you've probably modified it &mdash; see <tt>src/luaconf.h</tt>):<br><tt>jit/opt.lua</tt><br><tt>jit/opt_inline.lua</tt></li><li>If you want to ship a single executable then you may want toembed the optimizer modules into your application (but don't loosetime with this during the early development phase). This involves:<ul><li>Compile the two modules to bytecode(using <tt>luac&nbsp;-s</tt> from a plain Lua installation).</li><li>Convert them to C include files (search for "Lua&nbsp;bin2c").</li><li>On Windows you can also put the compiled bytecode into a resource(search for "Lua&nbsp;bin2res").</li><li>Load the bytecode with <tt>luaL_loadbuffer</tt> (but don't run it).</li><li>Put the resulting functions into <tt>package.preload["jit.opt"]</tt>and <tt>package.preload["jit.opt_inline"]</tt>.</li></ul></li><li>Activate the LuaJIT optimizer from Lua code to be run at startup:<tt>&nbsp;&nbsp;require("jit.opt").start()</tt><br>Or use equivalent C code. See <tt>dojitopt()</tt> in <tt>src/lua.c</tt>.</li></ul></li><li>All other LuaJIT specific modules (<tt>jit.*</tt>) are for debugging only.They do not need to be shipped with an application. But they may be quiteuseful, anyway (especially <tt>jit.trace</tt>).</li><li>DynASM is only needed while <em>building</em> LuaJIT. It's notneeded while running LuaJIT and there is no point in shipping orinstalling it together with an application.</li><li>In case you want to strip some of the standard libraries fromyour application: The optimizer modules need several functions fromthe base library and the string library (and of course the LuaJITcore libraries). The io library is only used to print a fatal errormessage (you may want to replace it). The optional modulesfor debugging depend on a few more library functions &mdash;please check the source.</li></ul><p>Although the very liberal LuaJIT<a href="http://www.opensource.org/licenses/mit-license.php"><span class="ext">&raquo;</span>&nbsp;license</a>does not require any acknowledgment whatsoever, it would be appreciatedif you give some credit in the docs (or the "About" box) of your application.A simple line like:<br><tt>&nbsp;&nbsp;This product includes LuaJIT, http://luajit.org/</tt><br>would be nice. Please do not include any E-Mail addresses. Thank you!</p><p>I'm always interested where LuaJIT can be put to good use in applications.Please <a href="contact.html">tell me</a>or better yet write a few lines about your project to the<a href="http://www.lua.org/lua-l.html"><span class="ext">&raquo;</span>&nbsp;Lua mailing list</a>.Thank you!</p><br class="flush"></div><div id="foot"><hr class="hide">Copyright &copy; 2005-2007 Mike Pall<span class="noprint">&middot;<a href="contact.html">Contact</a></span></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -