source: git/Singular/dyn_modules/python/python.cc @ 79d8c07

fieker-DuValspielwiese
Last change on this file since 79d8c07 was 79d8c07, checked in by Hans Schoenemann <hannes@…>, 7 years ago
simplified some files: dyn_modules/python
  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <ctype.h>
5
6#include <unistd.h>
7#include <sys/stat.h>
8#include <boost/python.hpp>
9#include <Python.h>
10#include <kernel/mod2.h>
11#include <tok.h>
12#include <structs.h>
13#include <ipid.h>
14
15#include <locals.h>
16#include <omalloc.h>
17#include "python.h"
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <time.h>
23#include <Python.h>
24#include "wrapper.h"
25
26extern "C" {
27//int mod_init(
28//  int (*iiAddCproc)(char *libname, char *procname, BOOLEAN pstatic,
29//              BOOLEAN(*func)(leftv res, leftv v))
30//  )
31  int mod_init( SModulFunctions* psModulFunctions)
32{
33  enter_id("category","tests", STRING_CMD);
34  enter_id("version","$Id$", STRING_CMD);
35  enter_id("info","LIBRARY: kernel.lib  PROCEDURES OF GENERAL TYPE WRITEN IN C python(input); eval a string  in python", STRING_CMD);
36  Py_Initialize();
37  PyRun_SimpleString("from sys import path\n\
38path.insert(0,'.')\n");
39  initSingular();
40  init_Singular();
41
42  psModulFunctions->iiAddCproc(currPack->libname,"python",FALSE, mod_python);
43  return 0;
44}
45
46BOOLEAN mod_python(leftv __res, leftv __h)
47{
48  leftv __v = __h, __v_save;
49  int __tok = NONE, __index = 0;
50  sleftv __sa; leftv __za = &__sa;
51  char * a;
52  if(__v==NULL) goto mod_python_error;
53  __tok = __v->Typ();
54  if((__index=iiTestConvert(__tok, STRING_CMD))==0)
55     goto mod_python_error;
56  __v_save = __v->next;
57  __v->next = NULL;
58  if(iiConvert(__tok, STRING_CMD, __index, __v, __za))
59     goto mod_python_error;
60  __v = __v_save;
61  a = (char *)__za->Data();
62  if(__v!=NULL) { __tok = __v->Typ(); goto mod_python_error; }
63
64  PyRun_SimpleString(a);
65  __res->data = NULL;
66  __res->rtyp = END_RING;
67  return FALSE;
68
69  mod_python_error:
70    Werror("python(`%s`) is not supported", Tok2Cmdname(__tok));
71    Werror("expected python('string')");
72    return TRUE;
73}
Note: See TracBrowser for help on using the repository browser.