ZeroBrane:按文件注册API

时间:2018-11-04 00:22:31

标签: zerobrane

我正在为我们的Solarus Game Engine写一个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,

完成solarus api的工作正常,但似乎不考虑solarus_map api的即时注册。

EDIT2:

我的天哪,我一定做错了,因为检查并重写了上面粘贴的代码中的某些内容后,它确实起作用了!太棒了!

唯一的陷阱是,当切换到我不希望使用solarus_map API的文件时,ide:RemoveAPI是不够的。相反,我必须ide:AddAPI('lua','solarus_map',{})才能用一个空的API替换该API。我可以忍受的。

1 个答案:

答案 0 :(得分:1)

总而言之,要实现一个自定义api,该自定义api随文件而变化:

  • 将api名称添加到解释器中
  • /* Add application styles & imports to this file! */ @import '~@angular/material/prebuilt-themes/deeppurple-amber.css'; 事件中,使用<?xml version="1.0" encoding="utf-8"?> android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.design.widget.AppBarLayout android:id="@+id/appBar" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/head" android:id="@+id/img"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:layout_marginStart="28dp" android:layout_marginBottom="40dp" android:orientation="vertical"> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pending Work" android:textColor="#ffffff" android:textSize="35sp" /> <TextView android:id="@+id/num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0 Items" android:textColor="#ffffff" android:textSize="25sp" android:layout_marginBottom="20dp"/> </LinearLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@null" app:popupTheme="@style/AppTheme.PopupOverlay" /> </RelativeLayout> </android.support.design.widget.AppBarLayout> <include android:id="@+id/include" layout="@layout/content_main" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" app:elevation="8dp" app:fabSize="normal" app:layout_anchor="@+id/appBar" app:layout_anchorGravity="right|bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:tint="#fff" app:srcCompat="@android:drawable/ic_input_add" /> </android.support.design.widget.CoordinatorLayout> 更新API,如果需要将其清空或禁用,则最终将其设置为onEditorFocusSet

我的Question版本中的代码示例。

相关问题