zerobrane - ZeroBrane:基于每个文件注册 API
问题描述
我正在为我们的Solarus 游戏引擎编写 ZeroBrane Studio 插件,它就像一个魅力。包括自动完成。
我现在想知道是否可以仅为一个文件注册 lua API。
我需要它来提供全局符号的自动完成/文档,这些符号可能因脚本而异,但可以从引擎的附件文件中推断出来。
总结:是否可以为单个文件注册 api?例如在 onEditorLoad()
事件中。
谢谢。
格雷格
编辑:
我尝试了以下但没有成功:
local function switch_editor(editor)
if current_editor == editor then
ide:Print("same editor")
return
end
current_editor = editor
if not editor then
ide:Print("null ed")
return
end
lua_file_path = ide:GetDocument(editor).filePath
if lua_file_path:match('/data/maps/') then
ide:Print("map file!",type(editor))
local map_api = make_map_api(lua_file_path)
current_api = map_api
ide:AddAPI('lua','solarus_map',map_api)
else
ide:Print('other file')
if current_api then
ide:RemoveAPI('lua','solarus_map')
current_api = nil
end
end
end
api = {"baselib", "solarus", "solarus_map"}, --in interpreter table
... -- in the plugin table :
onEditorFocusSet = function(self,editor)
switch_editor(editor)
end,
完成api 工作正常,但似乎没有考虑 apisolarus
的即时注册。solarus_map
编辑2:
愚蠢的我,我一定是打错了,因为在检查和重写了一些几乎就像上面粘贴的代码一样的东西之后......它起作用了!惊人的!
唯一的小问题是,当切换到我不想要solarus_map
API 的文件时……ide:RemoveAPI
是不够的。相反,我必须ide:AddAPI('lua','solarus_map',{})
用空的 API 替换 API。我可以忍受。
解决方案
总而言之,要实现一个从文件到文件的自定义api:
- 将 api 名称添加到解释器
- 在这种情况
onEditorFocusSet
下,使用 更新 APIide:AddAPI(...)
,最终将其设置为{}
是否需要为空/禁用。
我的问题版本中的代码示例。
推荐阅读
- html - 面包屑项目的边框着色
- batch-file - Windows 批处理循环变量以
- asp.net-web-api - 空请求正文拒绝请求
- html - 如何为多个背景图像设置动画?
- asp.net-mvc - 当我在缓存控制中保持无缓存、无存储时,Internet Explorer 中未加载图标
- python - Pandas Dataframe 按列值拆分为单独的 csv
- mysql - 如何将 HubSpot 数据自动集成到 MySQL 数据库中?
- arrays - 动态分配内存给数组并读取大文本文件
- c - 如何实现环境 | 带有 fork execve 和管道的 grep LANG
- node.js - npm 如何检查软件包版本是否易受攻击并在命令提示符中显示?