DEFINE_FUNC_1(webp_decode_argb, data_buffer_value) {
        if (!val_is_buffer(data_buffer_value)) {
            val_throw(alloc_string("webp_decode_argb: Expected to be a buffer"));
            return alloc_null();
        }
        buffer data_buffer = val_to_buffer(data_buffer_value);
        int    data_len = buffer_size(data_buffer);
        char  *data_ptr = buffer_data(data_buffer);
        int webp_width = -1, webp_height = -1;
        char *webp_data_ptr = (char *)WebPDecodeARGB((const unsigned char *)data_ptr, data_len, &webp_width, &webp_height);
        int webp_data_len = webp_width * webp_height * 4;

        if (webp_data_ptr == NULL) {
            val_throw(alloc_string("webp_decode_argb: Invalid webp data"));
            return alloc_null();
        }

        buffer webp_buffer = alloc_buffer_len(0);
        buffer_append_sub(webp_buffer, webp_data_ptr, webp_data_len);
        buffer_set_size(webp_buffer, webp_data_len);

        value array = alloc_array(3);
        val_array_set_i(array, 0, alloc_int(webp_width));
        val_array_set_i(array, 1, alloc_int(webp_height));
        val_array_set_i(array, 2, buffer_val(webp_buffer));

        if (webp_data_ptr != NULL) free(webp_data_ptr);

        return array;
    }
Beispiel #2
0
value hxfcgi_get_cookies(value hreq) {
	val_check_kind(hreq,hxRequest);
	hxfcgi::BasicData d;
	string ret = d.getHeader("COOKIE");
	if (ret.compare("")==0)
	return val_null;
	char *k = (char*)ret.c_str();
	char *start, *end;
	value p = val_null, tmp;
	while( (start = strchr(k,'=')) != NULL ) {
		start++;
		end = start;
		while( *end != 0 && *end != '\r' && *end != '\n' && *end != ';' )
			end++;
		tmp = alloc_array(3);
		val_array_set_i(tmp,0,copy_string(k,(int)(start-k-1)));
		val_array_set_i(tmp,1,copy_string(start,(int)(end-start)));
		val_array_set_i(tmp,2,p);
		p = tmp;
		if( *end != ';' || end[1] != ' ' )
			break;
		k = end + 2;
	}
	return p;
}
Beispiel #3
0
static value socket_poll_alloc( value nsocks ) {
	polldata *p;
	int i;
	val_check(nsocks,int);
	p = (polldata*)malloc(sizeof(polldata));
	p->max = val_int(nsocks);
	if( p->max < 0 || p->max > 1000000 )
		return alloc_null();
#	ifdef NEKO_WINDOWS
	{
		p->fdr = (fd_set*)malloc(FDSIZE(p->max));
		p->fdw = (fd_set*)malloc(FDSIZE(p->max));
		p->outr = (fd_set*)malloc(FDSIZE(p->max));
		p->outw = (fd_set*)malloc(FDSIZE(p->max));
		p->fdr->fd_count = 0;
		p->fdw->fd_count = 0;
	}
#	else
	p->fds = (struct pollfd*)malloc(sizeof(struct pollfd) * p->max);
	p->rcount = 0;
	p->wcount = 0;
#	endif
	p->ridx = alloc_array(p->max+1);
	p->widx = alloc_array(p->max+1);
        val_gc_add_root(&p->ridx);
        val_gc_add_root(&p->widx);
	for(i=0;i<=p->max;i++) {
		val_array_set_i(p->ridx,i, alloc_int(-1));
		val_array_set_i(p->widx,i, alloc_int(-1));
	}
	value v = alloc_abstract(k_poll, p);
        val_gc(v,free_sock);
        return v;
}
Beispiel #4
0
static void file_error( const char *msg, fio *f, bool delete_f = false ) {
	gc_exit_blocking();
	value a = alloc_array(2);
	val_array_set_i(a,0,alloc_string(msg));
	val_array_set_i(a,1,alloc_filename(f->name.c_str()));
	if (delete_f)
		delete f;
	val_throw(a);
}
Beispiel #5
0
value hxfcgi_get_params(value hreq) {
	hxfcgi::Request *req = get_request(hreq);
	hxfcgi::Data d;
	map<string,string> params = d.getParams((*req));
	value ret = alloc_array(params.size()*2);
	unsigned int c = 0;
	for (map<string,string>::iterator iter = params.begin(); iter!=params.end(); iter++, c++) {
		val_array_set_i(ret,2*c,alloc_string(iter->first.c_str()));
		val_array_set_i(ret,2*c+1,alloc_string(iter->second.c_str()));
	}
	return ret;
}
Beispiel #6
0
/**
	socket_host : 'socket -> #address
	<doc>Return the socket local address composed of an (host,port) array</doc>
**/
static value socket_host( value o ) {
	SOCKET sock = val_sock(o);
	struct sockaddr_in addr;
	SockLen addrlen = sizeof(addr);
	value ret;
	if( getsockname(sock,(struct sockaddr*)&addr,&addrlen) == SOCKET_ERROR )
		return alloc_null();
	ret = alloc_array(2);
	val_array_set_i(ret,0,alloc_int32(*(int*)&addr.sin_addr));
	val_array_set_i(ret,1,alloc_int(ntohs(addr.sin_port)));
	return ret;
}
Beispiel #7
0
	value lime_al_get_source3f (int source, int param) {
		
		ALfloat val1, val2, val3;
		
		alGetSource3f (source, param, &val1, &val2, &val3);
		
		value result = alloc_array (3);
		val_array_set_i (result, 0, alloc_float (val1));
		val_array_set_i (result, 1, alloc_float (val2));
		val_array_set_i (result, 2, alloc_float (val3));
		return result;
		
	}
Beispiel #8
0
	value lime_al_get_listener3f (int param) {
		
		ALfloat val1, val2, val3;
		
		alGetListener3f (param, &val1, &val2, &val3);
		
		value result = alloc_array (3);
		val_array_set_i (result, 0, alloc_float (val1));
		val_array_set_i (result, 1, alloc_float (val2));
		val_array_set_i (result, 2, alloc_float (val3));
		return result;
		
	}
Beispiel #9
0
	value lime_al_get_buffer3i (int buffer, int param) {
		
		ALint val1, val2, val3;
		
		alGetBuffer3i (buffer, param, &val1, &val2, &val3);
		
		value result = alloc_array (3);
		val_array_set_i (result, 0, alloc_int(val1));
		val_array_set_i (result, 1, alloc_int(val2));
		val_array_set_i (result, 2, alloc_int(val3));
		return result;
		
	}
Beispiel #10
0
value lime_al_get_listener3i (value param) {

    ALint val1, val2, val3;

    alGetListener3i (val_int (param), &val1, &val2, &val3);

    value result = alloc_array (3);
    val_array_set_i (result, 0, alloc_int (val1));
    val_array_set_i (result, 1, alloc_int (val2));
    val_array_set_i (result, 2, alloc_int (val3));
    return result;

}
Beispiel #11
0
value lime_al_get_source3f (value source, value param) {

    ALfloat val1, val2, val3;

    alGetBuffer3f (val_int (source), val_int (param), &val1, &val2, &val3);

    value result = alloc_array (3);
    val_array_set_i (result, 0, alloc_float (val1));
    val_array_set_i (result, 1, alloc_float (val2));
    val_array_set_i (result, 2, alloc_float (val3));
    return result;

}
Beispiel #12
0
value lime_al_get_source3i (value source, value param) {

    ALint val1, val2, val3;

    alGetSource3i (val_int (source), val_int (param), &val1, &val2, &val3);

    value result = alloc_array (3);
    val_array_set_i (result, 1, alloc_int (val1));
    val_array_set_i (result, 2, alloc_int (val2));
    val_array_set_i (result, 3, alloc_int (val3));
    return result;

}
Beispiel #13
0
/**
	socket_poll_prepare : 'poll -> read:'socket array -> write:'socket array -> int array array
	<doc>
	Prepare a poll for scanning events on sets of sockets.
	</doc>
**/
static value socket_poll_prepare( value pdata, value rsocks, value wsocks ) {
	polldata *p;
	int i,len;
	val_check(rsocks,array);
	val_check(wsocks,array);
	val_check_kind(pdata,k_poll);
	p = val_poll(pdata);
	len = val_array_size(rsocks);
	if( len + val_array_size(wsocks) > p->max )
		val_throw(alloc_string("Too many sockets in poll"));
#	ifdef NEKO_WINDOWS
	for(i=0;i<len;i++) {
		value s = val_array_i(rsocks,i);
		p->fdr->fd_array[i] = val_sock(s);
	}
	p->fdr->fd_count = len;
	len = val_array_size(wsocks);
	for(i=0;i<len;i++) {
		value s = val_array_i(wsocks,i);
		p->fdw->fd_array[i] = val_sock(s);
	}
	p->fdw->fd_count = len;
#	else
	for(i=0;i<len;i++) {
		value s = val_array_i(rsocks,i);
		p->fds[i].fd = val_sock(s);
		p->fds[i].events = POLLIN;
		p->fds[i].revents = 0;
	}
	p->rcount = len;
	len = val_array_size(wsocks);
	for(i=0;i<len;i++) {
		int k = i + p->rcount;
		value s = val_array_i(wsocks,i);
		p->fds[k].fd = val_sock(s);
		p->fds[k].events = POLLOUT;
		p->fds[k].revents = 0;
	}
	p->wcount = len;
#	endif
	{
		value a = alloc_array(2);
		val_array_set_i(a,0, p->ridx);
		val_array_set_i(a,1, p->widx);
		return a;
	}
}
Beispiel #14
0
/**
	socket_poll_events : 'poll -> timeout:float -> void
	<doc>
	Update the read/write flags arrays that were created with [socket_poll_prepare].
	</doc>
**/
static value socket_poll_events( value pdata, value timeout ) {
	polldata *p;
#	ifdef NEKO_WINDOWS
	unsigned int i;
	int k = 0;
	struct timeval t;
	val_check_kind(pdata,k_poll);
	p = val_poll(pdata);
	memcpy(p->outr,p->fdr,FDSIZE(p->fdr->fd_count));
	memcpy(p->outw,p->fdw,FDSIZE(p->fdw->fd_count));
	val_check(timeout,number);
	init_timeval(val_number(timeout),&t);
	gc_enter_blocking();
	if( p->fdr->fd_count + p->fdw->fd_count != 0 && select(0,p->outr,p->outw,NULL,&t) == SOCKET_ERROR )
	{
		gc_exit_blocking();
		return alloc_null();
	}
	gc_exit_blocking();
	k = 0;
	for(i=0;i<p->fdr->fd_count;i++)
		if( FD_ISSET(p->fdr->fd_array[i],p->outr) )
			val_array_set_i(p->ridx,k++,alloc_int(i));
	val_array_set_i(p->ridx,k,alloc_int(-1));
	k = 0;
	for(i=0;i<p->fdw->fd_count;i++)
		if( FD_ISSET(p->fdw->fd_array[i],p->outw) )
			val_array_set_i(p->widx,k++, alloc_int(i));
	val_array_set_i(p->widx,k,alloc_int(-1));
#else
	int i,k;
	int tot;
	val_check_kind(pdata,k_poll);
	val_check(timeout,number);
	p = val_poll(pdata);
	tot = p->rcount + p->wcount;
	gc_enter_blocking();
	POSIX_LABEL(poll_events_again);
	if( poll(p->fds,tot,(int)(val_number(timeout) * 1000)) < 0 ) {
		HANDLE_EINTR(poll_events_again);
		gc_exit_blocking();
		return alloc_null();
	}
	gc_exit_blocking();
	k = 0;
	for(i=0;i<p->rcount;i++)
		if( p->fds[i].revents & (POLLIN|POLLHUP) )
			val_array_set_i(p->ridx,k++,alloc_int(i));
	val_array_set_i(p->ridx,k, alloc_int(-1));
	k = 0;
	for(;i<tot;i++)
		if( p->fds[i].revents & (POLLOUT|POLLHUP) )
			val_array_set_i(p->widx,k++, alloc_int(i - p->rcount));
	val_array_set_i(p->widx,k, alloc_int(-1));
#endif
	return val_null;
}
    DEFINE_FUNC_1(webp_get_features, data_buffer_value) {
        if (!val_is_buffer(data_buffer_value)) {
            val_throw(alloc_string("webp_get_features: Expected to be a buffer"));
            return alloc_null();
        }
        buffer data_buffer = val_to_buffer(data_buffer_value);
        int    data_len = buffer_size(data_buffer);
        char  *data_ptr = buffer_data(data_buffer);

        WebPBitstreamFeatures features = {0};
        VP8StatusCode code = WebPGetFeatures((const unsigned char *)data_ptr, data_len, &features);

        if (code != VP8_STATUS_OK) {
            val_throw(alloc_string("webp_get_features: Error: (code != VP8_STATUS_OK)"));
            return alloc_null();
        }

        value array = alloc_array(7);
        val_array_set_i(array, 0, alloc_int(features.width));
        val_array_set_i(array, 1, alloc_int(features.height));
        val_array_set_i(array, 2, alloc_int(features.has_alpha));
        //val_array_set_i(array, 3, alloc_int(features.bitstream_version));
        val_array_set_i(array, 3, alloc_int(0));
        val_array_set_i(array, 4, alloc_int(features.no_incremental_decoding));
        val_array_set_i(array, 5, alloc_int(features.rotate));
        val_array_set_i(array, 6, alloc_int(features.uv_sampling));
        return array;
    }
Beispiel #16
0
value rtmidi_in_getmessage(value obj) {
  RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
  std::vector<unsigned char> message;
  double stamp = midiin->getMessage(&message);
  // ignore stamp for now
  value ret = alloc_array(message.size());
  for (int i = 0; i < message.size(); ++i) {
    val_array_set_i(ret, i, alloc_int(message[i]));
  }
  return ret;
}
Beispiel #17
0
static value dialogs_open_file( value title, value msg, value initialdir, value mask,value multi) {
	value result = val_null;
	struct ARG_FILEFILTERS filters = {0,0,0};
	struct RES_STRINGLIST files;

	val_check(title,string);
	val_check(msg,string);
	val_check(multi,bool);
	val_check(initialdir, string);
	
	if (val_is_object(mask)) {
		value count = val_field(mask,val_id("count"));
		value descriptions = val_field(mask,val_id("descriptions"));
		value extensions = val_field(mask,val_id("extensions"));

		val_check(count,int);
		val_check(descriptions,array);
		val_check(extensions,array);

		filters.count = val_int(count);
		if (filters.count) {
			long i = filters.count;
			filters.descriptions = (const char**) malloc(i*sizeof(char*));
			filters.extensions = (const char**) malloc(i*sizeof(char*));
			while(i) {
				i--;
				filters.descriptions[i] = val_string(val_array_i(descriptions,i));
				filters.extensions[i] = val_string(val_array_i(extensions,i));
			}
		}
	}
	
	systools_dialogs_open_file(val_string(title),val_string(msg),val_string(initialdir),filters.count? &filters : NULL ,val_bool(multi) ,&files);
	if (files.count) {
		result = alloc_array(files.count);
		while(files.count) {
			files.count--;
			val_array_set_i(result, files.count, alloc_string(files.strings[files.count]));
			free(files.strings[files.count]);
		}
		free(files.strings);
	}

	// clean up allocated mem. for filters:
	if (val_is_object(mask)) {
		free(filters.descriptions);
		free(filters.extensions);
	}
	
	
	
	return result;
}
Beispiel #18
0
value hxfcgi_get_all_headers(value hreq) {
	val_check_kind(hreq,hxRequest);	
	hxfcgi::BasicData d;
	list<string> header = d.getAllHeaders();
	list<string>::iterator iter;
	value ret = alloc_array(header.size());
	int c = 0;
	for (iter = header.begin();iter != header.end(); iter++,c++) {
		val_array_set_i(ret,c,alloc_string((*iter).c_str()));
	}
	return ret;
}
Beispiel #19
0
void _rtmidi_in_callback(double deltatime,
                         std::vector<unsigned char> *message,
                         void *userData) {
  int top = 0;
  gc_set_top_of_stack(&top, true);

  value ret = alloc_array(message->size());
  for (int i = 0; i < message->size(); ++i) {
    val_array_set_i(ret, i, alloc_int((*message)[i]));
  }
  val_call1(callback_root->get(), ret);
  gc_set_top_of_stack(0,true);
}
Beispiel #20
0
/**
	socket_select : read : 'socket array -> write : 'socket array -> others : 'socket array -> timeout:number? -> 'socket array array
	<doc>Perform the [select] operation. Timeout is in seconds or [null] if infinite</doc>
**/
static value socket_select( value rs, value ws, value es, value timeout ) {
	struct timeval tval;
	struct timeval *tt;
	SOCKET n = 0;
	fd_set rx, wx, ex;
	fd_set *ra, *wa, *ea;
	value r;
	POSIX_LABEL(select_again);
	ra = make_socket_array(rs,&rx,&n);
	wa = make_socket_array(ws,&wx,&n);
	ea = make_socket_array(es,&ex,&n);
	if( ra == &INVALID || wa == &INVALID || ea == &INVALID )
	{
		val_throw( alloc_string("No valid sockets") );
		return alloc_null();
	}
	if( val_is_null(timeout) )
		tt = NULL;
	else {
		val_check(timeout,number);
		tt = &tval;
		init_timeval(val_number(timeout),tt);
	}
	gc_enter_blocking();
	if( select((int)(n+1),ra,wa,ea,tt) == SOCKET_ERROR ) {
		HANDLE_EINTR(select_again);
		gc_exit_blocking();
		char buf[100];
		sprintf(buf,"Select error %d", errno );
		val_throw( alloc_string(buf) );
	}
	gc_exit_blocking();
	r = alloc_array(3);
	val_array_set_i(r,0,make_array_result(rs,ra));
	val_array_set_i(r,1,make_array_result(ws,wa));
	val_array_set_i(r,2,make_array_result(es,ea));
	return r;
}
Beispiel #21
0
// DECL: void getCorners(Vector3* corners) const;
void hx_Frustum_getCorners(value thisObj, value corners)
{
    Frustum *_thisObj;
    ValueToObject(thisObj, _thisObj);

    Vector3 points[8];
    _thisObj->getCorners(points);

    value _corners = alloc_array(8);
    for (int index = 0; index < 8; index++)
        val_array_set_i(_corners, index, ObjectToValue(new Vector3(points[index])));

    SetOutParameterValue(corners, _corners);
}
Beispiel #22
0
/**
	socket_poll : 'socket array -> 'poll -> timeout:float -> 'socket array
	<doc>
	Perform a polling for data available over a given set of sockets. This is similar to [socket_select]
	except that [socket_select] is limited to a given number of simultaneous sockets to check.
	</doc>
**/
static value socket_poll( value socks, value pdata, value timeout ) {
	polldata *p;
	value a;
	int i, rcount = 0;
	if( val_is_null( socket_poll_prepare(pdata,socks,alloc_array(0))) )
		return alloc_null();
	socket_poll_events(pdata,timeout);
	p = val_poll(pdata);
	while( val_int(val_array_i(p->ridx,rcount)) != -1 )
		rcount++;
	a = alloc_array(rcount);
	for(i=0;i<rcount;i++)
		val_array_set_i(a,i, val_array_i(socks,val_int(val_array_i(p->ridx,i))));
	return a;
}
Beispiel #23
0
static value make_array_result( value a, fd_set *tmp ) {
	value r;
	int i, len;
	int pos = 0;
	if( tmp == NULL )
		return val_null;
	len = val_array_size(a);
	r = alloc_array(len);
	for(i=0;i<len;i++) {
		value s = val_array_i(a,i);
		if( FD_ISSET(val_sock(s),tmp) )
			val_array_set_i(r,pos++,s);
	}
	val_array_set_size(r,pos);
	return r;
}
Beispiel #24
0
	value lime_al_gen_buffers (int n) {
		
		ALuint* buffers = new ALuint[n];
		alGenBuffers (n, buffers);
		
		value result = alloc_array (n);
		
		for (int i = 0; i < n; i++) {
			
			val_array_set_i (result, i, alloc_int (buffers[i]));
			
		}
		
		delete [] buffers;
		return result;
		
	}
Beispiel #25
0
	value lime_al_gen_sources (int n) {
		
		ALuint* sources = new ALuint[n];
		alGenSources (n, sources);
		
		value result = alloc_array (n);
		
		for (int i = 0; i < n; i++) {
			
			val_array_set_i (result, i, alloc_int (sources[i]));
			
		}
		
		delete [] sources;
		return result;
		
	}
Beispiel #26
0
	value lime_al_get_booleanv (int param, int count) {
		
		ALboolean* values = new ALboolean[count];
		alGetBooleanv (param, values);
		
		value result = alloc_array (count);
		
		for (int i = 0; i < count; i++) {
			
			val_array_set_i (result, i, alloc_bool (values[i]));
			
		}
		
		delete [] values;
		return result;
		
	}
Beispiel #27
0
	value lime_al_get_bufferfv (int buffer, int param, int count) {
		
		ALfloat* values = new ALfloat[count];
		alGetBufferfv (buffer, param, values);
		
		value result = alloc_array (count);
		
		for (int i = 0; i < count; ++i) {
			
			val_array_set_i (result, i, alloc_float (values[i]));
			
		}
		
		delete [] values;
		return result;
		
	}
Beispiel #28
0
	value lime_al_get_listenerfv (int param, int count) {
		
		ALfloat* values = new ALfloat[count];
		alGetListenerfv (param, values);
		
		value result = alloc_array (count);
		
		for (int i = 0; i < count; i++) {
			
			val_array_set_i (result, i, alloc_float (values[i]));
			
		}
		
		delete [] values;
		return result;
		
	}
Beispiel #29
0
	value lime_al_get_sourceiv (int source, int param, int count) {
		
		ALint* values = new ALint[count];
		alGetSourceiv (source, param, values);
		
		value result = alloc_array (count);
		
		for (int i = 0; i < count; i++) {
			
			val_array_set_i (result, i, alloc_int (values[i]));
			
		}
		
		delete [] values;
		return result;
		
	}
Beispiel #30
0
	value lime_al_source_unqueue_buffers (int source, int nb) {
		
		ALuint* buffers = new ALuint[nb];
		alSourceUnqueueBuffers (source, nb, buffers);
		
		value result = alloc_array (nb);
		
		for (int i = 0; i < nb; i++) {
			
			val_array_set_i (result, i, alloc_int (buffers[i]));
			
		}
		
		delete [] buffers;
		return result;
		
	}