[ZeroBrane Studio] Re: Add autocomplete for a library

  • From: Paul K <paul@xxxxxxxxxxxxx>
  • To: "zerobrane@xxxxxxxxxxxxx" <zerobrane@xxxxxxxxxxxxx>
  • Date: Fri, 26 Sep 2014 15:36:12 -0700

Hi Steve,

> There is a bit simpler way to do this that avoids modifying
> luabase.lua file, but it requires a couple of small changes to ZBS
> that should be available in few days.

I pushed several changes that enable that simple way I mentioned. Here
is an example of how you may use it (using your API). This is a
package you can save as packages/test.lua (and you don't need any
other files):

local api = {
  st = {
    type = "lib",
    description = "the st lib test",

    -- children in the class hierarchy
    childs = { -- recursive
      Log = {
        type = "function",
        description = "Log a message to the debug files",
        args = "(string)",
        returns = "()",
      },
      SleepMillis = {
        type = "function",
        description = "Sleep a number of milli (1/1000) seconds.",
        args = "(number)",
        returns = "()",
      }
    }
  },
}

return {
  name = "AddAPI Test",
  description = "Demonstrates adding api.",
  author = "Me",
  version = 0.1,
  dependencies = 0.81,

  onRegister = function(self)
     ide:AddAPI("lua", "st", api)
  end,
  onUnRegister = function(self)
     ide:RemoveAPI("lua", "st")
  end,
  onInterpreterLoad = function(self, interpreter)
    local api = interpreter:GetAPI()
    if api then table.insert(api, "st") end
  end,
  onInterpreterClose = function(self, interpreter)
    local api = interpreter:GetAPI()
    if api and api[#api] == "st" then table.remove(api) end
  end,
}

Paul.

Other related posts: