static PyObject* evaluate_snippet(PyObject* self, PyObject* args, PyObject *keywds) { const char *filename, *src; char *out; unsigned max_stack = 500, gc_min_objects = 1000, max_trace = 20; double gc_growth_trigger = 2; int error; PyObject *ext_vars = NULL, *ext_codes = NULL; PyObject *tla_vars = NULL, *tla_codes = NULL; PyObject *import_callback = NULL; PyObject *native_callbacks = NULL; struct JsonlangVm *vm; static char *kwlist[] = { "filename", "src", "max_stack", "gc_min_objects", "gc_growth_trigger", "ext_vars", "ext_codes", "tla_vars", "tla_codes", "max_trace", "import_callback", "native_callbacks", NULL }; (void) self; if (!PyArg_ParseTupleAndKeywords( args, keywds, "ss|IIdOOOOIOO", kwlist, &filename, &src, &max_stack, &gc_min_objects, &gc_growth_trigger, &ext_vars, &ext_codes, &tla_vars, &tla_codes, &max_trace, &import_callback, &native_callbacks)) { return NULL; } vm = jsonlang_make(); jsonlang_max_stack(vm, max_stack); jsonlang_gc_min_objects(vm, gc_min_objects); jsonlang_max_trace(vm, max_trace); jsonlang_gc_growth_trigger(vm, gc_growth_trigger); if (!handle_vars(vm, ext_vars, 0, 0)) return NULL; if (!handle_vars(vm, ext_codes, 1, 0)) return NULL; if (!handle_vars(vm, tla_vars, 0, 1)) return NULL; if (!handle_vars(vm, tla_codes, 1, 1)) return NULL; struct ImportCtx ctx = { vm, import_callback }; if (!handle_import_callback(&ctx, import_callback)) { return NULL; } struct NativeCtx *ctxs = NULL; if (!handle_native_callbacks(vm, native_callbacks, &ctxs)) { free(ctxs); return NULL; } out = jsonlang_evaluate_snippet(vm, filename, src, &error); free(ctxs); return handle_result(vm, out, error); }
void ircInterface::onMessage(std::string msg){ /* while(pkge.find("\r\n") != std::string::npos){ std::string msg = pkge.substr(0, pkge.find("\r\n")); pkge = pkge.substr(pkge.find("\r\n") + 2); */ //std::cout << "ircInterface: raw message is : "<<msg<<std::endl; ircLog::instance()->logf(FILENAME, "raw message is: %s", msg.c_str()); //alot of the control strings will start with the type sperated from the //contents of the message with a space std::string type = msg.substr(0, msg.find_first_of(' ')); //first check for messages that start with message names //check for ping if(!type.compare(PING)) { _connStatus->pingRcvd(); sendPong(); return; } else if(!type.compare(ERROR)) { //TODO need to figure out hwat to do here //for now lets just try and not spam the other levels return; } else if(!type.compare("IRCERROR")) { //handle connection errors in conn status _connStatus->connectionIoError(); } //now check for messages that start with nicks or server titles else { _connStatus->pingRcvd(); //type is actually a prefix containing the host mask etc std::string prefix = type; // the actual message past the prefix msg = msg.substr(msg.find_first_of(' ')+1); //the first part of that message should be the type type = msg.substr(0, msg.find_first_of(' ')); //check first to see if it is a private message //most irc messaages are private messages if(!type.compare(PRIVMSG)) { handle_privmsg(msg, prefix); } else if(!type.compare(NOTICE)) { if(_connStatus->state() == CS_IDLE) { _connStatus->connected(); } handle_notice(msg, prefix); } else if(!type.compare(QUIT)) { ircEvent e = handle_quit(msg, prefix); notifyEvent(e); } else if(!type.compare(JOIN)) { ircEvent e = handle_join(msg, prefix); notifyEvent(e); } else if(!type.compare(PART)) { ircEvent e = handle_part(msg, prefix); notifyEvent(e); } else if(!type.compare(NICK)) { ircEvent e = handle_nick(msg, prefix); notifyEvent(e); } else if(!type.compare(INSPIRCDVARS)) { handle_vars(msg); } else if(!type.compare(NICKLIST)) { //add function to parse the nicklist std::vector<ircEvent> e = handle_nicklist(msg); for(unsigned int i = 0; i < e.size(); ++i) { notifyEvent(e[i]); } } else if(!type.compare("001")) { _connStatus->registered(); } } // } }