Merge branch 'master' of https://github.com/calf-studio-gear/calf
[calf.git] / bigbull / ttldata.h
blobcc739205d554428eceb80c1ab4a81735f33a9388
1 #ifndef _TTLDATA_H
2 #define _TTLDATA_H
4 #include <iostream>
5 #include <sstream>
6 #include <string>
7 #include <Python.h>
9 class TTLLexer: public yyFlexLexer
11 public:
12 std::string strctx;
13 PyObject *pylist;
15 TTLLexer(std::istream *istr) : yyFlexLexer(istr), pylist(PyList_New(0)) {}
16 void add(const std::string &type, const std::string &value) {
17 PyList_Append(pylist, Py_BuildValue("(ss)", type.c_str(), value.c_str()));
18 // printf("Type %s, Value %s\n", type.c_str(), value.c_str());
20 void add(const std::string &type, PyObject *value) {
21 PyList_Append(pylist, Py_BuildValue("(sO)", type.c_str(), value));
22 PyObject *str = PyObject_Str(value);
23 // printf("Type %s, Repr Value %s\n", type.c_str(), PyString_AsString(str));
24 Py_DECREF(str);
26 PyObject *grab() {
27 PyObject *tmp = pylist;
28 pylist = NULL;
29 return tmp;
31 ~TTLLexer() {
32 Py_XDECREF(pylist);
36 #define LEXER_DATA (dynamic_cast<TTLLexer *>(this))
38 #endif