I'm migrating a Java Card applet test structure to make use of JCShell and am having trouble finding documentation or examples on the use of DEFUN. I have a couple of questions out of this:
1) Aside from the JCShell user manual 6.9.0.X which doesn't really cover DEFUN syntax much, are there any further documents or examples that can be made available for more advanced JCShell scripting scenarios?
2) In particular, is it possible to provide arguments to functions defined using DEFUN? If not, is there a convention NXP uses to achieve a similar result?
Thanks
已解决! 转到解答。
Older versions of JCShell had a directory called "scripts" and there are a number of examples within that directory of the use of DEFUN.
In any event, DEFUN is equivalent to placing the contents of the DEFUN function in a <name>.jcsh file in the defined scripts directory where <name> is the name of the function (and without the cotaining DEFUN END pair). AFAICT, the instantiation of the DEFUN function is deferred until the containing file is called, and then is available for the life of the jcshell session.
Older versions of JCShell had a directory called "scripts" and there are a number of examples within that directory of the use of DEFUN.
In any event, DEFUN is equivalent to placing the contents of the DEFUN function in a <name>.jcsh file in the defined scripts directory where <name> is the name of the function (and without the cotaining DEFUN END pair). AFAICT, the instantiation of the DEFUN function is deferred until the containing file is called, and then is available for the life of the jcshell session.
Thanks for the tip! I found the scripts folder in the v3.7.2.4 package in the archives. In this I found scripts/tools/script_tlv.jcsh which showed an example of arguments used by DEFUN:
So with the script "myscript.jcsh":
# Testing function arguments
DEFUN my_test_function
/echo argv[0] is ${argv[0]}
/echo argv[1] is ${argv[1]}
/echo argv[2] is ${argv[2]}
END
# Run it with various arguments
my_test_function A B C
my_test_function A B
my_test_function A
And executing it using:
myscript 1 2 3
(I deliberately put "1 2 3" to make sure it is not getting argv from the arguments to the main script instead of the call to the function)
And I get the output:
argv[0] is A
argv[1] is B
argv[2] is C
argv[0] is A
argv[1] is B
argv[2] is
argv[0] is A
argv[1] is
argv[2] is
Thanks!
P.S. @Kan_Li a suggestion for NXP is to update and re-introduce these scripts into the JCShell releases as well as explicitly document DEFUN.
Hi @makinako ,
Such kind of docs are under DNA, have you already signed it with NXP? If not, you may request it on line.
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi @makinako ,
Are you referring to the following DEFUN info?
https://www.gnu.org/software/emacs/manual/html_node/eintr/defun.html
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
No this is not the correct syntax. The code sample you just sent me is LISP and JCShell DEFUN does not resemble it. The example on the link you just sent me is this:
(defun function-name (arguments…)
"optional-documentation…"
(interactive argument-passing-info) ; optional
body…)
and here is an example out of the JCShell documentation:
DEFUN GET_SCR_PATH
/echo ${script.name}
END
As I said in my first message, there is no actual section in the JCShell document that defines the syntax for DEFUN and the examples are not very comprehensive.
Hi @makinako ,
Yes, it is strange not documented in JCShell user manual, and I have also asked a few people but there seems to be no such document at all. I am sorry about that! All I can do is sharing example. If you need it, I may share you via the Case Portal. Please submit a private ticket for it according to the following video.
https://www.nxp.com/video/tutorial-for-nxp-support-case-portal:NCP-VIDEO
Have a great day,
Kan
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------