summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/plugin.lua1
-rw-r--r--script/plugins/ffi/c-parser/c99.lua (renamed from script/LuaJIT/c-parser/c99.lua)2
-rw-r--r--script/plugins/ffi/c-parser/cdefines.lua (renamed from script/LuaJIT/c-parser/cdefines.lua)6
-rw-r--r--script/plugins/ffi/c-parser/cdriver.lua (renamed from script/LuaJIT/c-parser/cdriver.lua)8
-rw-r--r--script/plugins/ffi/c-parser/cpp.lua (renamed from script/LuaJIT/c-parser/cpp.lua)4
-rw-r--r--script/plugins/ffi/c-parser/ctypes.lua (renamed from script/LuaJIT/c-parser/ctypes.lua)2
-rw-r--r--script/plugins/ffi/c-parser/typed.lua (renamed from script/LuaJIT/c-parser/typed.lua)0
-rw-r--r--script/plugins/ffi/cdefRerence.lua (renamed from script/LuaJIT/cdefRerence.lua)0
-rw-r--r--script/plugins/ffi/init.lua (renamed from script/LuaJIT/init.lua)63
-rw-r--r--script/plugins/ffi/searchCode.lua (renamed from script/LuaJIT/searchCode.lua)0
-rw-r--r--script/plugins/init.lua1
-rw-r--r--test/ffi/builder.lua4
-rw-r--r--test/ffi/cdef.lua4
-rw-r--r--test/ffi/init.lua2
-rw-r--r--test/ffi/parser.lua4
15 files changed, 73 insertions, 28 deletions
diff --git a/script/plugin.lua b/script/plugin.lua
index 870b68b6..7afcbc0a 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -6,6 +6,7 @@ local await = require 'await'
local scope = require 'workspace.scope'
local ws = require 'workspace'
local fs = require 'bee.filesystem'
+require 'plugins'
---@class plugin
local m = {}
diff --git a/script/LuaJIT/c-parser/c99.lua b/script/plugins/ffi/c-parser/c99.lua
index 12ccee93..9735afa2 100644
--- a/script/LuaJIT/c-parser/c99.lua
+++ b/script/plugins/ffi/c-parser/c99.lua
@@ -28,7 +28,7 @@
local c99 = {}
local re = require("parser.relabel")
-local typed = require("LuaJIT.c-parser.typed")
+local typed = require("plugins.ffi.c-parser.typed")
local defs = {}
diff --git a/script/LuaJIT/c-parser/cdefines.lua b/script/plugins/ffi/c-parser/cdefines.lua
index b3a3bd24..55065f2d 100644
--- a/script/LuaJIT/c-parser/cdefines.lua
+++ b/script/plugins/ffi/c-parser/cdefines.lua
@@ -1,9 +1,9 @@
local cdefines = {}
-local c99 = require("LuaJIT.c-parser.c99")
-local cpp = require("LuaJIT.c-parser.cpp")
-local typed = require("LuaJIT.c-parser.typed")
+local c99 = require("plugins.ffi.c-parser.c99")
+local cpp = require("plugins.ffi.c-parser.cpp")
+local typed = require("plugins.ffi.c-parser.typed")
local function add_type(lst, name, typ)
lst[name] = typ
diff --git a/script/LuaJIT/c-parser/cdriver.lua b/script/plugins/ffi/c-parser/cdriver.lua
index c979f6eb..ab48d01a 100644
--- a/script/LuaJIT/c-parser/cdriver.lua
+++ b/script/plugins/ffi/c-parser/cdriver.lua
@@ -1,9 +1,9 @@
local cdriver = {}
-local cpp = require("LuaJIT.c-parser.cpp")
-local c99 = require("LuaJIT.c-parser.c99")
-local ctypes = require("LuaJIT.c-parser.ctypes")
-local cdefines = require("LuaJIT.c-parser.cdefines")
+local cpp = require("plugins.ffi.c-parser.cpp")
+local c99 = require("plugins.ffi.c-parser.c99")
+local ctypes = require("plugins.ffi.c-parser.ctypes")
+local cdefines = require("plugins.ffi.c-parser.cdefines")
function cdriver.process_file(filename)
local ctx, err = cpp.parse_file(filename)
diff --git a/script/LuaJIT/c-parser/cpp.lua b/script/plugins/ffi/c-parser/cpp.lua
index fbf1e717..f885e724 100644
--- a/script/LuaJIT/c-parser/cpp.lua
+++ b/script/plugins/ffi/c-parser/cpp.lua
@@ -1,8 +1,8 @@
local cpp = {}
-local typed = require("LuaJIT.c-parser.typed")
-local c99 = require("LuaJIT.c-parser.c99")
+local typed = require("plugins.ffi.c-parser.typed")
+local c99 = require("plugins.ffi.c-parser.c99")
local SEP = package.config:sub(1,1)
diff --git a/script/LuaJIT/c-parser/ctypes.lua b/script/plugins/ffi/c-parser/ctypes.lua
index babb2cbb..72d19ab9 100644
--- a/script/LuaJIT/c-parser/ctypes.lua
+++ b/script/plugins/ffi/c-parser/ctypes.lua
@@ -2,7 +2,7 @@ local ctypes = { TESTMODE = false }
local inspect = require("inspect")
local utility = require 'utility'
-local typed = require("LuaJIT.c-parser.typed")
+local typed = require("plugins.ffi.c-parser.typed")
local equal_declarations
diff --git a/script/LuaJIT/c-parser/typed.lua b/script/plugins/ffi/c-parser/typed.lua
index c84b87e3..c84b87e3 100644
--- a/script/LuaJIT/c-parser/typed.lua
+++ b/script/plugins/ffi/c-parser/typed.lua
diff --git a/script/LuaJIT/cdefRerence.lua b/script/plugins/ffi/cdefRerence.lua
index 819a0dd1..819a0dd1 100644
--- a/script/LuaJIT/cdefRerence.lua
+++ b/script/plugins/ffi/cdefRerence.lua
diff --git a/script/LuaJIT/init.lua b/script/plugins/ffi/init.lua
index c94295da..57a64958 100644
--- a/script/LuaJIT/init.lua
+++ b/script/plugins/ffi/init.lua
@@ -1,8 +1,14 @@
-local searchCode = require 'LuaJIT.searchCode'
-local cdefRerence = require 'LuaJIT.cdefRerence'
-local cdriver = require 'LuaJIT.c-parser.cdriver'
+local searchCode = require 'plugins.ffi.searchCode'
+local cdefRerence = require 'plugins.ffi.cdefRerence'
+local cdriver = require 'plugins.ffi.c-parser.cdriver'
local util = require 'utility'
local SDBMHash = require 'SDBMHash'
+local ws = require 'workspace'
+local files = require 'files'
+local await = require 'await'
+local config = require 'config'
+local fs = require 'bee.filesystem'
+local scope = require 'workspace.scope'
local namespace <const> = 'ffi.namespace*.'
@@ -323,9 +329,16 @@ function m.compileCodes(codes)
return lines
end
-function m.initBuilder()
- local config = require 'config'
- local fs = require 'bee.filesystem'
+local function createDir(uri)
+ local dir = scope.getScope(uri).uri or 'default'
+ local fileDir = fs.path(METAPATH) / ('%08x'):format(SDBMHash():hash(dir))
+ fs.create_directories(fileDir)
+ return fileDir
+end
+
+local builder
+function m.initBuilder(fileDir)
+ fileDir = fileDir or createDir()
---@async
return function (uri)
local refs = cdefRerence()
@@ -342,14 +355,44 @@ function m.initBuilder()
if not texts then
return
end
-
local hash = ('%08x'):format(SDBMHash():hash(uri))
local encoding = config.get(nil, 'Lua.runtime.fileEncoding')
- local filePath = METAPATH .. '/ffi/' .. table.concat({ hash, encoding }, '_')
+ local filePath = fileDir / table.concat({ hash, encoding }, '_')
- fs.create_directories(fs.path(filePath):parent_path())
- util.saveFile(filePath .. '.d.lua', table.concat(texts, '\n'))
+ util.saveFile(tostring(filePath) .. '.d.lua', table.concat(texts, '\n'))
end
end
+files.watch(function (ev, uri)
+ if ev == 'compiler' or ev == 'update' then
+ if builder then
+ await.call(function () ---@async
+ builder(uri)
+ end)
+ end
+ end
+end)
+
+ws.watch(function (ev, uri)
+ if ev == 'startReload' then
+ if config.get(uri, 'Lua.runtime.version') ~= 'LuaJIT' then
+ return
+ end
+ await.call(function () ---@async
+ ws.awaitReady(uri)
+ local fileDir = createDir(uri)
+ builder = m.initBuilder(fileDir)
+ local client = require 'client'
+ client.setConfig {
+ {
+ key = 'Lua.workspace.library',
+ action = 'add',
+ value = tostring(fileDir),
+ uri = uri,
+ }
+ }
+ end)
+ end
+end)
+
return m
diff --git a/script/LuaJIT/searchCode.lua b/script/plugins/ffi/searchCode.lua
index 9e74e7c0..9e74e7c0 100644
--- a/script/LuaJIT/searchCode.lua
+++ b/script/plugins/ffi/searchCode.lua
diff --git a/script/plugins/init.lua b/script/plugins/init.lua
new file mode 100644
index 00000000..28f902ea
--- /dev/null
+++ b/script/plugins/init.lua
@@ -0,0 +1 @@
+require 'plugins.ffi' \ No newline at end of file
diff --git a/test/ffi/builder.lua b/test/ffi/builder.lua
index 0730abcf..47e39db3 100644
--- a/test/ffi/builder.lua
+++ b/test/ffi/builder.lua
@@ -1,4 +1,4 @@
-local luajit = require 'LuaJIT'
+local ffi = require 'plugins.ffi'
local util = require 'utility'
rawset(_G, 'TEST', true)
@@ -34,7 +34,7 @@ end
function TEST(wanted)
wanted = removeEmpty(splitLines(wanted))
return function (script)
- local lines = formatLines(luajit.compileCodes({ script }))
+ local lines = formatLines(ffi.compileCodes({ script }))
assert(util.equal(wanted, lines), util.dump(lines))
end
end
diff --git a/test/ffi/cdef.lua b/test/ffi/cdef.lua
index 03c6e743..cf3992d3 100644
--- a/test/ffi/cdef.lua
+++ b/test/ffi/cdef.lua
@@ -1,7 +1,7 @@
local files = require 'files'
-local code = require 'LuaJIT.searchCode'
-local cdefRerence = require 'LuaJIT.cdefRerence'
+local code = require 'plugins.ffi.searchCode'
+local cdefRerence = require 'plugins.ffi.cdefRerence'
rawset(_G, 'TEST', true)
diff --git a/test/ffi/init.lua b/test/ffi/init.lua
index 88b50523..d632b753 100644
--- a/test/ffi/init.lua
+++ b/test/ffi/init.lua
@@ -11,7 +11,7 @@ template['Lua.runtime.version'].default = 'LuaJIT'
---@async
local function TestBuilder()
- local builder = require 'LuaJIT'.initBuilder()
+ local builder = require 'plugins.ffi'.initBuilder()
files.setText(TESTURI, [[
local ffi = require 'ffi'
ffi.cdef 'void test();'
diff --git a/test/ffi/parser.lua b/test/ffi/parser.lua
index cf55e1e0..983b64c3 100644
--- a/test/ffi/parser.lua
+++ b/test/ffi/parser.lua
@@ -1,8 +1,8 @@
local utility = require 'utility'
-local cdriver = require 'LuaJIT.c-parser.cdriver'
+local cdriver = require 'plugins.ffi.c-parser.cdriver'
rawset(_G, 'TEST', true)
-local ctypes = require 'LuaJIT.c-parser.ctypes'
+local ctypes = require 'plugins.ffi.c-parser.ctypes'
ctypes.TESTMODE = true
function TEST(wanted, full)