RTableSetAttribute
assign to the attribute RTableSettings field in external code
RTableAppendAttribute
append to the attribute RTableSettings field in external code
RTableSetIndFn
assign to the index_functions RTableSettings field in external code
RTableAppendIndFn
append to the index_functions RTableSettings field in external code
RTableSetType
assign to the data_type and maple_type RTableSettings field in external code
Calling Sequence
Parameters
Description
Examples
RTableSetAttribute(kv, rts, name)
RTableAppendAttribute(kv, rts, name)
RTableSetIndFn(kv, rts, indfn)
RTableAppendIndFn(kv, rts, indfn)
RTableSetType(kv, rts, id, name)
kv
-
kernel handle of type MKernelVector
rts
pointer to an RTableSettings structure
name
name of an attribute or type
indfn
type ALGEB indexing function object
id
data_type identifier
These functions can be used in external code with OpenMaple or define_external.
These functions update an RTableSettings structure. They are provided for convenience. The RTableSettings structure can be modified directly. Some extra argument checking is done.
RTableSetAttribute(kv,rts,name) is equivalent to rts->attributes = ToMapleExpressionSequence(kv,1,ToMapleName(kv,name,TRUE)); Attributes can be retrieved using the attributes command in Maple.
RTableAppendAttribute(kv,rts,name) is equivalent to the following.
M_INT n, i;
ALGEB attrib;
n = MapleNumArgs(kv,rts->attributes);
attrib = NewMapleExpressionSequence(kv,n+1);
for( i=1; i<=n; ++i ) {
attrib[i] = rts->attributes[i];
}
rts->attributes[n] = (ALGEB)MapleToName(kv,name,TRUE);
RTableSetIndFn and RTableAppendIndFn are the same as RTableSetAttribute and RTableAppendAttribute except they work on rts->index_functions instead of rts->attributes to set the indexing function property.
RTableSetType sets the data_type and maple_type fields of the RTableSettings structure. This command is equivalent to the following code.
rts->data_type = id;
if( id == RTABLE_DAG } {
rts->maple_type = ToMapleName(kv,name,TRUE);
#include <string.h>
#include "maplec.h"
ALGEB M_DECL MyStack( MKernelVector kv, ALGEB *args )
{
M_INT argc;
RTableSettings rts;
ALGEB rt;
char *method;
M_INT size;
argc = MapleNumArgs(kv,(ALGEB)args);
if( argc == 0 ) {
MapleRaiseError(kv,"method expected");
return( NULL );
method = MapleToString(kv,args[1]);
if( strcmp(method,"create") == 0 ) {
M_INT bounds[2];
if( argc != 2 ) {
MapleRaiseError(kv,"size expected");
size = MapleToM_INT(kv,args[2]);
RTableGetDefaults(kv,&rts);
RTableSetAttribute(kv,&rts,"stack");
RTableAppendAttribute(kv,&rts,"12345");
RTableSetType(kv,&rts,RTABLE_DAG,"numeric");
rts.num_dimensions = 1;
bounds[0] = 1;
bounds[1] = size+1;
rt = RTableCreate(kv,&rts,NULL,bounds);
return( rt );
else {
RTableData rtd;
M_INT index[1];
if( argc < 2 ) {
MapleRaiseError(kv,"stack rtable expected");
if( !IsMapleRTable(kv,args[2]) ) {
rt = args[2];
RTableGetSettings(kv,&rts,rt);
if( MapleNumArgs(kv,rts.attributes) < 2
|| !IsMapleName(kv,(ALGEB)rts.attributes[1])
|| !IsMapleName(kv,(ALGEB)rts.attributes[2])
|| strcmp(MapleToString(kv,(ALGEB)rts.attributes[1]),"stack")
|| strcmp(MapleToString(kv,(ALGEB)rts.attributes[2]),"12345")
|| rts.num_dimensions != 1
|| rts.data_type != RTABLE_DAG
|| rts.storage != RTABLE_RECT ) {
MapleRaiseError(kv,"invalid stack rtable");
if( strcmp(method,"push") == 0 ) {
if( argc < 3 ) {
MapleRaiseError(kv,"element to push expected");
index[0] = 1;
rtd = RTableSelect(kv,rt,index);
size = MapleToM_INT(kv,rtd.dag);
if( size+1 == RTableUpperBound(kv,rt,1) ) {
MapleRaiseError(kv,"stack is full");
index[0] = size+2;
rtd.dag = args[3];
RTableAssign(kv,rt,index,rtd);
size++;
rtd.dag = ToMapleInteger(kv,size);
return( args[3] );
else if( strcmp(method,"pop") == 0 ) {
if( size == 0 ) {
MapleRaiseError(kv,"stack is empty");
size--;
return( rtd.dag );
else if( strcmp(method,"isempty") == 0 ) {
return( ToMapleBoolean(kv,size==0) );
MapleRaiseError1(kv,"invalid method %1",args[1]);
return( ToMapleNULL(kv) );
Execute the external function from Maple.
with⁡ExternalCalling:
dll≔ExternalLibraryName⁡HelpExamples:
mystack≔DefineExternal⁡MyStack,dll:
s≔mystack⁡create,5
s≔000000
attributes⁡s
stack,12345
mystack⁡push,s,1,2,3
Error, (in mystack) unable to store '[1, 2, 3]' when datatype=numeric
mystack⁡pop,s
Error, (in mystack) stack is empty
mystack⁡isempty,s
true
mystack⁡push,s,1
1
mystack⁡push,s,2
2
mystack⁡push,s,3
3
mystack⁡push,s,4
4
mystack⁡push,s,5
5
mystack⁡push,s,6
Error, (in mystack) stack is full
mystack⁡push,s,99
99
false
See Also
CustomWrapper
define_external
OpenMaple
OpenMaple/C/API
OpenMaple/C/Examples
rtable
Download Help Document