예제 #1
0
static value socket_set_blocking( value o, value b ) {
	SOCKET sock = val_sock(o);
	val_check(b,bool);
   gc_enter_blocking();
#ifdef NEKO_WINDOWS
	{
		unsigned long arg = val_bool(b)?0:1;
		if( ioctlsocket(sock,FIONBIO,&arg) != 0 )
      {
         gc_exit_blocking();
			return alloc_null();
      }
	}
#else
	{
		int rights = fcntl(sock,F_GETFL);
		if( rights == -1 )
      {
         gc_exit_blocking();
			return alloc_null();
      }
		if( val_bool(b) )
			rights &= ~O_NONBLOCK;
		else
			rights |= O_NONBLOCK;
		if( fcntl(sock,F_SETFL,rights) == -1 )
      {
         gc_exit_blocking();
			return alloc_null();
      }
	}
#endif
   gc_exit_blocking();
	return alloc_bool(true);
}
예제 #2
0
파일: Sys.cpp 프로젝트: Draknek/hxcpp
/**
	sys_getch : bool -> int
	<doc>Read a character from stdin with or without echo</doc>
**/
static value sys_getch( value b ) {
#if defined(HX_WINRT) || defined(EMSCRIPTEN) || defined(EPPC)
   return alloc_null();
#elif defined(NEKO_WINDOWS)
	val_check(b,bool);
	gc_enter_blocking();
	int result = val_bool(b)?getche():getch();
	gc_exit_blocking();
	return alloc_int( result );
#else
	// took some time to figure out how to do that
	// without relying on ncurses, which clear the
	// terminal on initscr()
	int c;
	struct termios term, old;
	val_check(b,bool);
	gc_enter_blocking();
	tcgetattr(fileno(stdin), &old);
	term = old;
	cfmakeraw(&term);
	tcsetattr(fileno(stdin), 0, &term);
	c = getchar();
	tcsetattr(fileno(stdin), 0, &old);
	if( val_bool(b) ) fputc(c,stdout);
	gc_exit_blocking();
	return alloc_int(c);
#	endif
}
예제 #3
0
value flush(value a,value b,value c){
	int fd = val_int(a);
	bool flushIn = val_bool(b);
	bool flushOut = val_bool(c);
	int flushType;

	//---------------------------------------------
	#if defined( TARGET_OSX ) || defined( TARGET_LINUX )
		if( flushIn && flushOut) flushType = TCIOFLUSH;
		else if(flushIn) flushType = TCIFLUSH;
		else if(flushOut) flushType = TCOFLUSH;
		else return alloc_null();

		tcflush(fd, flushType);
	#endif
	//---------------------------------------------

	//---------------------------------------------
	#ifdef TARGET_WIN32
		if( flushIn && flushOut) flushType = PURGE_TXCLEAR | PURGE_RXCLEAR;
		else if(flushIn) flushType = PURGE_RXCLEAR;
		else if(flushOut) flushType = PURGE_TXCLEAR;
		else return alloc_null();

		PurgeComm((HANDLE)fd, flushType);
	#endif
	//---------------------------------------------
	
	return alloc_null();
}
예제 #4
0
파일: others.c 프로젝트: ConstNW/neko
EXTERN int val_compare( value a, value b ) {
	char tmp_buf[32];
	switch( C(val_type(a),val_type(b)) ) {
	case C(VAL_INT,VAL_INT):
		return icmp(val_int(a),val_int(b));
	case C(VAL_INT32,VAL_INT):
		return icmp(val_int32(a),val_int(b));
	case C(VAL_INT,VAL_INT32):
		return icmp(val_int(a),val_int32(b));
	case C(VAL_INT32,VAL_INT32):
		return icmp(val_int32(a),val_int32(b));
	case C(VAL_INT,VAL_FLOAT):
		return fcmp(val_int(a),val_float(b));
	case C(VAL_INT32,VAL_FLOAT):
		return fcmp(val_int32(a),val_float(b));
	case C(VAL_INT,VAL_STRING):
		return scmp(tmp_buf,sprintf(tmp_buf,"%d",val_int(a)),val_string(b),val_strlen(b));
	case C(VAL_INT32,VAL_STRING):
		return scmp(tmp_buf,sprintf(tmp_buf,"%d",val_int32(a)),val_string(b),val_strlen(b));
	case C(VAL_FLOAT,VAL_INT):
		return fcmp(val_float(a),val_int(b));
	case C(VAL_FLOAT,VAL_INT32):
		return fcmp(val_float(a),val_int32(b));
	case C(VAL_FLOAT,VAL_FLOAT):
		return fcmp(val_float(a),val_float(b));
	case C(VAL_FLOAT,VAL_STRING):
		return scmp(tmp_buf,sprintf(tmp_buf,FLOAT_FMT,val_float(a)),val_string(b),val_strlen(b));
	case C(VAL_STRING,VAL_INT):
		return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,"%d",val_int(b)));
	case C(VAL_STRING,VAL_INT32):
		return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,"%d",val_int32(b)));
	case C(VAL_STRING,VAL_FLOAT):
		return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,FLOAT_FMT,val_float(b)));
	case C(VAL_STRING,VAL_BOOL):
		return scmp(val_string(a),val_strlen(a),val_bool(b)?"true":"false",val_bool(b)?4:5);
	case C(VAL_BOOL,VAL_STRING):
		return scmp(val_bool(a)?"true":"false",val_bool(a)?4:5,val_string(b),val_strlen(b));
	case C(VAL_STRING,VAL_STRING):
		return scmp(val_string(a),val_strlen(a),val_string(b),val_strlen(b));
	case C(VAL_BOOL,VAL_BOOL):
		return (a == b) ? 0 : (val_bool(a) ? 1 : -1);
	case C(VAL_OBJECT,VAL_OBJECT):
		if( a == b )
			return 0;
		{
			value tmp = val_field(a,id_compare);
			if( tmp == val_null )
				return invalid_comparison;
			a = val_callEx(a,tmp,&b,1,NULL);
		}
		if( val_is_int(a) )
			return val_int(a);
		return invalid_comparison;
	default:
		if( a == b )
			return 0;
		return invalid_comparison;
	}
}
예제 #5
0
파일: socket.c 프로젝트: motion-twin/neko
/**
	socket_shutdown : 'socket -> read:bool -> write:bool -> void
	<doc>Prevent the socket from further reading or writing or both.</doc>
**/
static value socket_shutdown( value o, value r, value w ) {
	val_check_kind(o,k_socket);
	val_check(r,bool);
	val_check(w,bool);
	if( !val_bool(r) && !val_bool(w) )
		return val_true;
	if( shutdown(val_sock(o),val_bool(r)?(val_bool(w)?SHUT_RDWR:SHUT_RD):SHUT_WR) )
		neko_error();
	return val_true;
}
예제 #6
0
파일: api.c 프로젝트: 0b1kn00b/xcross
static value os_dialog( value title, value msg, value error, value confirm ) {
	int r;
	val_check(title,string);
	val_check(msg,string);
	val_check(error,bool);
	val_check(confirm,bool);
	r = sys_dialog(
		val_string(title),
		val_string(msg),
		(val_bool(error)?DLG_ERROR:0) | (val_bool(confirm)?DLG_CONFIRM:0)
	);
	return alloc_bool(r);
}
예제 #7
0
/**
	socket_shutdown : 'socket -> read:bool -> write:bool -> void
	<doc>Prevent the socket from further reading or writing or both.</doc>
**/
static value socket_shutdown( value o, value r, value w ) {
	SOCKET sock = val_sock(o);
	val_check(r,bool);
	val_check(w,bool);
	if( !val_bool(r) && !val_bool(w) )
		return alloc_bool(true);
	gc_enter_blocking();
	if( shutdown(sock,val_bool(r)?(val_bool(w)?SHUT_RDWR:SHUT_RD):SHUT_WR) )
	{
		gc_exit_blocking();
		return alloc_null();
	}
	gc_exit_blocking();
	return alloc_bool(true);
}
예제 #8
0
파일: misc.c 프로젝트: MattTuttle/neko
/**
	enable_jit : ?bool -> ?bool
	<doc>Enable or disable the JIT. Calling enable_jit(null) tells if JIT is enabled or not</doc>
**/
static value enable_jit( value b ) {
	if( val_is_null(b) )
		return alloc_bool(neko_vm_jit(neko_vm_current(),-1));
	val_check(b,bool);
	neko_vm_jit(neko_vm_current(),val_bool(b));
	return val_null;
}
예제 #9
0
파일: api.cpp 프로젝트: aik6980/systools
static value dialogs_message_box( value title, value msg, value error ) {
	val_check(title,string);
	val_check(msg,string);
	val_check(error,bool);
	systools_dialogs_message_box(val_string(title),val_string(msg),val_bool(error));
	return val_null;
}
예제 #10
0
파일: GL.cpp 프로젝트: ma-gnesium/HxGL
//Be very careful with this, it does not support offsets into buffers yet
value vertexAttribPointer( value *args, int count )
{
	enum {index,size,type,normalized,stride,pointer};
	if (count != 6) 
	{
		throw "vertexAttribPointer invalid parameter length";
	}

	char *ptr = NULL;
	if (val_is_buffer (args[pointer]))
	{
		std::cout << "vertexAttribPointer does not accept data for pointer arg" << std::endl;
		//ptr = buffer_data( val_to_buffer ( args[pointer] ) );
	}
	else if (val_is_int (args[pointer]))
	{
		ptr = ((char *)NULL + val_int(args[pointer]));
	}
	glVertexAttribPointer(
		(GLuint)val_int( args[index] ),
		(GLint)val_int( args[size] ),
		(GLenum)val_int( args[type] ),
		(GLboolean)val_bool( args[normalized] ),
		(GLsizei)val_int( args[stride] ),
		(const GLvoid *)ptr );
	return alloc_null( );
}
예제 #11
0
파일: api.c 프로젝트: 0b1kn00b/xcross
static value os_winlog_set_button( value wnd, value txt, value enabled ) {
	val_check_kind(wnd,k_winlog);
	val_check(txt,string);
	val_check(enabled,bool);
	sys_winlog_set_button(val_window(wnd)->p,val_string(txt),val_bool(enabled));
	return val_null;
}
예제 #12
0
파일: ssl.c 프로젝트: jonasmalacofilho/neko
static value key_from_pem(value data, value pub, value pass){
	mbedtls_pk_context *pk;
	int r, len;
	value v;
	unsigned char *buf;
	val_check(data, string);
	val_check(pub, bool);
	if (!val_is_null(pass)) val_check(pass, string);
	len = val_strlen(data)+1;
	buf = (unsigned char *)alloc(len);
	memcpy(buf, val_string(data), len-1);
	buf[len-1] = '\0';
	pk = (mbedtls_pk_context *)alloc(sizeof(mbedtls_pk_context));
	mbedtls_pk_init(pk);
	if( val_bool(pub) )
		r = mbedtls_pk_parse_public_key( pk, buf, len );
	else if( val_is_null(pass) )
		r = mbedtls_pk_parse_key( pk, buf, len, NULL, 0 );
	else
		r = mbedtls_pk_parse_key( pk, buf, len, (const unsigned char*)val_string(pass), val_strlen(pass) );
	if( r != 0 ){
		mbedtls_pk_free(pk);
		return ssl_error(r);
	}
	v = alloc_abstract(k_pkey,pk);
	val_gc(v,free_pkey);
	return v;
}
예제 #13
0
    value snow_system_lock_cursor(value _enable) {

        snow::window::system_lock_cursor( val_bool(_enable) );

        return alloc_null();

    } DEFINE_PRIM(snow_system_lock_cursor, 1);
예제 #14
0
    value snow_system_enable_vsync( value _enable ) {

        int result = snow::window::system_enable_vsync( val_bool(_enable) );

        return alloc_int( result );

    } DEFINE_PRIM(snow_system_enable_vsync, 1);
예제 #15
0
/**
        udpr_send_char : peer -> data:int -> chan:int -> reliable:bool -> void
        Send a character [ over a connected socket. Must be in the range 0..255</doc>
**/
static value udpr_send_char( value p, value data, value chan, value reliable ) {
	ENetPeer *peer;
	ENetPacket *packet;
	int c,d;
	char buf[2];
	val_check_kind(p,k_udprpeer);
	val_check(data,int);
	val_check(chan,int);
	val_check(reliable,bool);

	peer = (ENetPeer *)val_data(p);
	c = val_int(chan);
    d = val_int(data);

    if( peer == NULL || c < 0 || c > 255 || d < 0 || d > 255 )
        neko_error();
   	buf[0] = (unsigned char)d;
   	buf[1] = '\0';
	packet = enet_packet_create(
		buf,
		1,
		val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
    if(enet_peer_send(peer, c, packet))
		neko_error();
    return val_true;
}
예제 #16
0
	value lime_window_set_enable_text_events (value window, value enabled) {
		
		Window* targetWindow = (Window*)(intptr_t)val_float (window);
		targetWindow->SetEnableTextEvents (val_bool (enabled));
		return alloc_null ();
		
	}
예제 #17
0
/**
	udpr_write : ENetPeer-> data:string -> Channel->Reliable:Bool->void
	Send a full string [data]
**/
static value udpr_write(value p, value data, value chan, value reliable)
{
	ENetPeer *peer;
	ENetPacket *packet;
	int c;
	val_check_kind(p,k_udprpeer);
	val_check(data,string);
	val_check(chan,int);
	val_check(reliable,bool);

	c = val_int(chan);
	peer = (ENetPeer *)val_data(p);
#ifdef ENET_DEBUG_FULL
	fprintf(stderr, "udpr_write: Writing packet '%s' to peer %x on channel %d\n", val_string(data), peer, c);
	fprintf(stderr, "peer state: %d peer channels: %d\n", peer -> state, peer->channelCount);
#endif
	if(peer == NULL || c < 0 || c > 255)
		neko_error();

	packet = enet_packet_create(
		val_string(data),
		val_strlen(data),
		val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
    if(enet_peer_send(peer, c, packet)) {
#ifdef ENET_DEBUG
		fprintf(stderr, "ERROR: udpr_write: enet_peer_send error\n");
		fprintf(stderr, "peer state: %d peer channels: %d\n", peer -> state, peer->channelCount);
#endif
    	neko_error();
    }
	return val_true;
}
예제 #18
0
/**
        udpr_send : peer -> data:string -> pos:int -> len:int -> chan:int -> reliable:bool -> int
        Send up to [len] bytes from [buf] starting at [pos] over a connected socket on channel [chan]
        using reliable setting [reliable]
        Return the number of bytes sent.
**/
static value udpr_send( value p, value data, value pos, value len, value chan, value reliable ) {
	ENetPeer *peer;
	ENetPacket *packet;
	int pp,l,sLen,c;
	val_check_kind(p,k_udprpeer);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	val_check(chan,int);
	val_check(reliable,bool);

	peer = (ENetPeer *)val_data(p);
	pp = val_int(pos);
	l = val_int(len);
	sLen = val_strlen(data);
	c = val_int(chan);
	if( peer == NULL || c < 0 || c > 255 || pp < 0 || l < 0 || pp > sLen || pp + l > sLen )
			neko_error();
	packet = enet_packet_create(
		val_string(data) + pp,
		l,
		val_bool(reliable) ? ENET_PACKET_FLAG_RELIABLE : 0);
	if(enet_peer_send(peer, c, packet))
		neko_error();
	return alloc_int(l);
}
예제 #19
0
파일: Socket.cpp 프로젝트: delahee/hxlibc
value socket_set_fast_send( value o, value b )
{
	SOCKET sock = val_sock(o);
	val_check(b,bool);
   int fast = val_bool(b);
   setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&fast,sizeof(fast));
   return alloc_null();
}
예제 #20
0
파일: api.cpp 프로젝트: aik6980/systools
static value dialogs_dialog_box( value title, value msg, value error ) {
	int r;
	val_check(title,string);
	val_check(msg,string);
	val_check(error,bool);
	r = systools_dialogs_dialog_box(val_string(title),val_string(msg),val_bool(error));
	return alloc_bool(r);
}
예제 #21
0
파일: misc.c 프로젝트: MattTuttle/neko
/**
	run_gc : major:bool -> void
	<doc>Run the Neko garbage collector</doc>
**/
static value run_gc( value b ) {
	val_check(b,bool);
	if( val_bool(b) )
		neko_gc_major();
	else
		neko_gc_loop();
	return val_null;
}
예제 #22
0
파일: thread.c 프로젝트: ConstNW/neko
/**
	thread_read_message : block:bool -> any
	<doc>
	Reads a message from the message queue. If [block] is true, the
	function only returns when a message is available. If [block] is
	false and no message is available in the queue, the function will
	return immediatly [null].
	</doc>
**/
static value thread_read_message( value block ) {
	value v = thread_current();
	vthread *t;
	if( v == NULL )
		neko_error();
	t = val_thread(v);
	val_check(block,bool);
	return _deque_pop( &t->q, val_bool(block) );
}
예제 #23
0
파일: Timer.cpp 프로젝트: TomByrne/Waxe
value wx_timer_start(value inTimer, value inMilliSeconds, value inOneShot)
{
	wxTimer *timer;
   if (ValueToWX(inTimer,timer))
	{
		timer->Start(val_int(inMilliSeconds), val_bool(inOneShot) );
	}
	return alloc_null();
}
예제 #24
0
파일: socket.c 프로젝트: motion-twin/neko
/**
	socket_set_fast_send : 'socket -> bool -> void
	<doc>
	Disable or enable to TCP_NODELAY flag for the socket
	</doc>
**/
static value socket_set_fast_send( value s, value f ) {
	int fast;
	val_check_kind(s,k_socket);
	val_check(f,bool);
	fast = val_bool(f);
	if( setsockopt(val_sock(s),IPPROTO_TCP,TCP_NODELAY,(char*)&fast,sizeof(fast)) )
		neko_error();
	return val_null;
}
예제 #25
0
double  api_val_field_numeric(value  arg1,int arg2)
{
	value field = val_field(arg1, arg2);
	if (val_is_number(field))
		return val_number(field);
	if (val_is_bool(field))
		return val_bool(field);
	return 0;
}
예제 #26
0
파일: DC.cpp 프로젝트: TomByrne/Waxe
value wx_dc_draw_bitmap(value inDC, value inBitmap, value x, value y, value transparent)
{
	wxDC *dc;
	wxBitmap *bitmap;
	if (ValueToWX(inDC,dc) && ValueToWX(inBitmap,bitmap) )
	{
		dc->DrawBitmap(*bitmap, val_int(x), val_int(y), val_bool(transparent) );
	}
	return alloc_null();
}
예제 #27
0
	value lime_image_data_util_copy_pixels (value image, value sourceImage, value sourceRect, value destPoint, value mergeAlpha) {
		
		Image _image = Image (image);
		Image _sourceImage = Image (sourceImage);
		Rectangle _sourceRect = Rectangle (sourceRect);
		Vector2 _destPoint = Vector2 (destPoint);
		ImageDataUtil::CopyPixels (&_image, &_sourceImage, &_sourceRect, &_destPoint, val_bool (mergeAlpha));
		return alloc_null ();
		
	}
예제 #28
0
    value snow_window_bordered(value _window, value _enable) {

        snow::window::Window* window = snow::from_hx<snow::window::Window>(_window);

        if( window ) {
            window->bordered( val_bool(_enable) );
        }

        return alloc_null();

    } DEFINE_PRIM(snow_window_bordered, 2);
예제 #29
0
    value snow_window_fullscreen( value _window, value _enable, value _flag ) {

        snow::window::Window* window = snow::from_hx<snow::window::Window>(_window);

        if( window ) {
            window->fullscreen( val_bool(_enable), val_int(_flag) );
        }

        return alloc_null();

    } DEFINE_PRIM(snow_window_fullscreen, 3);
예제 #30
0
파일: ssl.c 프로젝트: jonasmalacofilho/neko
static value conf_set_verify( value config, value b ) {
	val_check_kind(config, k_ssl_conf);
	if( !val_is_null(b) ) val_check(b, bool);
	if( val_is_null(b) )
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_OPTIONAL);
	else if( val_bool(b) )
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_REQUIRED);
	else
		mbedtls_ssl_conf_authmode(val_conf(config), MBEDTLS_SSL_VERIFY_NONE);
	return val_true;
}