MapleListAlloc
create a list in external code
MapleListAssign
assign into a list in external code
MapleListSelect
select from a list in external code
Calling Sequence
Parameters
Description
Examples
MapleListAlloc(kv, n)
MapleListAssign(kv, list, i, val)
MapleListSelect(kv, list, i)
kv
-
kernel handle of type MKernelVector
n
number of elements in the list
list
Maple list object
i
index of entry in a list
val
value to assign into the list
These functions can be used in external code with OpenMaple or define_external.
MapleListAlloc creates a new list that can contain n elements. The list must be filled completely before passing it back to Maple.
MapleListAssign sets the ith element of the given list to the value val. Lists can be modified only if they were created by MapleListAlloc and have never entered Maple (for example, as an argument to a function evaluation or returned value). Lists are static objects; once created, they cannot change. For information on working with a dynamic object, see ?RTableCreate.
MapleListSelect retrieves the ith element of the given list. Indexing in a list starts at 1.
The size of a list can be obtained using the MapleNumArgs command.
#include <sys/types.h>
#include <time.h>
#include "maplec.h"
ALGEB M_DECL MyTimeList( MKernelVector kv, ALGEB *args )
{
time_t c;
struct tm *t;
ALGEB list, elem, val;
char *code;
M_INT n, i;
if( MapleNumArgs(kv,(ALGEB)args) != 1 ) {
MapleRaiseError(kv,"one argument expected");
return( NULL );
}
if( !IsMapleList(kv,args[1]) ) {
MapleRaiseError(kv,"list expected");
n = MapleNumArgs(kv,args[1]);
list = MapleListAlloc(kv,n);
c = time(&c);
t = localtime(&c);
for( i=1; i<=n; ++i ) {
elem = MapleListSelect(kv,args[1],i);
if( !IsMapleString(kv,elem) ) {
MapleRaiseError1(kv,"string expected for %-1 parameter",
ToMapleInteger(kv,i));
code = MapleToString(kv,elem);
if( strcmp(code,"SS") == 0 ) {
val = ToMapleInteger(kv,t->tm_sec);
else if( strcmp(code,"MM") == 0 ) {
val = ToMapleInteger(kv,t->tm_min);
else if( strcmp(code,"HH") == 0 ) {
val = ToMapleInteger(kv,t->tm_hour);
else if( strcmp(code,"dd") == 0 ) {
val = ToMapleInteger(kv,t->tm_mday);
else if( strcmp(code,"mm") == 0 ) {
val = ToMapleInteger(kv,t->tm_mon);
else if( strcmp(code,"yy") == 0 ) {
val = ToMapleInteger(kv,t->tm_year+1900);
else if( strcmp(code,"ww") == 0 ) {
val = ToMapleInteger(kv,t->tm_wday);
else if( strcmp(code,"jj") == 0 ) {
val = ToMapleInteger(kv,t->tm_yday);
else if( strcmp(code,"vv") == 0 ) {
val = ToMapleInteger(kv,t->tm_isdst);
else {
MapleRaiseError1(kv,"unrecognized format code, %1",elem);
MapleListAssign(kv,list,i,val);
return( list );
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
date≔DefineExternal⁡MyTimeList,dll:
date⁡mm,dd,yy
2,29,2024
date⁡HH,MM,SS
23,49,37
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
StringTools[FormatTime]
Download Help Document