Module bex.bridge

Lua-to-VIM function bridge.

Exposes Lua functions in the v:lua table and as global Vim functions. Create a namespace for your module by indexing this module, e.g.:

local bridge = require('bex.bridge').my_module

You can then get an identifier for your function by simply indexing your namespace:

local ident = bridge[function(...) ... end]

This identifier can then be used in Vim functions, Ex commands, etc.:

-- An example, use bex.cmd for this instead
vim.cmd("autocmd mygroup FileType * call " .. ident .. "()")

To prevent registrations from growing without bound if you bridge functions dynamically, you can define a reachable method on your namespace. The method should return a function which tests whether a given identifier is in use any longer. For example, the built-in autocmd support defines it as follows:

function bridge:reachable()
    local autocmds = vim.api.nvim_exec("autocmd", true)
    return function(id)
        return string.find(autocmds, id)
    end
end

Garbage collection will be attempted every bridge.gc_interval function registrations, which defaults to 20.

Class namespace

namespace:gc () Garbage collect namespace.


Class namespace

Namespace table.

The type of table obtained by indexing this module.

namespace:gc ()
Garbage collect namespace.

Explicitly garbage collects the namespace.

generated by LDoc 1.4.6 Last updated 2021-06-29 21:08:43