manual:chapter4:libs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter4:libs [2018/03/02 09:29]
claudio [Creating user libraries]
manual:chapter4:libs [2019/09/11 07:57] (current)
claudioadmin [Creating user libraries]
Line 25: Line 25:
 ''{ { IDENT NARGS ALLOWINSYMB HELPTEXT } { IDENT NARGS ALLOWINSYMB HELPTEXT } ... }'' ''{ { IDENT NARGS ALLOWINSYMB HELPTEXT } { IDENT NARGS ALLOWINSYMB HELPTEXT } ... }''
  
-Where ''IDENT'' is the name of the command to be made visible, this is both the name of the variable containing the command in the directory, and the name of the command as it will be seen by the user of the library. ''NARGS'' and ''ALLOWINSYMB'' are integer numbers. The former is the number of arguments that the command takes, and the latter is a true/false value (1 or 0) indicating whether that command will be allowed to be used in symbolic expressions or not. All user commands (when allowed by setting this number to 1), will be accepted as a function call inside expressions, and the number of commands will be checked against the ''NARGS'' number. Finally, ''HELPTEXT'' is a string to be used as help when the user long-presses the name of the command in the menu. The string should be formatted so the text is in 3 lines, with the first 2 describing the command and the third line shows a stack diagram (preferably following the same guidelines as used in the system menus for consistency).+Where ''IDENT'' is the name of the command to be made visible, this is both the name of the variable containing the command in the directory, and the name of the command as it will be seen by the user of the library. ''NARGS'' and ''ALLOWINSYMB'' are integer numbers. The former is the number of arguments that the command takes from the stack, and the latter is a true/false value (1 or 0) indicating whether that command will be allowed to be used in symbolic expressions or not. All user commands (when allowed by setting this number to 1), will be accepted as a function call inside expressions, and the number of arguments will be checked against the ''NARGS'' number. Finally, ''HELPTEXT'' is a string to be used as help when the user long-presses the name of the command in the menu. The string should be formatted so the text is in 3 lines, with the first 2 describing the command and the third line shows a stack diagram (preferably following the same guidelines as used in the system menus for consistency).
 The ''$VISIBLE'' must therefore be a list of lists, where each sublist has exactly 4 elements: one ident, two integers and one string. Any deviation from this format will cause ''CRLIB'' to issue an ''Invalid $VISIBLE list''. The ''$VISIBLE'' must therefore be a list of lists, where each sublist has exactly 4 elements: one ident, two integers and one string. Any deviation from this format will cause ''CRLIB'' to issue an ''Invalid $VISIBLE list''.
  
Line 45: Line 45:
  
   * Always store private library settings using ''LIBSTO'' and ''LIBRCL''. These two commands will work the same as ''STO'' and ''RCL'' when called from the source directory, but when executed from within a library command, they will store/recall content from a special hidden directory that is private to the library. Each library can store arbitrary data in this private directory. Data is persistent and can only be erased by calling the ''LIBCLEAR'' command. Data stored with ''LIBSTO'' can only be recalled with ''LIBRCL'', using the unquoted name won't work since the variable is not in the current directory or local variable environment.   * Always store private library settings using ''LIBSTO'' and ''LIBRCL''. These two commands will work the same as ''STO'' and ''RCL'' when called from the source directory, but when executed from within a library command, they will store/recall content from a special hidden directory that is private to the library. Each library can store arbitrary data in this private directory. Data is persistent and can only be erased by calling the ''LIBCLEAR'' command. Data stored with ''LIBSTO'' can only be recalled with ''LIBRCL'', using the unquoted name won't work since the variable is not in the current directory or local variable environment.
 +
 +  * After testing a library, remember to ''DETACH'' it before trying to edit its code in the source directory. Remember that the variables are named exactly like the library commands, and if the library is attached, those names will be compiled to call the installed library, rather than the intended name identifier. This will not be visible to the user, the code will look identical but ''CRLIB'' will not be able to scan the names to include the subroutine.
 +
 +  * When creating new versions of a library, always add commands **at the end** of the ''$VISIBLE'' list. People using your library will have their own programs compiled with library pointers, which internally use the library ID and the index into the ''$VISIBLE'' list to refer to your commands. If the order of the commands change on the new version, user programs compiled for previous versions of the library will call the wrong command. If desired, create a custom ''$MENU'' to organize the commands in a different order as ''$VISIBLE''.
 +
  
 === Sample library "Hello world!" === === Sample library "Hello world!" ===
  
-To create the library, first create an empty directory: '''helloLIB' CRLIB'' and go into it. This library will have a single command ''HWORLD'' that puts the message "Hello world!" on the stack.+To create the library, first create an empty directory: '''helloLIB' CRDIR'' and go into it. This library will have a single command ''HWORLD'' that puts the message "Hello world!" on the stack.
  
 Create the variables needed inside the directory: Create the variables needed inside the directory:
Line 59: Line 64:
 |''$VISIBLE''  |''{ { 'HWORLD' 0 0 "Shows a nice↲greeting.↲  →  " } }'' | |''$VISIBLE''  |''{ { 'HWORLD' 0 0 "Shows a nice↲greeting.↲  →  " } }'' |
  
-Finally, use ''CRLIB'' to create the library, then ''ATTACH'' to attach it. From the main menu, ''Libs'' will now show an item ''mLIB''. Long pressing the item will show the library title. Going into the menu we should see the HWORLD command, long pressing it will show the help that was provided.+Finally, use ''CRLIB'' to create the library, then ''ATTACH'' to attach it. From the main menu, ''Libs'' will now show an item ''MyHW''. Long pressing the item will show the library title. Going into the menu we should see the HWORLD command, long pressing it will show the help that was provided.
  
 Notice that in this case, the ''WORLD'' string was included in the library because it was referenced by the main program ''HWORLD'', but it is not visible to the user. Notice that in this case, the ''WORLD'' string was included in the library because it was referenced by the main program ''HWORLD'', but it is not visible to the user.
 From now on, compiling a program that contains ''HWORLD'' will use the installed library command, rather than an identifier. Programs compiled before the library was attached will have an identifier instead. From now on, compiling a program that contains ''HWORLD'' will use the installed library command, rather than an identifier. Programs compiled before the library was attached will have an identifier instead.
 +
 +
 ---- ----
  
  • manual/chapter4/libs.1520011749.txt.gz
  • Last modified: 2018/03/02 09:29
  • by claudio