コード例 #1
0
ファイル: hx_Vector3.cpp プロジェクト: jgranick/hx-gameplay
// DECL: Vector3(const float* array);
value hx_Vector3_Construct_ArrFlt(value array)
{
    float values[] =
            {
                ValueToFloat(val_array_i(array, 0)),
                ValueToFloat(val_array_i(array, 1)),
                ValueToFloat(val_array_i(array, 2))
            };
    return ObjectToValue(new Vector3(values));
}
コード例 #2
0
// DECL: Quaternion(float* array);
value hx_Quaternion_Construct_ArrFlt(value array)
{
    float values[] =
            {
                ValueToFloat(val_array_i(array, 0)),
                ValueToFloat(val_array_i(array, 1)),
                ValueToFloat(val_array_i(array, 2)),
                ValueToFloat(val_array_i(array, 3))
            };
    return ObjectToValue(new Quaternion(values));
}
コード例 #3
0
ファイル: hx_Vector3.cpp プロジェクト: jgranick/hx-gameplay
// DECL: void set(const float* array);
void hx_Vector3_set_ArrFlt(value thisObj, value array)
{
    Vector3 *_thisObj;
    float values[] =
            {
                ValueToFloat(val_array_i(array, 0)),
                ValueToFloat(val_array_i(array, 1)),
                ValueToFloat(val_array_i(array, 2))
            };
    ValueToObject(thisObj, _thisObj);
    _thisObj->set(values);
}
コード例 #4
0
ファイル: api.cpp プロジェクト: aik6980/systools
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;
}
コード例 #5
0
// DECL: void set(float* array);
void hx_Quaternion_set_ArrFlt(value thisObj, value array)
{
    Quaternion *_thisObj;
    float values[] =
            {
                ValueToFloat(val_array_i(array, 0)),
                ValueToFloat(val_array_i(array, 1)),
                ValueToFloat(val_array_i(array, 2)),
                ValueToFloat(val_array_i(array, 3))
            };
    ValueToObject(thisObj, _thisObj);
    _thisObj->set(values);
}
コード例 #6
0
ファイル: Socket.cpp プロジェクト: KTXSoftware/Kha-haxelib
/**
	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;
}
コード例 #7
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	value lime_alc_create_context (value device, value attrlist) {
		
		ALCdevice* alcDevice = (ALCdevice*)val_data (device);
		
		ALCint* list = NULL;
		
		if (val_is_null (attrlist) == false) {
			
			int size = val_array_size (attrlist);
			list = new ALCint[size];
			
			for (int i = 0; i < size; ++i) {
				list[i] = (ALCint)val_int( val_array_i (attrlist, i) );
			}
			
		}
		
		ALCcontext* alcContext = alcCreateContext (alcDevice, list);
		
		if (list != NULL) {
			delete[] list;
		}
		
		return CFFIPointer (alcContext);
		
	}
コード例 #8
0
ファイル: Socket.cpp プロジェクト: KTXSoftware/Kha-haxelib
/**
	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;
	}
}
コード例 #9
0
ファイル: api.cpp プロジェクト: aik6980/systools
static value dialogs_save_file( value title, value msg, value initialdir, value mask) {
	char * v;
	struct ARG_FILEFILTERS filters = {0,0,0};

	value result = val_null;
	val_check(title, string);
	val_check(msg, string);
	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));
			}
		}
	}

	result = val_null;
	v = systools_dialogs_save_file(val_string(title),val_string(msg),val_string(initialdir),filters.count? &filters : NULL);
	if (v) {
		result = alloc_string(v);
		free((void*)v);
	}

	// clean up allocated mem. for filters:
	if (val_is_object(mask)) {
		free(filters.descriptions);
		free(filters.extensions);
	}

	return result;

}
コード例 #10
0
ファイル: ExternalInterface.cpp プロジェクト: Rezmason/lime
	void lime_gamepad_add_mappings (value mappings) {
		
		int length = val_array_size (mappings);
		
		for (int i = 0; i < length; i++) {
			
			Gamepad::AddMapping (val_string (val_array_i (mappings, i)));
			
		}
		
	}
コード例 #11
0
ファイル: ExternalInterface.cpp プロジェクト: fserb/RTMidi
value rtmidi_out_sendmessage(value obj, value msg) {
  RtMidiOut *midiout = (RtMidiOut *)(intptr_t)val_float(obj);

  std::vector<unsigned char> message;

  int size = val_array_size(msg);
  for (int i = 0; i < size; ++i) {
    message.push_back(val_int(val_array_i(msg, i)));
  }

  midiout->sendMessage(&message);
  return alloc_null();
}
コード例 #12
0
ファイル: CairoBindings.cpp プロジェクト: Gemioli/lime
	void lime_cairo_set_dash (value handle, value dash) {
		
		int length = val_array_size (dash);
		
		double* dashPattern = new double[length];
		
		for (int i = 0; i < length; i++) {
			
			dashPattern[i] = val_number (val_array_i (dash, i));
			
		}
		
		cairo_set_dash ((cairo_t*)val_data (handle), dashPattern, length, 0);
		delete dashPattern;
		
	}
コード例 #13
0
ファイル: Socket.cpp プロジェクト: KTXSoftware/Kha-haxelib
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;
}
コード例 #14
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	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;
			
		}
	}
コード例 #15
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	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;
			
		}
		
	}
コード例 #16
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	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;
			
		}
		
	}
コード例 #17
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	void lime_al_listenerfv (int param, value values) {
		
		if (val_is_null (values) == false) {
			
			int size = val_array_size (values);
			ALfloat *data = new ALfloat[size];
			
			for (int i = 0; i < size; ++i) {
				
				data[i] = (ALfloat)val_float( val_array_i (values, i) );
				
			}
			
			alListenerfv(param, data);
			
			delete[] data;
			
		}
		
	}
コード例 #18
0
ファイル: OpenALBindings.cpp プロジェクト: Leander1P/lime
	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;
			
		}
		
	}
コード例 #19
0
ファイル: Socket.cpp プロジェクト: KTXSoftware/Kha-haxelib
static void make_array_result_inplace(value a, fd_set *tmp)
{
    if (tmp == NULL) {
        val_array_set_size(a, 0);
        return;
    }
    int len = val_array_size(a);
    value *results = (value *) malloc(sizeof(value) * len);
    int result_len = 0;
    for (int i = 0; i < len; i++) {
        value s = val_array_i(a, i);
        if (FD_ISSET(val_sock(s), tmp)) {
            results[result_len++] = s;
        }
    }
    val_array_set_size(a, result_len);
    for (int i = 0; i < result_len; i++) {
        val_array_set_i(a, i, results[i]);
    }
    free(results);
}
コード例 #20
0
ファイル: Socket.cpp プロジェクト: KTXSoftware/Kha-haxelib
static fd_set *make_socket_array( value a, fd_set *tmp, SOCKET *n ) {
	int i, len;
	SOCKET sock;
	FD_ZERO(tmp);
	if( val_is_null(a) )
		return tmp;
	if( !val_is_array(a) )
		return &INVALID;
	len = val_array_size(a);
	if( len > FD_SETSIZE )
		val_throw(alloc_string("Too many sockets in select"));
	for(i=0;i<len;i++) {
		value s = val_array_i(a,i);
                // make sure it is a socket...
		sock = val_sock(s);
		if( sock > *n )
			*n = sock;
		FD_SET(sock,tmp);
	}
	return tmp;
}
コード例 #21
0
ファイル: String.cpp プロジェクト: 0b1kn00b/hxcpp
/**
	sprintf : fmt:string -> params:(any | array) -> string
	<doc>
	Format a string. If only one parameter is needed then it can be
	directly passed, either the parameters need to be stored in an array.
	The following formats are accepted (with corresponding types) :
	<ul>
		<li>[%s] : string</li>
		<li>[%d] [%x] [%X] : int</li>
		<li>[%c] : int in the 0..255 range</li>
		<li>[%b] : bool</li>
		<li>[%f] : float</li>
	</ul>
	</doc>
**/
static value neko_sprintf( value fmt, value params ) {
	const char *last, *cur, *end;
	int count = 0;
	buffer b;
	val_check(fmt,string);
	b = alloc_buffer(0);
	last = val_string(fmt);
	cur = last;
	end = cur + val_strlen(fmt);
	while( cur != end ) {
		if( *cur == '%' ) {
			int width = 0, prec = 0, flags = 0;
			buffer_append_sub(b,last,cur - last);
			cur++;
			while( *cur >= '0' && *cur <= '9' ) {
				width = width * 10 + (*cur - '0');
				cur++;
			}
			if( *cur == '.' ) {
				cur++;
				while( *cur >= '0' && *cur <= '9' ) {
					prec = prec * 10 + (*cur - '0');
					cur++;
				}
			}
			if( *cur == '%' ) {
				buffer_append_sub(b,"%",1);
				cur++;
			} else {
				value param;
				if( count == 0 && !val_is_array(params) ) { // first ?
					param = params;
					count++;
				} else if( !val_is_array(params) || val_array_size(params) <= count )
					return alloc_null();
				else
					param = val_array_i(params,count++);
				switch( *cur ) {
				case 'c':
					{
						int c;
						char cc;
						val_check(param,int);
						c = val_int(param);
						if( c < 0 || c > 255 )
							return alloc_null();
						cc = (char)c;
						buffer_append_sub(b,&cc,1);
					}
					break;
				case 'x':
					flags |= HEX_SMALL;
				case 'X':
					flags |= HEX;
				case 'd':
					{
						char tmp[10];
						int sign = 0;
						int size = 0;
						int tsize;
						int n;
						val_check(param,int);
						n = val_int(param);
						if( !(flags & HEX) && n < 0 ) {
							sign++;
							prec--;
							n = -n;
						} else if( n == 0 )
							tmp[9-size++] = '0';
						if( flags & HEX ) {
							unsigned int nn = (unsigned int)n;
							while( nn > 0 ) {
								int k = nn&15;
								if( k < 10 )
									tmp[9-size++] = k + '0';
								else
									tmp[9-size++] = (k - 10) + ((flags & HEX_SMALL)?'a':'A');
								nn = nn >> 4;
							}
						} else {
							while( n > 0 ) {
								tmp[9-size++] = (n % 10) + '0';
								n = n / 10;
							}
						}
						tsize = (size > prec)?size:prec + sign;
						while( width > tsize ) {
							width--;
							buffer_append_sub(b," ",1);
						}
						if( sign )
							buffer_append_sub(b,"-",1);
						while( prec > size ) {
							prec--;
							buffer_append_sub(b,"0",1);
						}
						buffer_append_sub(b,tmp+10-size,size);
					}
					break;
				case 'f':
					{
						val_check(param,float);
						val_buffer(b,param);
					}
					break;
				case 's':
					{
						int size;
						int tsize;
						val_check(param,string);
						size = val_strlen(param);
						tsize = (size > prec)?size:prec;
						while( width > tsize ) {
							width--;
							buffer_append_sub(b," ",1);
						}
						while( prec > size ) {
							prec--;
							buffer_append_sub(b," ",1);
						}
						buffer_append_sub(b,val_string(param),size);
					}
					break;
				case 'b':
					{
						val_check(param,bool);
						buffer_append_sub(b,val_bool(param)?"true":"false",val_bool(param)?4:5);
					}
					break;
				default:
					return alloc_null();
					break;
				}
			}
コード例 #22
0
ファイル: Process.cpp プロジェクト: delahee/hxlibc
/**
   process_run : cmd:string -> args:string array -> 'process
   <doc>
   Start a process using a command and the specified arguments.
   </doc>
**/
static value process_run( value cmd, value vargs ) {
   int i;
   vprocess *p;
   val_check(cmd,string);
   val_check(vargs,array);
#   ifdef NEKO_WINDOWS
   {       
      SECURITY_ATTRIBUTES sattr;      
      STARTUPINFOW sinf;
      HANDLE proc = GetCurrentProcess();
      HANDLE oread,eread,iwrite;
      // creates commandline
      buffer b = alloc_buffer("\"");
      val_buffer(b,cmd);
      buffer_append(b,"\"");

      int n = val_array_size(vargs);
      for(i=0;i<n;i++) {
         value v = val_array_i(vargs,i);
         val_check(v,string);
         buffer_append(b," \"");
         val_buffer(b,v);
         buffer_append(b,"\"");
      }
      wchar_t *name = val_dup_wstring(buffer_to_string(b));
      gc_enter_blocking();
      p = (vprocess*)malloc(sizeof(vprocess));
      // startup process
      sattr.nLength = sizeof(sattr);
      sattr.bInheritHandle = TRUE;
      sattr.lpSecurityDescriptor = NULL;
      memset(&sinf,0,sizeof(sinf));
      sinf.cb = sizeof(sinf);
      sinf.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
      sinf.wShowWindow = SW_NORMAL;
      CreatePipe(&oread,&sinf.hStdOutput,&sattr,0);
      CreatePipe(&eread,&sinf.hStdError,&sattr,0);
      CreatePipe(&sinf.hStdInput,&iwrite,&sattr,0);
      DuplicateHandle(proc,oread,proc,&p->oread,0,FALSE,DUPLICATE_SAME_ACCESS);
      DuplicateHandle(proc,eread,proc,&p->eread,0,FALSE,DUPLICATE_SAME_ACCESS);
      DuplicateHandle(proc,iwrite,proc,&p->iwrite,0,FALSE,DUPLICATE_SAME_ACCESS);
      CloseHandle(oread);
      CloseHandle(eread);
      CloseHandle(iwrite);
      //printf("Cmd %s\n",val_string(cmd));
      if( !CreateProcessW(NULL,name,NULL,NULL,TRUE,0,NULL,NULL,&sinf,&p->pinf) )
      {
         free(p);
         gc_exit_blocking();
			val_throw(alloc_null());
         return alloc_null();
      }
      // close unused pipes
      CloseHandle(sinf.hStdOutput);
      CloseHandle(sinf.hStdError);
      CloseHandle(sinf.hStdInput);
      gc_exit_blocking();
   }
#else
   char **argv = (char**)malloc(sizeof(char*)*(val_array_size(vargs)+2));

   argv[0] = strdup(val_string(cmd));
   for(i=0;i<val_array_size(vargs);i++) {
      value v = val_array_i(vargs,i);
      val_check(v,string);
      argv[i+1] = strdup(val_string(v));
   }
   argv[i+1] = NULL;
   int input[2], output[2], error[2];
   if( pipe(input) || pipe(output) || pipe(error) )
      return alloc_null();
   p = (vprocess*)malloc(sizeof(vprocess));
   p->pid = fork();
   if( p->pid == -1 )
      return alloc_null();
   gc_enter_blocking();
   // child
   if( p->pid == 0 ) {
      close(input[1]);
      close(output[0]);
      close(error[0]);
      dup2(input[0],0);
      dup2(output[1],1);
      dup2(error[1],2);
      execvp(val_string(cmd),argv);
      fprintf(stderr,"Command not found : %s\n",val_string(cmd));
      exit(1);
   }
   // parent
   for(i=0;i<=val_array_size(vargs);i++)
           free(argv[i]);
        free(argv);
   do_close(input[0]);
   do_close(output[1]);
   do_close(error[1]);
   p->iwrite = input[1];
   p->oread = output[0];
   p->eread = error[0];
   gc_exit_blocking();
#   endif
   {
      value vp = alloc_abstract(k_process,p);
      val_gc(vp,free_process);
      return vp;
   }
}