void controlEvent(Control *control, EventType type) { val_call2( clbkControlEvent.get(), ReferenceToValue(control, true), EnumToValue(type) ); }
void ByteArray::Resize (int inSize) { if (mValue == 0) mValue = val_call1 (gByteArrayCreate->get (), alloc_int (inSize)); else val_call2 (gByteArrayResize->get (), mValue, alloc_int (inSize)); }
void Multiplayers_onDatas( const char *sDatas , const char *sFrom ){ #ifdef ANDROID //ALOG("Multiplayers_onDatas" ); #endif val_call2( eval_onDatas_multi->get( ) , alloc_string( sDatas ) , alloc_string( sFrom ) ); }
void HypPlayServices_onEvent( const char *sType , const char *sArg ){ #ifdef ANDROID ALOG("hypps_onEvent" ); #endif val_call2( eval_onEvent->get( ) , alloc_string( sType ) , alloc_string( sArg ) ); }
bool visitWrapper(Node *node, long cookie) { bool result = val_get_bool(val_call2( clbkVisitMethod.get(), ReferenceToValue(node, true), alloc_int(cookie) )); return result; }
static void logFunction(Logger::Level level, const char *message) { if (clbkLogFunction != NULL) { val_call2( clbkLogFunction->get(), EnumToValue(level), StringToValue(message) ); } }
/** $hiter : 'hash -> f:function:2 -> void <doc>Call the function [f] with every key and value in the hashtable</doc> **/ static value builtin_hiter( value vh, value f ) { int i; hcell *c; vhash *h; val_check_function(f,2); val_check_kind(vh,k_hash); h = val_hdata(vh); for(i=0;i<h->ncells;i++) { c = h->cells[i]; while( c != NULL ) { val_call2(f,c->key,c->val); c = c->next; } } return val_null; }
void* ValuePointer::Call (void* arg0, void* arg1) { if (!hlValue) { return val_call2 ((value)Get (), (value)arg0, (value)arg1); } else { vdynamic* args[] = { (vdynamic*)arg0, (vdynamic*)arg1, }; return hl_dyn_call ((vclosure*)hlValue, (vdynamic**)&args, 2); } }
/** $hremove : 'hash -> k:any -> cmp:function:2? -> bool <doc> Look for the value bound to the key [k] in the hashtable. Use the comparison function [cmp] or [$compare] if [null]. Return true if such value exists and remove it from the hash, false either. </doc> **/ static value builtin_hremove( value vh, value key, value cmp ) { vhash *h; hcell *c, *prev = NULL; int hkey; if( !val_is_null(cmp) ) val_check_function(cmp,2); val_check_kind(vh,k_hash); h = val_hdata(vh); hkey = val_hash(key) % h->ncells; c = h->cells[hkey]; if( val_is_null(cmp) ) { while( c != NULL ) { if( val_compare(key,c->key) == 0 ) { if( prev == NULL ) h->cells[hkey] = c->next; else prev->next = c->next; h->nitems--; return val_true; } prev = c; c = c->next; } } else { while( c != NULL ) { if( val_call2(cmp,key,c->key) == alloc_int(0) ) { if( prev == NULL ) h->cells[hkey] = c->next; else prev->next = c->next; h->nitems--; return val_true; } prev = c; c = c->next; } } return val_false; }
/** $hset : 'hash -> k:any -> v:any -> cmp:function:2? -> bool <doc> Set the value bound to key [k] to [v] or add it to the hashtable if not found. Return true if the value was added to the hashtable. </doc> **/ static value builtin_hset( value vh, value key, value val, value cmp ) { vhash *h; hcell *c; int hkey; if( !val_is_null(cmp) ) val_check_function(cmp,2); val_check_kind(vh,k_hash); h = val_hdata(vh); hkey = val_hash(key); c = h->cells[hkey % h->ncells]; if( val_is_null(cmp) ) { while( c != NULL ) { if( val_compare(key,c->key) == 0 ) { c->val = val; return val_false; } c = c->next; } } else { while( c != NULL ) { if( val_call2(cmp,key,c->key) == alloc_int(0) ) { c->val = val; return val_false; } c = c->next; } } if( h->nitems >= (h->ncells << 1) ) builtin_hresize(vh,alloc_int(h->ncells << 1)); c = (hcell*)alloc(sizeof(hcell)); c->hkey = hkey; c->key = key; c->val = val; hkey %= h->ncells; c->next = h->cells[hkey]; h->cells[hkey] = c; h->nitems++; return val_true; }
/** $hmem : 'hash -> k:any -> cmp:function:2? -> bool <doc> Look for the value bound to the key [k] in the hashtable. Use the comparison function [cmp] or [$compare] if [null]. Return true if such value exists, false either. </doc> **/ static value builtin_hmem( value vh, value key, value cmp ) { vhash *h; hcell *c; if( !val_is_null(cmp) ) val_check_function(cmp,2); val_check_kind(vh,k_hash); h = val_hdata(vh); c = h->cells[val_hash(key) % h->ncells]; if( val_is_null(cmp) ) { while( c != NULL ) { if( val_compare(key,c->key) == 0 ) return val_true; c = c->next; } } else { while( c != NULL ) { if( val_call2(cmp,key,c->key) == alloc_int(0) ) return val_true; c = c->next; } } return val_false; }
static value inputandroid_initialize(value onTouchBatchStartCallback, value onTouchCallback, value setCachedVariables) { val_check_function(onTouchBatchStartCallback, 1); // Is Func ? if (__onTouchBatchStartCallback == NULL) { __onTouchBatchStartCallback = alloc_root(); } *__onTouchBatchStartCallback = onTouchBatchStartCallback; val_check_function(onTouchCallback, 1); // Is Func ? if (__onTouchCallback == NULL) { __onTouchCallback = alloc_root(); } *__onTouchCallback = onTouchCallback; __touchValue = alloc_abstract(0, &__touch); __touchCountValue = alloc_abstract(0, &__touchCount); val_call2(setCachedVariables, __touchValue, __touchCountValue); return alloc_null(); }
void gamepadEvent(Gamepad::GamepadEvent event, Gamepad *gamepad) { val_call2(clbkGamepadEvent.get(), EnumToValue(event), ObjectToValue(gamepad, false)); }
static int ms_compare( m_sort *m, int a, int b ) { value v = val_call2(m->cmp,m->arr[a],m->arr[b]); if( !val_is_int(v) ) return -1; return val_int(v); }
void keyEvent(Keyboard::KeyEvent event, int key) { val_call2(clbkKeyEvent.get(), EnumToValue(event), alloc_int(key)); }
value hxfcgi_parse_multipart_neko(value hreq, value onpart, value ondata ) { val_check_kind(hreq,hxRequest); val_check_function(onpart,2); val_check_function(ondata,3); hxfcgi::Request *req = get_request(hreq); char *buf; int len = 0; char *boundstr; hxfcgi::BasicData b; string ctype = b.getHeader("CONTENT_TYPE"); if(ctype.find("multipart/form-data") != 0) return val_null; // extract boundary value { const char *boundary, *bend; if( (boundary = strstr(ctype.c_str(),"boundary=")) == NULL ) neko_error(); boundary += 9; PARSE_HEADER(boundary,bend); len = (int)(bend - boundary); boundstr = (char *) malloc(sizeof(char) * (len+3)); if( strlen(boundstr) > BUFSIZE / 2 ) neko_error(); boundstr[0] = '-'; boundstr[1] = '-'; memcpy(boundstr+2,boundary,len); boundstr[len+2] = 0; } len = 0; buf = (char *) malloc(sizeof(char) * (BUFSIZE)); while( true ) { char *name, *end_name, *filename, *end_file_name, *data; int pos; // refill buffer // we assume here that the the whole multipart header can fit in the buffer req->bufferFill(buf,&len); // is boundary at the beginning of buffer ? if( len < (int) strlen(boundstr) || memcmp(buf,boundstr,strlen(boundstr)) != 0 ) { free(boundstr); free(buf); return val_null; } name = memfind(buf,len,"Content-Disposition:"); if( name == NULL ) break; name = memfind(name,len - (int)(name - buf),"name="); if( name == NULL ) { free(boundstr); free(buf); return val_null; } name += 5; PARSE_HEADER(name,end_name); data = memfind(end_name,len - (int)(end_name - buf),"\r\n\r\n"); if( data == NULL ) { free(boundstr); free(buf); return val_null; } filename = memfind(name,(int)(data - name),"filename="); if( filename != NULL ) { filename += 9; PARSE_HEADER(filename,end_file_name); } data += 4; pos = (int)(data - buf); // send part name val_call2(onpart,copy_string(name,(int)(end_name - name)),filename?copy_string(filename,(int)(end_file_name - filename)):val_null); // read data while( true ) { const char *boundary; // recall buffer memcpy(buf,buf+pos,len - pos); len -= pos; pos = 0; req->bufferFill(buf,&len); // lookup bounds boundary = memfind(buf,len,boundstr); if( boundary == NULL ) { if( len == 0 ) { free(boundstr); free(buf); return val_null; } // send as much buffer as possible to client if( len < BUFSIZE ) pos = len; else pos = len - strlen(boundstr) + 1; val_call3(ondata,copy_string(buf,pos),alloc_int(0),alloc_int(pos)); } else { // send remaining data pos = (int)(boundary - buf); val_call3(ondata,copy_string(buf,pos-2),alloc_int(0),alloc_int(pos-2)); // recall memcpy(buf,buf+pos,len - pos); len -= pos; break; } } } free(boundstr); free(buf); return val_null; }
/** parse_multipart_data : onpart:function:2 -> ondata:function:3 -> void <doc> Incrementally parse the multipart data. call [onpart(name,filename)] for each part found and [ondata(buf,pos,len)] when some data is available </doc> **/ static value parse_multipart_data( value onpart, value ondata ) { value buf; int len = 0; mcontext *c = CONTEXT(); const char *ctype = ap_table_get(c->r->headers_in,"Content-Type"); value boundstr; val_check_function(onpart,2); val_check_function(ondata,3); buf = alloc_empty_string(BUFSIZE); if( !ctype || strstr(ctype,"multipart/form-data") == NULL ) return val_null; // extract boundary value { const char *boundary, *bend; if( (boundary = strstr(ctype,"boundary=")) == NULL ) neko_error(); boundary += 9; PARSE_HEADER(boundary,bend); len = (int)(bend - boundary); boundstr = alloc_empty_string(len+2); if( val_strlen(boundstr) > BUFSIZE / 2 ) neko_error(); val_string(boundstr)[0] = '-'; val_string(boundstr)[1] = '-'; memcpy(val_string(boundstr)+2,boundary,len); } len = 0; if( !ap_should_client_block(c->r) ) neko_error(); while( true ) { char *name, *end_name, *filename, *end_file_name, *data; int pos; // refill buffer // we assume here that the the whole multipart header can fit in the buffer fill_buffer(c,buf,&len); // is boundary at the beginning of buffer ? if( len < val_strlen(boundstr) || memcmp(val_string(buf),val_string(boundstr),val_strlen(boundstr)) != 0 ) return discard_body(c); name = memfind(val_string(buf),len,"Content-Disposition:"); if( name == NULL ) break; name = memfind(name,len - (int)(name - val_string(buf)),"name="); if( name == NULL ) return discard_body(c); name += 5; PARSE_HEADER(name,end_name); data = memfind(end_name,len - (int)(end_name - val_string(buf)),"\r\n\r\n"); if( data == NULL ) return discard_body(c); filename = memfind(name,(int)(data - name),"filename="); if( filename != NULL ) { filename += 9; PARSE_HEADER(filename,end_file_name); } data += 4; pos = (int)(data - val_string(buf)); // send part name val_call2(onpart,copy_string(name,(int)(end_name - name)),filename?copy_string(filename,(int)(end_file_name - filename)):val_null); // read data while( true ) { const char *boundary; // recall buffer memmove(val_string(buf),val_string(buf)+pos,len - pos); len -= pos; pos = 0; fill_buffer(c,buf,&len); // lookup bounds boundary = memfind(val_string(buf),len,val_string(boundstr)); if( boundary == NULL ) { if( len == 0 ) return discard_body(c); // send as much buffer as possible to client if( len < BUFSIZE ) pos = len; else pos = len - val_strlen(boundstr) + 1; val_call3(ondata,buf,alloc_int(0),alloc_int(pos)); } else { // send remaining data pos = (int)(boundary - val_string(buf)); val_call3(ondata,buf,alloc_int(0),alloc_int(pos-2)); // recall memmove(val_string(buf),val_string(buf)+pos,len - pos); len -= pos; break; } } } return val_null; }
void gestureTapEvent(int x, int y) { val_call2(clbkGestureTapEvent.get(), alloc_int(x), alloc_int(y)); }
value api_val_call2(value arg1,value arg2,value arg3) { return val_call2(arg1,arg2,arg3); }