Esempio n. 1
0
/**
	regexp_matched_pos : 'regexp -> n:int -> { pos => int, len => int }
	<doc>Return the [n]th matched block position by the regexp. If [n] is 0 then
	return the whole matched substring position</doc>
**/
static value regexp_matched_pos( value o, value n ) {
	pcredata *d;
	int m;
	val_check_kind(o,k_regexp);	
	d = PCRE(o);
	val_check(n,int);
	m = val_int(n);
	if( m < 0 || m >= d->nmatchs || val_is_null(d->str) )
		return alloc_null();
	{
		int start = d->matchs[m*2];
		int len = d->matchs[m*2+1] - start;
		value o = alloc_empty_object();
		alloc_field(o,id_pos,alloc_int(start));
		alloc_field(o,id_len,alloc_int(len));
		return o;
	}
}
Esempio n. 2
0
/**
	socket_send_char : 'socket -> int -> void
	<doc>Send a character over a connected socket. Must be in the range 0..255</doc>
**/
static value socket_send_char( value o, value v ) {
	int c;
	unsigned char cc;
        SOCKET sock = val_sock(o);
	val_check(v,int);
	c = val_int(v);
	if( c < 0 || c > 255 )
		return alloc_null();
	cc = (unsigned char)c;
	gc_enter_blocking();
	POSIX_LABEL(send_char_again);
	if( send(sock,(const char *)&cc,1,MSG_NOSIGNAL) == SOCKET_ERROR ) {
		HANDLE_EINTR(send_char_again);
		return block_error();
	}
	gc_exit_blocking();
	return alloc_bool(true);
}
Esempio n. 3
0
value lime_al_gen_buffers (value n) {

    int count = val_int (n);
    ALuint* buffers = new ALuint[count];

    alGenBuffers (count, buffers);

    value result = alloc_array (count);

    for (int i = 0; i < count; ++i) {

        val_array_set_i (result, i, alloc_int (buffers[i]));

    }

    delete [] buffers;
    return result;

}
Esempio n. 4
0
	void lime_al_source_pausev (int n, value sources) {
		
		if (val_is_null (sources) == false) {
			
			int size = val_array_size (sources);
			ALuint* data = new ALuint[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALuint)val_int( val_array_i (sources, i) );
				
			}
			
			alSourcePausev (n, data);
			
			delete[] data;
			
		}
	}
Esempio n. 5
0
value wx_timer_create(value inOwner,value inID)
{
	wxEvtHandler *handler=0;
   ValueToWX(inOwner,handler);

	if (handler)
	{
      wxClientData *data = handler->GetClientObject();
      if (data)
      {
         HaxeEventHandler *haxe = (HaxeEventHandler *)data;
			handler = haxe;
		}
	}

	wxTimer *timer = new wxTimer( handler, val_int(inID) );

	return WXToDeletingValue(timer);
}
Esempio n. 6
0
/**
	$hresize : 'hash -> int -> void
	<doc>Resize an hashtable</doc>
**/
static value builtin_hresize( value vh, value size ) {
	vhash *h;
	hcell **cc;
	int nsize;
	int i;
	val_check_kind(vh,k_hash);
	val_check(size,int);
	h = val_hdata(vh);
	nsize = val_int(size);
	if( nsize <= 0 )
		nsize = HASH_DEF_SIZE;
	cc = (hcell**)alloc(sizeof(hcell*)*nsize);
	memset(cc,0,sizeof(hcell*)*nsize);
	for(i=0;i<h->ncells;i++)
		add_rec(cc,nsize,h->cells[i]);
	h->cells = cc;
	h->ncells = nsize;
	return val_null;
}
Esempio n. 7
0
/**
	host_reverse : 'int32 -> string
	<doc>Reverse the DNS of the given IP address.</doc>
**/
static value host_reverse( value host ) {
	struct hostent *h;
	unsigned int ip;
	val_check(host,int);
	ip = val_int(host);
   gc_enter_blocking();
#	if defined(NEKO_WINDOWS) || defined(NEKO_MAC) || defined(ANDROID) || defined(BLACKBERRY)
	h = gethostbyaddr((char *)&ip,4,AF_INET);
#	else
	struct hostent htmp;
	int errcode;
	char buf[1024];
	gethostbyaddr_r((char *)&ip,4,AF_INET,&htmp,buf,1024,&h,&errcode);
#	endif
   gc_exit_blocking();
	if( h == NULL )
		return alloc_null();
	return alloc_string( h->h_name );
}
Esempio n. 8
0
/**
	$sfind : src:string -> pos:int -> pat:string -> int?
	<doc>
	Return the first position starting at [pos] in [src] where [pat] was found.
	Return null if not found. Error if [pos] is outside [src] bounds.
	</doc>
**/
static value builtin_sfind( value src, value pos, value pat ) {
	int p, l, l2;
	const char *ptr;
	val_check(src,string);
	val_check(pos,int);
	val_check(pat,string);
	p = val_int(pos);
	l = val_strlen(src);
	l2 = val_strlen(pat);
	if( p < 0 || p >= l )
		neko_error();
	ptr = val_string(src) + p;
	while( l - p >= l2 ) {
		if( memcmp(ptr,val_string(pat),l2) == 0 )
			return alloc_int(p);
		p++;
		ptr++;
	}
	return val_null;
}
Esempio n. 9
0
/**
	regexp_matched : 'regexp -> n:int -> string?
	<doc>Return the [n]th matched block by the regexp. If [n] is 0 then return 
	the whole matched substring. If the [n]th matched block was optional and not matched, returns null</doc>
**/
static value regexp_matched( value o, value n ) {
	pcredata *d;
	int m;
	val_check_kind(o,k_regexp);	
	d = PCRE(o);
	val_check(n,int);
	m = val_int(n);
	if( m < 0 || m >= d->nmatchs || val_is_null(d->str) )
		neko_error();
	{
		int start = d->matchs[m*2];
		int len = d->matchs[m*2+1] - start;
		value str;
		if( start == -1 )
			return val_null;
		str = alloc_empty_string(len);
		memcpy((char*)val_string(str),val_string(d->str)+start,len);
		return str;
	}
}
Esempio n. 10
0
	void lime_al_sourceiv (int source, int param, value values) {
		
		if (val_is_null (values) == false) {
			
			int size = val_array_size (values);
			ALint* data = new ALint[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALint)val_int( val_array_i (values, i) );
				
			}
			
			alSourceiv (source, param, data);
			
			delete[] data;
			
		}
		
	}
Esempio n. 11
0
	void lime_al_source_queue_buffers (int source, int nb, value buffers) {
		
		if (val_is_null (buffers) == false) {
			
			int size = val_array_size (buffers);
			ALuint* data = new ALuint[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALuint)val_int( val_array_i (buffers, i) );
				
			}
			
			alSourceQueueBuffers (source, nb, data);
			
			delete[] data;
			
		}
		
	}
Esempio n. 12
0
	void lime_al_delete_buffers (int n, value buffers) {
		
		if (val_is_null (buffers) == false) {
			
			int size = val_array_size (buffers);
			ALuint* data = new ALuint[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALuint)val_int( val_array_i (buffers, i) );
				
			}
			
			alDeleteBuffers (n, data);
			
			delete[] data;
			
		}
		
	}
Esempio n. 13
0
/**
	sys_create_dir : string -> mode:int -> void
	<doc>Create a directory with the specified rights</doc>
**/
static value sys_create_dir( value path, value mode ) {
	#ifdef EPPC
	return alloc_bool(true);
	#else
	val_check(path,string);
	val_check(mode,int);
	gc_enter_blocking();
#ifdef NEKO_WINDOWS
	if( mkdir(val_string(path)) != 0 )
#else
	if( mkdir(val_string(path),val_int(mode)) != 0 )
#endif
	{
		gc_exit_blocking();
		return alloc_null();
	}
	gc_exit_blocking();
	return alloc_bool(true);
	#endif
}
Esempio n. 14
0
static void test_max(Tuple *tuples[])
{
    Sum *s_int = sum_max(0, Int, val_new_int(&res.defi));
    Sum *s_real = sum_max(1, Real, val_new_real(&res.defd));
    Sum *s_long = sum_max(2, Long, val_new_long(&res.defl));

    calc(tuples, s_int, s_real, s_long);

    if (res.max_int != val_int(sum_value(s_int)))
        fail();
    if (res.max_real != val_real(sum_value(s_real)))
        fail();
    if (res.max_long != val_long(sum_value(s_long)))
        fail();

    test_defs(s_int, s_real, s_long);

    mem_free(s_int);
    mem_free(s_real);
    mem_free(s_long);
}
Esempio n. 15
0
	// TODO: check if this is right
	// sync with udpr_connect() below
static value populate_address(ENetAddress *a, value ip, value port) {
	if(!val_is_null(ip))
		val_check(ip,int32);
	val_check(port,int);

	if(!val_is_null(ip) && val_int32(ip) != 0) {
		a->host = val_int32(ip);
		//a->host = htonl(val_int32(ip));
	}
	else {
#ifdef ENET_DEBUG
		fprintf(stderr, "populate_address: null ip\n");
#endif
		a->host = ENET_HOST_ANY;
	}
	a->port = val_int(port); //htons(val_int(port))
#ifdef ENET_DEBUG
	fprintf(stderr, "populate_address: %x:%u from %x:%u\n", a->host, a->port, val_is_null(ip)?0:val_int32(ip),val_int(port));
#endif
	return val_true;
}
Esempio n. 16
0
        value snow_iosrc_file_read(value _handle, value _dest, value _size, value _maxnum) {

            snow::io::iosrc_file* iosrc = snow::from_hx<snow::io::iosrc_file>( _handle );
            QuickVec<unsigned char> buffer;

            if( iosrc ) {

                if(!val_is_null(_dest)) {

                    ByteArray dest(_dest);

                    int res = snow::io::read(iosrc->file_source, dest.Bytes(), val_int(_size), val_int(_maxnum));

                    return alloc_int(res);
                }

            } //object from hx

            return alloc_int(-1);

        } DEFINE_PRIM(snow_iosrc_file_read, 4);
Esempio n. 17
0
value hx_zmq_getintsockopt(value socket_handle_,value option_) {

	val_check_kind(socket_handle_, k_zmq_socket_handle);

	if (!val_is_int(option_)) {
		val_throw(alloc_int(EINVAL));
		return alloc_null();
	}

	int rc = 0;
	int err = 0;
	uint64_t optval = 0;
	size_t optvallen = sizeof(optval);
	rc = zmq_getsockopt(val_data(socket_handle_),val_int(option_),&optval, &optvallen);
	err = zmq_errno();
	if (rc != 0) {
		val_throw(alloc_int(err));
		return alloc_int(0);
	}		
	return alloc_int(optval);
}
Esempio n. 18
0
	value lime_system_get_directory (value type, value company, value title) {
		
		const char* companyName = "";
		const char* titleName = "";
		
		if (!val_is_null (company)) companyName = val_string (company);
		if (!val_is_null (title)) titleName = val_string (title);
		
		const char* directory = System::GetDirectory ((SystemDirectory)val_int (type), companyName, titleName);
		
		if (directory) {
			
			return alloc_string (directory);
			
		} else {
			
			return alloc_null ();
			
		}
		
	}
Esempio n. 19
0
/**
	inflate_init : window_size:int? -> 'istream
	<doc>Open a decompression stream</doc>
**/
static value inflate_init( value wsize ) {
	z_stream *z;
	value s;
	int err;
	int wbits;
	if( val_is_null(wsize) )
		wbits = MAX_WBITS;
	else {
		val_check(wsize,int);
		wbits = val_int(wsize);
	}
	z = (z_stream*)malloc(sizeof(z_stream) + sizeof(int));
	memset(z,0,sizeof(z_stream));
	val_flush(z) = Z_NO_FLUSH;
	if( (err = inflateInit2(z,wbits)) != Z_OK ) {
		free(z);
		zlib_error(NULL,err);
	}
	s = alloc_abstract(k_stream_inf,z);
	//val_gc(s,free_stream_inf);
	return s;
}
Esempio n. 20
0
value hx_zmq_construct_socket (value context_handle,value type)
{
	val_is_kind(context_handle,k_zmq_context_handle);
	if (!val_is_int(type)) {
		val_throw(alloc_int(EINVAL));
		return alloc_null();
	}
		
	void *s = zmq_socket (val_data(context_handle),val_int(type));
	int err = zmq_errno();
	
	if (s == NULL) {
		val_throw (alloc_int(err));
		return alloc_null();
	}
	
	// See: http://nekovm.org/doc/ffi#abstracts_and_kinds
	value v =  alloc_abstract(k_zmq_socket_handle,s);
	val_gc(v,finalize_socket);		// finalize_socket is called when the abstract value is garbage collected
	return v;
	
}
Esempio n. 21
0
/**
        socket_bind : host : int32 -> port:int -> connections:int -> incoming:int32 -> outgoing:int32 -> bool
        <doc>Bind a UDPR socket for server usage on the given host and port, with max connections,
        incoming bandwidth limited to bytes per second or 0 for unlimited, outgoing also. Host may be
        val_type_null, in which case the binding is to ENET_HOST_ANY
        </doc>
**/
static value udpr_bind( value ip, value port, value connections, value incoming, value outgoing ) {
	ENetAddress address;
	ENetHost *s;
	val_check(connections,int);
	val_check(incoming,int32);
	val_check(outgoing,int32);
	if(populate_address(& address, ip, port) != val_true)
		neko_error();

	s = enet_host_create(	&address,
							(size_t)val_int(connections), 		/* number of clients and/or outgoing connections */
							(enet_uint32)val_int32(incoming),	/* amount of incoming bandwidth in Bytes/sec */
							(enet_uint32)val_int32(outgoing));
	if(s == NULL)
		neko_error();
	value v = alloc_abstract(k_udprhost,s);
	val_gc(v, destroy_enethost);
#ifdef ENET_DEBUG
	fprintf(stderr, "udpr_bind: complete\n");
#endif
	return v;
}
Esempio n. 22
0
static const cst_val *asyl_in(const cst_item *syl)
{
    /* Number of accented syllables since last major break */
    const cst_item *ss,*p,*fs;
    int c;

    ss = item_as(syl,"Syllable");

    fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughter.R:SylStructure.daughter");

    for (c=0, p=ss; 
	 p && (c < CST_CONST_INT_MAX); 
	 p=item_prev(p))
    {
	if (val_int(accented(p)) == 1)
	    c++;
	if (item_equal(p,fs))
	    break;
    }
    
    return val_string_n(c);
}
Esempio n. 23
0
void NekoCodeChunk::neko_dump(std::string const & indent) const {
	for (const_iterator it = begin();
		 it != end();
		 ++it)
		{
			std::cout << indent << it->first << ": ";
			print_neko_instruction((OPCODE) it->second.first, it->second.second, parameter_table[it->second.first]);

			std::cout << "; // ";
			{
				int ppc = (int)((int_val *)it->first - m->code);
				int idx = m->dbgidxs[ppc>>5].base + bitcount(m->dbgidxs[ppc>>5].bits >> (31 - (ppc & 31)));
				value s = val_array_ptr(m->dbgtbl)[idx];
				if( val_is_string(s) )
					printf("%s",val_string(s));
				else if( val_is_array(s) && val_array_size(s) == 2 && val_is_string(val_array_ptr(s)[0]) && val_is_int(val_array_ptr(s)[1]) )
					printf("file %s line %d",val_string(val_array_ptr(s)[0]),val_int(val_array_ptr(s)[1]));
				else
					printf("???");
			}
			std::cout << std::endl;
		}
}
Esempio n. 24
0
// -----------------------------------------------------------------------------
// ObjectEditPanel class constructor
// -----------------------------------------------------------------------------
ObjectEditPanel::ObjectEditPanel(wxWindow* parent) : wxPanel(parent)
{
	wxIntegerValidator<int>          val_int(nullptr, wxNUM_VAL_DEFAULT);
	wxIntegerValidator<unsigned int> val_uint(nullptr, wxNUM_VAL_DEFAULT);
	wxFloatingPointValidator<double> val_double(2, nullptr, wxNUM_VAL_DEFAULT);
	auto                             tb_size = WxUtils::scaledSize(64, -1);

	// Create controls
	text_xoff_      = new wxTextCtrl(this, -1, "", wxDefaultPosition, tb_size, 0, val_int);
	text_yoff_      = new wxTextCtrl(this, -1, "", wxDefaultPosition, tb_size, 0, val_int);
	text_scalex_    = new wxTextCtrl(this, -1, "", wxDefaultPosition, tb_size, 0, val_uint);
	text_scaley_    = new wxTextCtrl(this, -1, "", wxDefaultPosition, tb_size, 0, val_uint);
	combo_rotation_ = new wxComboBox(this, -1, "", wxDefaultPosition, tb_size);
	cb_mirror_x_    = new wxCheckBox(this, -1, "Mirror X");
	cb_mirror_y_    = new wxCheckBox(this, -1, "Mirror Y");
	btn_preview_    = new SIconButton(this, "eye", "Preview");
	btn_cancel_     = new SIconButton(this, "close", "Cancel");
	btn_apply_      = new SIconButton(this, "tick", "Apply");

	// Init controls
	combo_rotation_->Set(WxUtils::arrayString({ "0", "45", "90", "135", "180", "225", "270", "315" }));
	combo_rotation_->SetValidator(val_double);
	btn_preview_->SetDefault();

	// Layout
	setupLayout();

	// Bind events
	btn_preview_->Bind(wxEVT_BUTTON, &ObjectEditPanel::onBtnPreviewClicked, this);
	btn_cancel_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { KeyBind::pressBind("map_edit_cancel"); });
	btn_apply_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { KeyBind::pressBind("map_edit_accept"); });
	cb_mirror_x_->Bind(wxEVT_CHECKBOX, &ObjectEditPanel::onBtnPreviewClicked, this);
	cb_mirror_y_->Bind(wxEVT_CHECKBOX, &ObjectEditPanel::onBtnPreviewClicked, this);

	// Init layout
	wxWindowBase::Layout();
}
Esempio n. 25
0
value readByte(value a) {
	int fd = val_int(a);
	char buffer[2];

	//---------------------------------------------
	#if defined( TARGET_OSX ) || defined( TARGET_LINUX )
		if(read(fd, buffer, 1) < 0){
			return alloc_null();
		}
	#endif
	//---------------------------------------------

	//---------------------------------------------
	#ifdef TARGET_WIN32
		DWORD nRead;
		if (!ReadFile((HANDLE)fd, buffer, 1, &nRead, 0)){
			return alloc_null();
		}
	#endif
	//---------------------------------------------
	
	buffer[1] = '\0';
	return alloc_int(buffer[0]);
}
Esempio n. 26
0
	void Bytes::Set (value bytes) {
		
		if (val_is_null (bytes)) {
			
			_length = 0;
			_data = 0;
			_value = 0;
			
		} else {
			
			_value = bytes;
			_length = val_int (val_field (bytes, id_length));
			
			if (_length > 0) {
				
				value b = val_field (bytes, id_b);
				
				if (val_is_string (b)) {
					
					_data = (unsigned char*)val_string (b);
					
				} else {
					
					_data = (unsigned char*)buffer_data (val_to_buffer (b));
					
				}
				
			} else {
				
				_data = 0;
				
			}
			
		}
		
	}
Esempio n. 27
0
/**
	inflate_buffer : 'istream -> src:string -> srcpos:int -> dst:string -> dstpos:int -> { done => bool, read => int, write => int }
**/
static value inflate_buffer( value s, value src, value srcpos, value dst, value dstpos ) {
	z_stream *z;
	int err;
	value o;
	val_check_kind(s,k_stream_inf);
	val_check(srcpos,int);

	buffer src_buf = val_to_buffer(src);
	if (!src_buf)
	   hx_failure("invalid source buffer");
	buffer dst_buf = val_to_buffer(dst);
	if (!dst_buf)
	   hx_failure("invalid destination buffer");

	int slen = buffer_size(src_buf);
	int dlen = buffer_size(dst_buf);

	val_check(dstpos,int);
	z = val_stream(s);
	if( val_int(srcpos) < 0 || val_int(dstpos) < 0 )
		return alloc_null();
	slen -= val_int(srcpos);
	dlen -= val_int(dstpos);
	if( slen < 0 || dlen < 0 )
		return alloc_null();

	z->next_in = (Bytef*)buffer_data(src_buf) + val_int(srcpos);
	z->next_out = (Bytef*)buffer_data(dst_buf) + val_int(dstpos);
	z->avail_in = slen;
	z->avail_out = dlen;
	if( (err = inflate(z,val_flush(z))) < 0 )
		zlib_error(z,err);
	z->next_in = NULL;
	z->next_out = NULL;
	o = alloc_empty_object();
	alloc_field(o,id_done,alloc_bool(err == Z_STREAM_END));
	alloc_field(o,id_read,alloc_int((int)(slen - z->avail_in)));
	alloc_field(o,id_write,alloc_int((int)(dlen - z->avail_out)));
	return o;
}
Esempio n. 28
0
File: _ssl.c Progetto: judu/hxssl
value _SSL_set_mode(value ssl, value op) {
	long response = SSL_set_mode((SSL*) val_data(ssl), val_int(op));
	return alloc_best_int(response);
}
Esempio n. 29
0
File: _ssl.c Progetto: judu/hxssl
//int 	SSL_write(SSL *ssl,const void *buf,int num);
value _SSL_write(value ssl, const value buf, value num) {
	return alloc_int(SSL_write((SSL*) val_data(ssl), val_data(buf),
			val_int(num)));
}
Esempio n. 30
0
File: _ssl.c Progetto: judu/hxssl
//int 	SSL_read(SSL *ssl,void *buf,int num);
value _SSL_read(value ssl, value buf, value num) {
	return alloc_int(
			SSL_read((SSL*) val_data(ssl), val_data(buf), val_int(num)));
}