void LuaCreature::OnCombatStart(Unit* mTarget) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_ENTER_COMBAT]); push_creature(_unit); push_int(CREATURE_EVENT_ON_ENTER_COMBAT); push_unit(mTarget); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnTargetDodged(Unit* mTarget) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_TARGET_DODGED]); push_creature(_unit); push_int(CREATURE_EVENT_ON_TARGET_DODGED); push_unit(mTarget); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnDied(Unit* mKiller) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_DIED]); push_creature(_unit); push_int(CREATURE_EVENT_ON_DIED); push_unit(mKiller); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
void LuaCreature::OnFlee(Unit* mFlee) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_FLEE]); push_creature(_unit); push_int(CREATURE_EVENT_ON_FLEE); push_unit(mFlee); lua_engine::ExecuteLuaFunction(3); RELEASE_LOCK }
static void f_path_iterator_first(INT32 args) { struct cairo_mod_path* pw; cairo_path_t* path; int j,i; pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program); path = pw->path; THIS->idx = 0; push_int(path->num_data > 0); }
static void f_path_iterator_next(INT32 args) { struct cairo_mod_path* pw; cairo_path_t* path; int j,i; pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program); path = pw->path; THIS->idx++; for (i=0,j=0; j<=THIS->idx && i<path->num_data; i+= path->data[i].header.length, j++); push_int(THIS->idx >= 0 && THIS->idx < j); }
/* **| method: int unbind(); **| Unbind from the bound server. ** **| returns: the LDAP error code ** **| note: this method uses the OpenLDAP synchronous interface. ** **| see_also: the OpenLDAP v2 ldap_unbind(3) manual page. */ static void f_ldap_unbind(INT32 args) { if (THIS->bound) { THIS->lerrno = ldap_unbind_s(THIS->conn); THIS->bound = 0; } else THIS->lerrno = 0; pop_n_elems(args); push_int(THIS->lerrno); }
void f_msg_getfd(INT32 args) { MESSAGE *message; struct object *obj; message=THISMSG->msg; pop_n_elems(args); if( message->fp ) { obj=file_make_object_from_fd(fileno(message->fp), 0x1000,0); push_object(obj); } else push_int(-1); }
void LuaCreature::OnHit(Unit* mTarget, float fAmount) { NULL_BINDING_CHECK lua_engine::BeginLuaFunctionCall(m_binding->refs[CREATURE_EVENT_ON_HIT]); push_creature(_unit); push_int(CREATURE_EVENT_ON_HIT); push_unit(mTarget); push_float(fAmount); lua_engine::ExecuteLuaFunction(4); RELEASE_LOCK }
static void image_ilbm___decode(INT32 args) { unsigned char *s; ptrdiff_t len; struct pike_string *str; struct mapping *m; int n; extern void parse_iff(char *, unsigned char *, ptrdiff_t, struct mapping *, char *); get_all_args(NULL, args, "%S", &str); s = (unsigned char *)str->str; len = str->len; pop_n_elems(args-1); for(n=0; n<5; n++) push_int(0); push_mapping(m = allocate_mapping(4)); parse_iff("ILBM", s, len, m, "BODY"); mapping_index_no_free(sp-5, m, &string_[string_BMHD]); mapping_index_no_free(sp-4, m, &string_[string_CMAP]); mapping_index_no_free(sp-3, m, &string_[string_CAMG]); mapping_index_no_free(sp-2, m, &string_[string_BODY]); map_delete(m, &string_[string_BMHD]); map_delete(m, &string_[string_CMAP]); map_delete(m, &string_[string_CAMG]); map_delete(m, &string_[string_BODY]); if(TYPEOF(sp[-5]) != T_STRING) Pike_error("Missing BMHD chunk\n"); if(TYPEOF(sp[-2]) != T_STRING) Pike_error("Missing BODY chunk\n"); /* Extract image size from BMHD */ s = (unsigned char *)STR0(sp[-5].u.string); len = sp[-5].u.string->len; if(len<20) Pike_error("Short BMHD chunk\n"); free_svalue(sp-7); SET_SVAL(sp[-7], T_INT, NUMBER_NUMBER, integer, (s[0]<<8)|s[1]); SET_SVAL(sp[-6], T_INT, NUMBER_NUMBER, integer, (s[2]<<8)|s[3]); f_aggregate(7); }
void f__pipe_debug(INT32 args) { pop_n_elems(args); push_int(DO_NOT_WARN(noutputs)); push_int(DO_NOT_WARN(ninputs)); push_int(DO_NOT_WARN(nstrings)); push_int(DO_NOT_WARN(nobjects)); push_int(DO_NOT_WARN(mmapped)); push_int(DO_NOT_WARN(nbuffers)); push_int(DO_NOT_WARN(sbuffers)); f_aggregate(7); }
/*! @decl int order(string map) *! *! Returns the 'order' number for the map @[map]. *! *! This is usually the number of seconds since Jan 1 1970 (see @[time()]). *! When the map is changed, this number will change as well. *! *! @[map] is the YP-map to search in. This must be the full map name. *! eg @tt{passwd.byname@} instead of just @tt{passwd@}. */ static void f_order(INT32 args) { int err; YP_ORDER_TYPE ret; check_all_args(NULL, args, BIT_STRING, 0); err = yp_order( this->domain, sp[-args].u.string->str, &ret); YPERROR( err ); pop_n_elems( args ); push_int( (INT32) ret ); }
static void port_accept(INT32 args) { PIKE_SOCKADDR addr; struct port *this=THIS; int fd, err; ACCEPT_SIZE_T len=0; int one = 1; if(this->box.fd < 0) Pike_error("port->accept(): Port not open.\n"); /* FIXME: Race. */ THIS->box.revents = 0; THREADS_ALLOW(); len=sizeof(addr); do { fd=fd_accept(this->box.fd, (struct sockaddr *)&addr, &len); err = errno; } while (fd < 0 && err == EINTR); THREADS_DISALLOW(); INVALIDATE_CURRENT_TIME(); if(fd < 0) { this->my_errno=errno = err; pop_n_elems(args); push_int(0); return; } /* We don't really care if setsockopt fails, since it's just a hint. */ while ((fd_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(int)) < 0) && (errno == EINTR)) one = 1; my_set_close_on_exec(fd,1); push_new_fd_object(port_fd_factory_fun_num, fd, FILE_READ | FILE_WRITE, SOCKET_CAPABILITIES); if (this->box.backend) { struct object *o = Pike_sp[-1].u.object; struct my_file *f = (struct my_file *) (o->storage + o->prog->inherits[SUBTYPEOF(Pike_sp[-1])].storage_offset); change_backend_for_box(&f->box, this->box.backend); } stack_pop_n_elems_keep_top(args); }
/* * close and free the contents of a struct output * Note that the output struct is not freed or unlinked here, * that is taken care of later. */ static INLINE void output_finish(struct object *obj) { struct output *o, *oi; struct object *obji; debug_malloc_touch(obj); o=(struct output *)(obj->storage); if (o->obj) { if(obj==THIS->firstoutput){ THIS->firstoutput=o->next; } else for(obji=THIS->firstoutput;obji;obji=oi->next) { oi=(struct output *)(obji->storage); if(oi->next==obj) { oi->next=o->next; } } if(o->obj->prog) { #ifdef BLOCKING_CLOSE apply_low(o->obj,o->set_blocking_offset,0); pop_stack(); #endif push_int(0); apply(o->obj,"set_id",1); pop_stack(); apply(o->obj,"close",0); pop_stack(); if(!THISOBJ->prog) Pike_error("Pipe done callback destructed pipe.\n"); destruct(o->obj); } free_object(o->obj); noutputs--; o->obj=NULL; THIS->living_outputs--; finished_p(); /* Moved by per, one line down.. :) */ /* free_object(THISOBJ); */ /* What? /Hubbe */ } }
/*! @decl int match(string str) *! *! Returns 1 if @[str] matches the regexp bound to the regexp object. *! Zero otherwise. *! *! @decl array(string) match(array(string) strs) *! *! Returns an array containing strings in @[strs] that match the *! regexp bound to the regexp object. *! *! @bugs *! The current implementation doesn't support searching *! in strings containing the NUL character or any *! wide character. *! *! @seealso *! @[split] */ static void regexp_match(INT32 args) { int i; struct regexp *regexp = THIS->regexp; if(args < 1) SIMPLE_TOO_FEW_ARGS_ERROR("Regexp.SimpleRegexp->match", 1); if(Pike_sp[-args].type == T_STRING) { if(Pike_sp[-args].u.string->size_shift) SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "Expected string (8bit)"); i = pike_regexec(regexp, (char *)STR0(Pike_sp[-args].u.string)); pop_n_elems(args); push_int(i); return; } else if(Pike_sp[-args].type == T_ARRAY) { struct array *arr; int i, n; arr = Pike_sp[-args].u.array; for(i = n = 0; i < arr->size; i++) { struct svalue *sv = ITEM(arr) + i; if(sv->type != T_STRING || sv->u.string->size_shift) SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "Expected string (8bit)"); if(pike_regexec(regexp, (char *)STR0(sv->u.string))) { ref_push_string(sv->u.string); n++; } } f_aggregate(n); stack_pop_n_elems_keep_top(args); return; } else SIMPLE_BAD_ARG_ERROR("Regexp.SimpleRegexp->match", 1, "string|array(string)"); }
/* Read some data from the blocking object. * */ static int read_some_data(void) { struct pipe *this = THIS; struct input * i = this->firstinput; if (!i || i->type != I_BLOCKING_OBJ) { Pike_fatal("PIPE: read_some_data(): Bad input type!\n"); return -1; } push_int(8192); push_int(1); /* We don't care if we don't get all 8192 bytes. */ apply(i->u.obj, "read", 2); if ((sp[-1].type == T_STRING) && (sp[-1].u.string->len > 0)) { append_buffer(sp[-1].u.string); pop_stack(); THIS->sleeping = 1; return(1); /* Success */ } /* FIXME: Should we check the return value here? */ pop_stack(); /* EOF */ return(0); /* EOF */ }
void image_hrz_f_decode(INT32 args) { struct object *io; struct pike_string *s; int c; get_all_args( NULL, args, "%S", &s); if(s->len != 256*240*3) Pike_error("This is not a HRZ file\n"); push_int( 256 ); push_int( 240 ); io = clone_object( image_program, 2); for(c=0; c<256*240; c++) { rgb_group pix; pix.r = s->str[c*3]<<2 | s->str[c*3]>>4; pix.g = s->str[c*3+1]<<2 | s->str[c*3+1]>>4; pix.b = s->str[c*3+2]<<2 | s->str[c*3+2]>>4; ((struct image *)io->storage)->img[c] = pix; } pop_n_elems(args); push_object( io ); }
/* Free an input */ static INLINE void free_input(input *inp) { ninputs--; switch(inp->type) { case NBIO_STR: DERR(fprintf(stderr, "Freeing string input 0x%x\n", (unsigned int)inp)); free_string(inp->u.data); nstrings--; break; #ifdef USE_MMAP case NBIO_MMAP: DERR(fprintf(stderr, "Freeing mmap input 0x%x\n", (unsigned int)inp)); if(inp->u.mmap_storage->data != MAP_FAILED) { munmap(inp->u.mmap_storage->data, inp->u.mmap_storage->m_len); mmapped -= inp->u.mmap_storage->m_len; } push_int(0); push_int(0); push_int(0); apply_low(inp->u.mmap_storage->file, inp->set_nb_off, 3); apply_low(inp->u.mmap_storage->file, inp->set_b_off, 0); pop_n_elems(2); free_object(inp->u.mmap_storage->file); free(inp->u.mmap_storage); break; #endif case NBIO_OBJ: push_int(0); push_int(0); push_int(0); apply_low(inp->u.file, inp->set_nb_off, 3); apply_low(inp->u.file, inp->set_b_off, 0); pop_n_elems(2); /* FALL THROUGH */ case NBIO_BLOCK_OBJ: DERR(fprintf(stderr, "Freeing obj input 0x%x\n", (unsigned int)inp)); free_object(inp->u.file); nobjects--; break; } if(THIS->last_input == inp) THIS->last_input = NULL; THIS->inputs = inp->next; if(!THIS->finished && THIS->inputs && THIS->inputs->type == NBIO_OBJ) { /* Aha! Set read callback here */ DERR(fprintf(stderr, "Setting read/close callbacks for input 0x%x\n", (unsigned int)THIS->inputs)); push_callback(input_read_cb_off); push_int(0); push_callback(input_close_cb_off); apply_low(THIS->inputs->u.file, THIS->inputs->set_nb_off, 3); THIS->inputs->mode = READING; } free(inp); }
static void f_nbio_status(INT32 args) { pop_n_elems(args); push_int(noutputs); push_int(ninputs); push_int(nstrings); push_int(nobjects); push_nbio_int(mmapped); push_int(nbuffers); push_int(sbuffers); f_aggregate(7); }
/* Let's guess what this function does.... * */ static INLINE void input_finish(void) { struct input *i; while(1) { /* Get the next input from the queue */ i=THIS->firstinput->next; free_input(THIS->firstinput); THIS->firstinput=i; if(!i) break; switch(i->type) { case I_OBJ: THIS->sleeping=0; push_callback(offset_input_read_callback); push_int(0); push_callback(offset_input_close_callback); apply_low(i->u.obj,i->set_nonblocking_offset,3); pop_stack(); return; case I_BLOCKING_OBJ: if (read_some_data()) return; continue; case I_MMAP: if (THIS->fd==-1) return; continue; case I_STRING: append_buffer(i->u.str); case I_NONE: break; } } THIS->sleeping=0; low_start(); finished_p(); }
void exec_eil(int field_size){ Odescr *address = pop_tstack(); switch(field_size){ case sizeof(int):{ push_int(*((int *)address->inst.sval)); break; } case sizeof(char):{ push_char(*((char *)address->inst.sval)); break; } case sizeof(char *):{ char** act = (char **)address->inst.sval; push_string(act[0]); break; } default:{ machine_error("EIL field_size error."); break; } } freemem((char*)address, sizeof(Odescr)); // only dealloc the object and not the inst }
/* array get_term(int term_num) */ static void f_get_term(INT32 args) { int n, term_num; long count; char *term; GET_PIKE_SEARCH(); get_all_args("Search->get_term()", args, "%i", &term_num); THREADS_ALLOW(); n = avs_getsearchterms(search->handle, term_num, &term, &count); THREADS_DISALLOW(); if (n != AVS_OK) Pike_error("Search->get_term(): %s\n", avs_errmsg(n)); pop_n_elems(args); push_text(term); push_int(count); f_aggregate(2); }
static void pextsIgnorableWhitespace(void *ctx, const xmlChar *ch, int len) { DBG_FUNC_ENTER(); if (CB_ABSENT(ignorableWhitespaceSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); if (ch && len) push_string(make_shared_binary_string((const char*)ch, (size_t) len)); else push_int(0); push_svalue(&THIS->user_data); CB_CALL(ignorableWhitespaceSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
static void f_parse_xml(INT32 args) { xmlDocPtr doc = NULL; switch (THIS->parsing_method) { case PARSE_PUSH_PARSER: Pike_error("Push parser not implemented yet. Please bug [email protected] to implement it."); case PARSE_MEMORY_PARSER: doc = xmlSAXParseMemory(THIS->sax, THIS->input_data->str, THIS->input_data->len, 1); break; case PARSE_FILE_PARSER: doc = xmlSAXParseFileWithData(THIS->sax, THIS->input_data->str, 1, NULL); break; } if ( doc != NULL ) xmlFreeDoc(doc); push_int(0); }
static void pextsCdataBlock(void *ctx, const xmlChar *value, int len) { DBG_FUNC_ENTER(); if (CB_ABSENT(cdataBlockSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); if (value) push_string(make_shared_binary_string((const char*)value, (size_t) len)); else push_int(0); push_svalue(&THIS->user_data); CB_CALL(cdataBlockSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
/*! @decl void write(string bytes) *! *! Add an input string to this pipe. */ static void pipe_write(INT32 args) { struct input *i; if (args<1 || sp[-args].type!=T_STRING) Pike_error("illegal argument to pipe->write()\n"); if (!THIS->firstinput) { append_buffer(sp[-args].u.string); pop_n_elems(args); push_int(0); return; } i=new_input(); i->type=I_STRING; nstrings++; add_ref(i->u.str=sp[-args].u.string); pop_n_elems(args-1); }
/*----------------------------------------------------------------------------*/ PmReturn_t tres_pm_save_state(pPmFrame_t *ppframe) { PmReturn_t retv = PM_RET_OK; pPmObj_t pobj; pPmInstance_t pcli; pPmDict_t pdict; uint16_t index; if(NATIVE_GET_NUM_ARGS() != 1) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } pobj = NATIVE_GET_LOCAL(0); if(OBJ_GET_TYPE(pobj) != OBJ_TYPE_CLI) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } pcli = (pPmInstance_t)pobj; pdict = pcli->cli_attrs; // store each attribute of the object for(index = 0; index < pdict->length; index++) { seglist_getItem(pdict->d_keys, index, &pobj); retv = seglist_getItem(pdict->d_vals, index, &pobj); PM_RETURN_IF_ERROR(retv); switch (OBJ_GET_TYPE(pobj)) { case OBJ_TYPE_INT: push_int(((pPmInt_t) pobj)->val); break; case OBJ_TYPE_FLT: push_float(((pPmFloat_t) pobj)->val); break; } } NATIVE_SET_TOS(PM_NONE); return retv; }
static void pextsEntityDecl(void *ctx, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) { DBG_FUNC_ENTER(); if (CB_ABSENT(entityDeclSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); push_int(type); safe_push_text(publicId); safe_push_text(systemId); safe_push_text(content); push_svalue(&THIS->user_data); CB_CALL(entityDeclSAX, 7); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsStartElement(void *ctx, const xmlChar *name, const xmlChar **atts) { int npairs; const xmlChar **tmp; DBG_FUNC_ENTER(); if (CB_ABSENT(startElementSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); if (atts) { npairs = 0; tmp = atts; while (tmp && *tmp) { safe_push_text(*tmp); tmp++; safe_push_text(*tmp); tmp++; npairs += 2; } f_aggregate_mapping(npairs); } else { push_int(0); } push_svalue(&THIS->user_data); CB_CALL(startElementSAX, 4); pop_stack(); DBG_FUNC_LEAVE(); }
/*----------------------------------------------------------------------------*/ PmReturn_t tres_pm_state_push(pPmFrame_t *ppframe) { //const char *ptr; int32_t ival; float fval; PmReturn_t retv = PM_RET_OK; pPmObj_t pa; /* Raise TypeError if wrong number of args */ pa = NATIVE_GET_LOCAL(0); if(NATIVE_GET_NUM_ARGS() != 1) { PM_RAISE(retv, PM_RET_EX_TYPE); return retv; } switch (OBJ_GET_TYPE(pa)) { //case OBJ_TYPE_STR: // ptr = (char const *)&(((pPmString_t)pa)->val); // // TODO: unimplemented // break; case OBJ_TYPE_INT: ival = ((pPmInt_t) pa)->val; push_int(ival); break; case OBJ_TYPE_FLT: fval = ((pPmFloat_t) pa)->val; push_float(fval); break; default: /* Raise TypeError */ PM_RAISE(retv, PM_RET_EX_TYPE); } NATIVE_SET_TOS(PM_NONE); return retv; }