librime-lua icon indicating copy to clipboard operation
librime-lua copied to clipboard

请问能否添加 接口 方便判断 librime-lua 版本

Open LawssssCat opened this issue 1 year ago • 5 comments

想判断 librime-lua 版本,看是否支持某接口,做一些异常捕获。

现有方案好像是通过判断是否有 某方法 来判断版本:

https://github.com/shewer/librime-lua-script/blob/5e55b8a386f355282e8a4be16a0b06d8e1423800/lua/tools/rime_api.lua

local function Version()
  local ver
  if Opencc and Opencc('s2t.json').convert_word then ----------- 构造
    return 200
  elseif rime_api.regex_match then
    return 197
  elseif rime_api.get_distribution_name then
    return 185
  elseif LevelDb then
    return 177
  elseif Opencc then
    return 147
  elseif KeySequence and KeySequence().repr then --------- 构造
    return 139
  elseif  ConfigMap and ConfigMap().keys then ----------------- 构造
    return 127
  elseif Projection then
    return 102
  elseif KeyEvent then
    return 100
  elseif Memory then
    return 80
  elseif rime_api.get_user_data_dir then
    return 9
  elseif log then
    return 9
  else
    return 0
  end
end

但是这样的话,判断 对象属性 时就必须要把对象构造出来

可是有的对象是没法构造出来的,或者构造出来非常耗资源 比方说 memory

所以否能 『在构造前』 判断对象是否有某属性?

LawssssCat avatar Oct 18 '22 01:10 LawssssCat