mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
docs(lua): clarify assumptions on luajit vs. puc lua
Problem: Plugin authors and distribution packagers are confused about the role of LuaJIT vs. PUC Lua. Solution: Clarify that LuaJIT is preferred but not required (extensions should not be assumed but checked for) and that vanilla Lua 5.1 should be used without language extensions such as `goto`.
This commit is contained in:
@@ -28,17 +28,18 @@ You can also run Lua scripts from your shell using the |-l| argument: >
|
|||||||
nvim -l foo.lua [args...]
|
nvim -l foo.lua [args...]
|
||||||
<
|
<
|
||||||
*lua-compat*
|
*lua-compat*
|
||||||
Lua 5.1 is the permanent interface for Nvim Lua. Plugins need only consider
|
Lua 5.1 is the permanent interface for Nvim Lua. Plugins should target Lua 5.1
|
||||||
Lua 5.1, not worry about forward-compatibility with future Lua versions. If
|
as specified in |luaref|; later versions (which are essentially different,
|
||||||
Nvim ever ships with Lua 5.4+, a Lua 5.1 compatibility shim will be provided
|
incompatible, dialects) are not supported. This includes extensions such as
|
||||||
so that old plugins continue to work transparently.
|
`goto` that some Lua 5.1 interpreters like LuaJIT may support.
|
||||||
|
|
||||||
*lua-luajit*
|
*lua-luajit*
|
||||||
On supported platforms, Nvim is built with LuaJIT, which provides extra
|
While Nvim officially only requires Lua 5.1 support, it should be built with
|
||||||
functionality (compared to PUC Lua) such as "bit" and various utilities (see
|
LuaJIT or a compatible fork on supported platforms for performance reasons.
|
||||||
|lua-profile|). Lua code in |init.lua| and plugins can assume its presence on
|
LuaJIT also comes with useful extensions such as `ffi`, |lua-profile|, and
|
||||||
many platforms, but for maximum compatibility should check the `jit` global
|
enhanced standard library functions; these cannot be assumed to be available,
|
||||||
variable: >lua
|
and Lua code in |init.lua| or plugins should check the `jit` global variable
|
||||||
|
before using them: >lua
|
||||||
if jit then
|
if jit then
|
||||||
-- code for luajit
|
-- code for luajit
|
||||||
else
|
else
|
||||||
@@ -46,11 +47,12 @@ variable: >lua
|
|||||||
end
|
end
|
||||||
<
|
<
|
||||||
*lua-bit*
|
*lua-bit*
|
||||||
The LuaJIT "bit" extension module is _always_ available: when built with PUC
|
One exception is the LuaJIT `bit` extension, which is always available: when
|
||||||
Lua, Nvim includes a fallback implementation which provides `require("bit")`.
|
built with PUC Lua, Nvim includes a fallback implementation which provides
|
||||||
|
`require("bit")`.
|
||||||
|
|
||||||
*lua-profile*
|
*lua-profile*
|
||||||
To profile Lua code (with LuaJIT-enabled Nvim), the basic steps are: >lua
|
If Nvim is built with LuaJIT, Lua code can be profiled via >lua
|
||||||
-- Start a profiling session:
|
-- Start a profiling session:
|
||||||
require('jit.p').start('ri1', '/tmp/profile')
|
require('jit.p').start('ri1', '/tmp/profile')
|
||||||
|
|
||||||
@@ -59,7 +61,7 @@ To profile Lua code (with LuaJIT-enabled Nvim), the basic steps are: >lua
|
|||||||
-- Stop the session. Profile is written to /tmp/profile.
|
-- Stop the session. Profile is written to /tmp/profile.
|
||||||
require('jit.p').stop()
|
require('jit.p').stop()
|
||||||
|
|
||||||
See https://luajit.org/ext_profiler.html or the "p.lua" source for details: >
|
See https://luajit.org/ext_profiler.html or the `p.lua` source for details: >
|
||||||
:lua vim.cmd.edit(package.searchpath('jit.p', package.path))
|
:lua vim.cmd.edit(package.searchpath('jit.p', package.path))
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
Reference in New Issue
Block a user