필터 지우기
필터 지우기

Backward compatible functionSignatures.json

조회 수: 2 (최근 30일)
Paul Wintz
Paul Wintz 2021년 10월 2일
답변: Rik 2021년 10월 5일
I'm writing a toolbox (packaged as described here) and I want to
  1. use functionSignatures.json to provide autocomplete information for function signatures when using the toolbox in R2021b, and
  2. support versions of MATLAB going back to at least R2016b (possibly without autocomplete infomation).
I have written a functionSignatures.json file that works well on R2021b, but because changes between MATLAB versions of how functionSignatures.json works, the command line prints the following errors when it tries to suggest autocompletions on R2016b:
Unknown attribute "purpose" with value "Initial state"
Unknown kind value "ordered".
Clearly, this is because support for "kind":"ordered" the attribute "purpose" in functionSignatures.json was not added to till after R2016b.
Is there a way to gracefully handle differences in functionSignatures.json between R2016b and R2021b?
  댓글 수: 2
Rik
Rik 2021년 10월 3일
Unfortunately there is only one way I see around this. As I understand, you can get a function to run at the end of the installation of your toolbox. That function can write the appropriate version of the JSON file in the same folder as your functions.
I'm not aware of a way to extract different files based on the release. There might be.
Paul Wintz
Paul Wintz 2021년 10월 5일
@Rik: Running a script at the end of installation is something that cannot be done automatically, although that was an idea I had also (see this question).

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2021년 10월 5일
In that case my proposed solution would be implementing something like Jan suggested in his answer.
Write a function similar to this:
function TestPostInstall
persistent IsInstalled
if isempty(IsInstalled)
%Because a pref (getpref and setpref) can be slow on Octave, I prefer
%to save a txt or mat file with a flag in a folder. I use the function
%below to get the path.
%https://www.mathworks.com/matlabcentral/fileexchange/87634-getwritablefolder
fn=fullfile(GetWritableFolder,'YourToolboxName','PostInstallScript.mat');
if ~exist(fn,'file')
RunPostInstall
PostInstallScriptHasRun='PostInstallScriptHasRun';
save(fn,PostInstallScriptHasRun)
end
IsInstalled=true;
end
end
Now you can write a RunPostInstall function that will write the correct JSON file (you might be interested in my ifversion function).
This setup has minimal overhead, as it will only go to disk once to see if the file exists. If you put a call to this same function in every entry function of your toolbox, the same persistent variable will apply to every call.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by