Manual of LuaFAR 3
Brief description of LuaFAR package
This package’s purpose is to facilitate writing plugins for FAR in Lua programming language. The package provides source code for luafar3.dll
(main product) and a luaplug.dll
(“generic” plugin).
luafar3.dll
allows:
To program functions exported by the plugin in Lua: e.g., the function
OpenW
should be namedexport.Open
in the Lua program, the same goes for all functions exported by the plugin.To call FAR service functions from a Lua program. The service functions are placed in the
far
,editor
,viewer
,panel
andregex
tables, and their names aren’t identical to the names of the respective FAR API functions. For instance, functionEditorControl
with parameterECTL_GETINFO
will be namededitor.GetInfo
in Lua programs.Note: the functions of the Unicode LuaFAR library assume string arguments and string return values to be in the UTF-8 encoding. (There are a few exceptions from this rule, mostly when strings are used to exchange binary data).
Currently, the documentation on LuaFAR API is incomplete and may be somewhat inaccurate. When in doubt, consult the source code. The API may change in the future.
As luafar3.dll
itself is not a plugin, it should not be placed in the %FARHOME%\Plugins
subtree (instead, place it in any directory listed in PATH
). The usual way of using luafar3.dll
is to create a wrapper plugin that redirects FAR’s calls of the exported functions to luafar3.dll
, that in turn calls the functions written in Lua. This way, one instance of luafar3.dll
can “serve” arbitrary number of plugins at the same time. An example of “wrapper plugin” is luaplug.dll
(its source code is part of this package).
There are two Lua files that must be present in plugin’s DLL directory:
_globalinfo.lua
(it should only contain the functionexport.GetGlobalInfo
).
This script must not call functions fromfar
library (e.g.,far.Message
), as they are not yet available to LuaFAR when Far callsGetGlobalInfoW
.The starting (or “default”) Lua script, that is searched in the following order (see
LF_RunDefaultScript
for details):- The plugin name with the extension
.lua
is looked for, e.g.:luaplug.dll -> luaplug.lua
- If the plugin name contains a hyphen, then its part preceding the last
hyphen is looked for, e.g.:
luaplug-x64.dll -> luaplug.lua
.
- The plugin name with the extension
When the starting script is run it receives one boolean argument:
true
– on its first run and after Lua state was recreatedfalse
– on subsequent runs caused by settingfar.ReloadDefaultScript
=
true
.