Difference between revisions of "HowTo:Implement an ApCoCoA-2 Package"

From ApCoCoAWiki
(Created page with "This page describes how to write a proper ApCoCoA-2 package in order to contribute it to ApCoCoA-2. For a complete description on how to contribute a package, see HowTo:Cont...")
 
m (changed reference to HowTo:Contribute an ApCoCoA Package)
Line 1: Line 1:
This page describes how to write a proper ApCoCoA-2 package in order to contribute it to ApCoCoA-2. For a complete description on how to contribute a package, see [[HowTo:Contribute an ApCoCoA Package]].
+
This page describes how to write a proper ApCoCoA-2 package in order to contribute it to ApCoCoA-2. For an overview on how to contribute a package and an example, see [[HowTo:Contribute an ApCoCoA Package]].
  
 
Note: In the following description, words marked as <code><span style="color:red;"><<word>></span></code> are placeholders, i.e. you should replace this text after copying.
 
Note: In the following description, words marked as <code><span style="color:red;"><<word>></span></code> are placeholders, i.e. you should replace this text after copying.

Revision as of 10:49, 29 October 2020

This page describes how to write a proper ApCoCoA-2 package in order to contribute it to ApCoCoA-2. For an overview on how to contribute a package and an example, see HowTo:Contribute an ApCoCoA Package.

Note: In the following description, words marked as <<word>> are placeholders, i.e. you should replace this text after copying.

Writing Functions

At the very first, you have to create a file <<package name>>.cpkg5. This is the package file and will later be located in the folder

/plugins/apcocoa/lib/cocoa/packages/apcocoa/

in the apcocoa directory. If the package is self-contained, you can first put it anywhere and load it into ApCoCoA or CoCoA-5 for testing the functions. Otherwise, we recommend putting it in the ApCoCoA package directory on your system and test it using ApCoCoA. The package can be reloaded for testing using the command

Source MEMORY_ApCoCoA_Packages_Path + "<<package name>>.cpkg5";

The following is a minimal example for the package:

Package $apcocoa/<<package name>>
export skip;

EndPackage;

The line export skip; is needed in order to tell CoCoA that this package does not export any functions. If you want to export functions, you can delete this line.

Afterwards you can now add the functions you want to have in the package. For instance, if you write

Package $apcocoa/<<package name>>
export skip;

Define Foo()
  PrintLn "Foo";
EndDefine; -- Foo

EndPackage;

you can call this function from CoCoA with $apcocoa/<<package name>>.foo();.

Adding package info

At first, add the following copyright information at the top of the package file (above Package $apcocoa/<<package name>>):

Copyright information
--
-- This file is part of the ApCoCoA package pool.
--
--   Copyright (c) ApCoCoA Project (Prof. Dr. Martin Kreuzer, Uni Passau)
--
--   Authors: <<year>> <<author name>>
--
-- Visit http://apcocoa.org/ for more information regarding ApCoCoA.
-- Visit http://www.apcocoa.org/wiki/ApCoCoA:KnownIssues for bugs, problems 
-- and known issues.
--
-- The ApCoCoA package pool is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License (version 3 or
-- later) as published by the Free Software Foundation. A copy of the full
-- licence may be found in the file COPYING in this directory.
--
-- The ApCoCoA package pool is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with the ApCoCoA package pool; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Then create two functions:

Define About()
  PrintLn "    	Topic   : <<Topic name (single word)>>";
  PrintLn "    	Keywords: <<keywords>>";
  PrintLn "    	Authors : <<author name>>";
  PrintLn "    	Version : <<current CoCoA version>>";
  PrintLn "    	Date    : <<release date>>";
EndDefine; -- About

Define Man()
  PrintLn "Recommended Alias:";
  PrintLn "   Alias <<alias>> := $apcocoa/<<package name>>;";
  PrintLn;
  ...
EndDefine; -- Man

The function Man() should contain a short description for every function contained in the package. For a clearer description of About() see the example below.