[4ed8634] | 1 | The following is valid for Singular 4-x-x: |
---|
[d36c18] | 2 | (for technical details see https://www.singular.uni-kl.de/Manual/modules.pdf) |
---|
[dc0a3b] | 3 | |
---|
[4ed8634] | 4 | ./configure --disable-static .... |
---|
[dc0a3b] | 5 | |
---|
[4ed8634] | 6 | make install |
---|
[e4d44b] | 7 | |
---|
[3ce617] | 8 | --------------------------------------- |
---|
| 9 | how to compile and run the the example: |
---|
[4ed8634] | 10 | libsingular-config --libs: gives the correct arguments for linking |
---|
| 11 | libsingular-config --cflags: gives the correct arguments for compiling |
---|
| 12 | g++ ...... -o tt tt.cc .... |
---|
[5f32d50] | 13 | |
---|
[3ce617] | 14 | ./tt |
---|
| 15 | -------------------------------------- |
---|
| 16 | the example: |
---|
[4ed8634] | 17 | #include <Singular/libsingular.h> |
---|
[70b4f4] | 18 | main() |
---|
[3ce617] | 19 | { |
---|
| 20 | // init path names etc. |
---|
[4ed8634] | 21 | siInit((char *)"/...lib/libSingular.so"); |
---|
[3ce617] | 22 | |
---|
| 23 | // construct the ring Z/32003[x,y,z] |
---|
| 24 | // the variable names |
---|
| 25 | char **n=(char**)omalloc(3*sizeof(char*)); |
---|
| 26 | n[0]=omStrDup("x"); |
---|
| 27 | n[1]=omStrDup("y"); |
---|
[70b4f4] | 28 | n[2]=omStrDup("z2"); |
---|
[3ce617] | 29 | |
---|
| 30 | ring R=rDefault(32003,3,n); |
---|
| 31 | // make R the default ring: |
---|
| 32 | rChangeCurrRing(R); |
---|
| 33 | |
---|
| 34 | // create the polynomial 1 |
---|
| 35 | poly p1=p_ISet(1,R); |
---|
| 36 | |
---|
[4bde6b] | 37 | // creat the polynomial 2*x^3*z^2 |
---|
[3ce617] | 38 | poly p2=p_ISet(2,R); |
---|
| 39 | pSetExp(p2,1,3); |
---|
| 40 | pSetExp(p2,3,2); |
---|
| 41 | pSetm(p2); |
---|
| 42 | |
---|
| 43 | // print p1 + p2 |
---|
| 44 | pWrite(p1); printf(" + \n"); pWrite(p2); printf("\n"); |
---|
| 45 | |
---|
| 46 | // compute p1+p2 |
---|
| 47 | p1=p_Add_q(p1,p2,R); p2=NULL; |
---|
[75f460] | 48 | pWrite(p1); |
---|
[3ce617] | 49 | |
---|
[70b4f4] | 50 | // clean up: |
---|
[3ce617] | 51 | pDelete(&p1); |
---|
| 52 | rKill(R); |
---|
[70b4f4] | 53 | |
---|
| 54 | currentVoice=feInitStdin(NULL); |
---|
| 55 | // hook for error handling: |
---|
| 56 | // WerrorS_callback=......; of type p(const char *) |
---|
[e3085c] | 57 | int err=iiAllStart(NULL,"int ver=system(\"version\");\n",BT_proc,0); |
---|
[70b4f4] | 58 | if (err) errorreported = 0; // reset error handling |
---|
| 59 | printf("interpreter returns %d\n",err); |
---|
| 60 | idhdl h=ggetid("ver"); |
---|
| 61 | if (h!=NULL) |
---|
| 62 | printf("singular variable ver of type %d contains %d\n",h->typ,(int)(long)IDDATA(h)); |
---|
| 63 | else |
---|
| 64 | printf("variable ver does not exist\n"); |
---|
| 65 | |
---|
| 66 | // calling a singular-library function |
---|
| 67 | idhdl datetime=ggetid("datetime"); |
---|
| 68 | if (datetime==NULL) |
---|
| 69 | printf("datetime not found\n"); |
---|
| 70 | else |
---|
| 71 | { |
---|
[7fc721] | 72 | BOOLEAN res=iiMake_proc(datetime,NULL,NULL); |
---|
| 73 | if (res) { printf("datetime return an error\n"); errorreported = 0; } |
---|
| 74 | else printf("datetime returned type %d, >>%s<<\n",iiRETURNEXPR.Typ(),(char *)iiRETURNEXPR.Data()); |
---|
[70b4f4] | 75 | } |
---|
| 76 | |
---|
[70bf188] | 77 | // changing a ring for the interpreter |
---|
| 78 | // re-using n and R from above |
---|
| 79 | R=rDefault(32003,3,n); |
---|
| 80 | idhdl newRingHdl=enterid("R" /* ring name*/, |
---|
| 81 | 0, /*nesting level, 0=global*/ |
---|
| 82 | RING_CMD, |
---|
| 83 | &IDROOT, |
---|
| 84 | FALSE); |
---|
| 85 | IDRING(newRingHdl)=R; |
---|
| 86 | // make R the default ring (include rChangeCurrRing): |
---|
| 87 | rSetHdl(newRingHdl); |
---|
[f255f0] | 88 | myynest=1; /* <=0: interactive at eof/ >=1: non-interactive */ |
---|
| 89 | err=iiAllStart(NULL,"poly p=x;listvar();return();\n",BT_proc,0); |
---|
[70bf188] | 90 | |
---|
[70b4f4] | 91 | // calling a kernel function via the interpreter interface |
---|
| 92 | sleftv r1; memset(&r1,0,sizeof(r1)); |
---|
| 93 | sleftv arg; memset(&arg,0,sizeof(r1)); |
---|
| 94 | arg.rtyp=STRING_CMD; |
---|
| 95 | arg.data=omStrDup("huhu"); |
---|
| 96 | err=iiExprArith1(&r1,&arg,TYPEOF_CMD); |
---|
| 97 | printf("interpreter returns %d\n",err); |
---|
| 98 | if (err) errorreported = 0; // reset error handling |
---|
| 99 | else printf("typeof returned type %d, >>%s<<\n",r1.Typ(),r1.Data()); |
---|
| 100 | // clean up r1: |
---|
| 101 | r1.CleanUp(); |
---|
[3ce617] | 102 | } |
---|