Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions locale/en-us/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,5 @@ command.exportDocument =
'Lua: Export Document ...'
command.addon_manager.open =
'Lua: Open Addon Manager ...'
command.reloadFFIMeta =
'Lua: Reload luajit ffi meta'
2 changes: 2 additions & 0 deletions locale/pt-br/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,5 @@ command.exportDocument = -- TODO: need translate!
'Lua: Export Document ...'
command.addon_manager.open = -- TODO: need translate!
'Lua: Open Addon Manager ...'
command.reloadFFIMeta = -- TODO: need translate!
'Lua: Reload luajit ffi meta'
2 changes: 2 additions & 0 deletions locale/zh-cn/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,5 @@ command.exportDocument =
'Lua: 导出文档...'
command.addon_manager.open =
'Lua: 打开插件管理器...'
command.reloadFFIMeta =
'Lua: 重新生成luajit的FFI模块C语言元数据'
2 changes: 2 additions & 0 deletions locale/zh-tw/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,5 @@ command.exportDocument = -- TODO: need translate!
'Lua: Export Document ...'
command.addon_manager.open = -- TODO: need translate!
'Lua: Open Addon Manager ...'
command.reloadFFIMeta = -- TODO: need translate!
'Lua: Reload luajit ffi meta'
16 changes: 9 additions & 7 deletions script/plugins/ffi/init.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
local searchCode = require 'plugins.ffi.searchCode'
local cdefRerence = require 'plugins.ffi.cdefRerence'
local cdriver = require 'plugins.ffi.c-parser.cdriver'
local util = require 'plugins.ffi.c-parser.util'
local utility = require 'utility'
local SDBMHash = require 'SDBMHash'
local config = require 'config'
local fs = require 'bee.filesystem'
local scope = require 'workspace.scope'
local ws = require 'workspace'
local furi = require 'file-uri'

local namespace <const> = 'ffi.namespace*.'

Expand Down Expand Up @@ -360,12 +359,15 @@ function m.build_single(codes, fileDir, uri)
if not texts then
return
end
local fullPath = fileDir /ws.getRelativePath(uri)

local hash = ('%08x'):format(SDBMHash():hash(uri))
local encoding = config.get(nil, 'Lua.runtime.fileEncoding')
local filePath = fileDir / table.concat({ hash, encoding }, '_')
if fullPath:stem():string():find '%.' then
local newPath = fullPath:parent_path() / (fullPath:stem():string():gsub('%.', '/') .. ".lua")
fs.create_directories(newPath:parent_path())
fullPath = newPath
end

utility.saveFile(tostring(filePath) .. '.d.lua', table.concat(texts, '\n'))
utility.saveFile(tostring(fullPath), table.concat(texts, '\n'))
return true
end

Expand Down
2 changes: 2 additions & 0 deletions test/plugins/ffi/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local template = require 'config.template'

template['Lua.runtime.version'].default = 'LuaJIT'

TESTURI = furi.encode('/unittest.ffi.lua')

---@async
local function TestBuilder()
local builder = require 'core.command.reloadFFIMeta'
Expand Down