Skip to content

Commit 22bbf73

Browse files
committed
Add lua abstraction layer
1 parent 3023d8f commit 22bbf73

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lua/acid/init.lua

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- luacheck: globals unpack vim
2+
local nvim = vim.api
3+
4+
local indirection = {}
5+
local acid = {}
6+
7+
acid.send = function(obj, handler)
8+
local session = math.random(10000, 99999)
9+
10+
indirection[session] = handler
11+
12+
nvim.nvim_call_function("AcidSendNrepl", {
13+
obj,
14+
"LuaFn",
15+
"require('acid').callback(" .. session .. ", _A)"
16+
})
17+
end
18+
19+
acid.callback = function(session, ret)
20+
return indirection[session](ret)
21+
end
22+
23+
return acid
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from acid.handlers import BaseHandler
2+
from acid.nvim.log import error
3+
4+
5+
class Handler(BaseHandler):
6+
7+
name = "LuaFn"
8+
priority = 0
9+
10+
def on_init(self):
11+
self.lua_fn = ""
12+
13+
def configure(self, lua_fn, *args, **kwargs):
14+
super().configure(*args, **kwargs)
15+
self.lua_fn = lua_fn
16+
return self
17+
18+
def on_handle(self, msg, *_):
19+
self.nvim.funcs.luaeval(self.lua_fn, msg)

0 commit comments

Comments
 (0)