Exemple #1
0
static value loader_loadprim( value prim, value nargs ) {
	value o = val_this();
	value libs;
	val_check(o,object);
	val_check(prim,string);
	val_check(nargs,int);
	libs = val_field(o,id_loader_libs);
	val_check_kind(libs,k_loader_libs);
	if( val_int(nargs) >= 10 || val_int(nargs) < -1 )
		neko_error();
	{
		neko_vm *vm = NEKO_VM();
		void *ptr = load_primitive(val_string(prim),val_int(nargs),val_field(o,id_path),(liblist**)(void*)&val_data(libs));
		vfunction *f;
		if( ptr == NULL ) {
			buffer b = alloc_buffer("Primitive not found : ");
			val_buffer(b,prim);
			buffer_append(b,"(");
			val_buffer(b,nargs);
			buffer_append(b,")");
			bfailure(b);
		}
		f = (vfunction*)alloc_function(ptr,val_int(nargs),val_string(copy_string(val_string(prim),val_strlen(prim))));
		if( vm->pstats && val_int(nargs) <= 6 ) {
			value env = alloc_array(2);
			val_array_ptr(env)[0] = f->module;
			val_array_ptr(env)[1] = (value)(((int_val)f->addr) | 1);
			f->addr = stats_proxy;
			f->env = env;
		}
		return (value)f;
	}
}
Exemple #2
0
/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value dataBuf, value pos, value len, value vaddr ) {
	int p,l;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
   buffer buf = val_to_buffer(dataBuf);
	const char *cdata = buffer_data(buf);
	int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();

   SOCKET sock = val_sock(o);
	gc_enter_blocking();
	POSIX_LABEL(send_again);
	dlen = sendto(sock, cdata + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	gc_exit_blocking();
	return alloc_int(dlen);
}
Exemple #3
0
value wx_dir_dialog_show(value ioData)
{
   wxWindow *parent = 0;
   wxString message;
   wxString directory;
   int      style;
   wxPoint  position;
   wxSize   size;

   ValueToWX(val_field(ioData,val_id("parent")),parent);
   ValueToWX(val_field(ioData,val_id("message")),message);
   ValueToWX(val_field(ioData,val_id("directory")),directory);
   ValueToWX(val_field(ioData,val_id("style")),style);
   ValueToWX(val_field(ioData,val_id("size")),size);

   wxDirDialog *dlg = new wxDirDialog(parent,message,directory,style,position,size);
   bool result = dlg->ShowModal()==wxID_OK;

   if (result)
   {
     alloc_field(ioData,val_id("directory"), WXToValue(dlg->GetPath()));
   }

   dlg->Destroy();
   return alloc_bool(result);
}
Exemple #4
0
/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value data, value pos, value len, value vaddr ) {
	int p,l,dlen;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int32);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	dlen = val_strlen(data);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int32(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
	POSIX_LABEL(send_again);
	dlen = sendto(val_sock(o), val_string(data) + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	return alloc_int(dlen);
}
Exemple #5
0
/**
	connect : { host => string, port => int, user => string, pass => string, socket => string? } -> 'connection
	<doc>Connect to a database using the connection informations</doc>
**/
static value connect_mysql( value params  ) {
	value host, port, user, pass, socket;
	val_check(params,object);
	host = val_field(params,val_id("host"));
	port = val_field(params,val_id("port"));
	user = val_field(params,val_id("user"));
	pass = val_field(params,val_id("pass"));
	socket = val_field(params,val_id("socket"));
	val_check(host,string);
	val_check(port,int);
	val_check(user,string);
	val_check(pass,string);
	if( !val_is_string(socket) && !val_is_null(socket) )
		neko_error();
	{
		connection *c = (connection*)alloc(sizeof(connection));		
		value v;
		c->m = mysql_init(NULL);
		c->conv_string = NULL;
		c->conv_date = NULL;
		c->conv_bytes = NULL;
		if( mysql_real_connect(c->m,val_string(host),val_string(user),val_string(pass),NULL,val_int(port),val_is_null(socket)?NULL:val_string(socket),0) == NULL ) {
			buffer b = alloc_buffer("Failed to connect to mysql server : ");
			buffer_append(b,mysql_error(c->m));
			mysql_close(c->m);
			bfailure(b);
		}
		v = alloc_abstract(k_connection,c);
		val_gc(v,free_connection);
		return v;
	}
}
Exemple #6
0
int neko_execute_self( neko_vm *vm, value mload ) {
	value args[] = { alloc_string("std@module_read"), alloc_int(2) };
	value args2[] = { alloc_string("std@module_exec"), alloc_int(1) };
	value args3[] = { alloc_function(read_bytecode,3,"boot_read_bytecode"), mload };
	value exc = NULL;
	value module_read, module_exec, module_val;
	module_read = val_callEx(mload,val_field(mload,val_id("loadprim")),args,2,&exc);
	if( exc != NULL ) {
		report(vm,exc,1);
		return 1;
	}
	module_exec = val_callEx(mload,val_field(mload,val_id("loadprim")),args2,2,&exc);
	if( exc != NULL ) {
		report(vm,exc,1);
		return 1;
	}
	module_val = val_callEx(val_null,module_read,args3,2,&exc);
	fclose(self);
	if( exc != NULL ) {
		report(vm,exc,1);
		return 1;
	}
	alloc_field(val_field(mload,val_id("cache")),val_id("_self"),module_val);
	val_callEx(val_null,module_exec,&module_val,1,&exc);
	if( exc != NULL ) {
		report(vm,exc,1);
		return 1;
	}
	return 0;
}
Exemple #7
0
AudioBuffer::AudioBuffer (value audioBuffer) {

    if (!init) {

        id_bitsPerSample = val_id ("bitsPerSample");
        id_channels = val_id ("channels");
        id_data = val_id ("data");
        id_sampleRate = val_id ("sampleRate");
        init = true;

    }

    if (!val_is_null (audioBuffer)) {

        bitsPerSample = val_int (val_field (audioBuffer, id_bitsPerSample));
        channels = val_int (val_field (audioBuffer, id_channels));
        data = new ArrayBufferView (val_field (audioBuffer, id_data));
        sampleRate = val_int (val_field (audioBuffer, id_sampleRate));

    } else {

        bitsPerSample = 0;
        channels = 0;
        data = new ArrayBufferView ();
        sampleRate = 0;

    }

    mValue = audioBuffer;

}
Exemple #8
0
	DisplayMode::DisplayMode (value displayMode) {

		width = val_int (val_field (displayMode, id_width));
		height = val_int (val_field (displayMode, id_height));
		pixelFormat = (PixelFormat)val_int (val_field (displayMode, id_pixelFormat));
		refreshRate = val_int (val_field (displayMode, id_refreshRate));

	}
Exemple #9
0
	void Bytes::Resize (int size) {
		
		if (size != _length) {
			
			if (!_value) {
				
				_value = alloc_empty_object ();
				
			}
			
			if (val_is_null (val_field (_value, id_b))) {
				
				value dataValue;
				
				if (useBuffer) {
					
					buffer b = alloc_buffer_len (size);
					dataValue = buffer_val (b);
					_data = (unsigned char*)buffer_data (b);
					
				} else {
					
					dataValue = alloc_raw_string (size);
					_data = (unsigned char*)val_string (dataValue);
					
				}
				
				alloc_field (_value, id_b, dataValue);
				
			} else {
				
				if (useBuffer) {
					
					buffer b = val_to_buffer (val_field (_value, id_b));
					buffer_set_size (b, size);
					_data = (unsigned char*)buffer_data (b);
					
				} else {
					
					value s = alloc_raw_string (size);
					memcpy ((char *)val_string (s), val_string (val_field (_value, id_b)), size);
					alloc_field (_value, id_b, s);
					_data = (unsigned char*)val_string (s);
					
				}
				
			}
			
			alloc_field (_value, id_length, alloc_int (size));
			
		}
		
		_length = size;
		
	}
Exemple #10
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;
}
Exemple #11
0
const char * api_val_string(value  arg1)
{
	if (val_is_string(arg1))
	   return val_string(arg1);
	value s = val_field(arg1,__s_id);
	return val_string(s);
}
Exemple #12
0
static int boot_main(int argc, char *argv[] ) {
	neko_vm *vm;
	value args[2];
	value mload, exc = NULL;

	char* root = getSwitch(argc,argv,"swroot");
	char* rootFromBundle = root ? NULL : getSwitchFromBundle("swroot");

	char* index = getSwitch(argc,argv,"swindex");
	if(!index) index = getSwitchFromBundle("swindex");

#if OSX
	char* tmpRootBuffer = NULL;
	if (rootFromBundle) {
		if (stricmp("SW_BUNDLE_PARENT",rootFromBundle)==0) {
			// folder containing bundle is path:
			root = getBundleRoot();
			strcat(root,"/..");
		} else {
			// path is relative to bundle:
			root = tmpRootBuffer = malloc(FILENAME_MAX);
			sprintf(root,"%s/%s",getBundleRoot(),rootFromBundle);
		}
	}
#endif

	// if root folder is specified, change the current directory:
	if( root ) {
		chdir(root);
#		if OSX
 		if (tmpRootBuffer)
 			free(tmpRootBuffer);
#		endif
	}

	// printf("boot-loader computed working folder: %s\n",root);
	// printf("boot-loader set working folder: %s\n",getcwd(NULL));

	// initialize Neko Virtual Machine
	neko_global_init(&vm);
	vm = neko_vm_alloc(NULL);
	neko_vm_jit(vm,1);
	neko_vm_select(vm);
	mload = neko_default_loader(argv, argc);

	args[0] = alloc_string(index ? index : DEFAULT_INDEX);
	args[1] = mload;
	val_callEx(mload,val_field(mload,val_id("loadmodule")),args,2,&exc);
	if( exc != NULL )
		report(vm,exc);
	vm = NULL;
	neko_global_free();

	while(switches_count--) {
		free(switches[switches_count]);
	}
	if (switches) free(switches);

	return( exc != NULL );
}
Exemple #13
0
	void NekoVM::Execute (const char *modulePath) {
		
		neko_vm *vm;
		
		neko_global_init ();
		vm = neko_vm_alloc (NULL);
		neko_vm_select (vm);
		
		std_main ();
		
		value mload = neko_default_loader(NULL, 0);
		
		value args2[] = { alloc_string(modulePath), mload };
		value exc = NULL;
		
		val_callEx(mload,val_field(mload,val_id("loadmodule")),args2,2,&exc);
		
		if( exc != NULL ) {
			
			report(vm,exc,1);
			//return 1;
		}
		//return 0;
		
	}
Exemple #14
0
// Array access - generic
int api_val_array_size(value  arg1)
{
	if (val_is_array(arg1))
	   return val_array_size(arg1);
	value l = val_field(arg1,length_id);
	return val_int(l);
}
Exemple #15
0
	bool AbstractToJObject (value inValue, jobject &outObject) {
		
		JNIObject *jniobj = 0;
		
		if (AbstractToObject (inValue, jniobj)) {
			
			outObject = jniobj->GetJObject ();
			return true;
			
		}
		
		static int id__jobject = -1;
		
		if (id__jobject < 0) {
			
			id__jobject = val_id ("__jobject");
			
		}
		
		value jobj = val_field (inValue, id__jobject);
		
		if (val_is_null (jobj)) {
			
			return false;
			
		}
		
		return AbstractToJObject (jobj, outObject);
		
	}
Exemple #16
0
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;

}
Exemple #17
0
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;
	}
}
Exemple #18
0
// String access
int api_val_strlen(value  arg1)
{
	if (val_is_string(arg1))
	   return val_strlen(arg1);
	value l =  val_field(arg1,length_id);
	if (val_is_int(l))
		return val_int(l);
	return 0;
}
Exemple #19
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;
}
Exemple #20
0
static void preload_module( const char *name, server_rec *serv ) {
	value exc = NULL;
	neko_vm *vm = neko_vm_alloc(NULL);
	value mload = neko_default_loader(NULL,0);
	value m, read_path, exec;
	time_t time = 0;
	neko_vm_select(vm);
	if( config.use_jit ) neko_vm_jit(vm,1);
	if( !exc ) {
		value args[] = { alloc_string("std@module_read_path"), alloc_int(3) };
		read_path = val_callEx(mload,val_field(mload,val_id("loadprim")),args,2,&exc);
	}
	if( !exc ) {
		value args[] = { alloc_string("std@module_exec"), alloc_int(1) };
		exec = val_callEx(mload,val_field(mload,val_id("loadprim")),args,2,&exc);
	}
	if( !exc ) {
		value args[] = { val_null, alloc_string(name), mload };
		char *p = strrchr(val_string(args[1]),'.');
		if( p != NULL ) *p = 0;
		m = val_callEx(mload,read_path,args,3,&exc);
	}
	if( !exc ) {
		struct stat t;
		if( stat(name,&t) )
			exc = alloc_string("failed to stat()");
		else
			time = t.st_mtime;
	}
	if( !exc ) {
		value f = alloc_function(init_module,0,"init_module");
		value env = alloc_array(2);
		val_array_ptr(env)[0] = exec;
		val_array_ptr(env)[1] = m;
		((vfunction*)f)->env = env;
		cache_module(name,time,f);
	}
	if( exc ) {
		buffer b = alloc_buffer(NULL);
		val_buffer(b,exc);
		ap_log_error(APLOG_MARK,APLOG_WARNING,LOG_SUCCESS serv,"Failed to preload module '%s' : %s",name,val_string(buffer_to_string(b)));
	}
	neko_vm_select(NULL);
}
Exemple #21
0
//-------------------------------------------------------------------------------------------------------------------
// wxMessageDialog implemetation, added to /haxe/lib/waxe/1.0.1/src/waxe/Dialog.cpp
value wx_message_dialog_show(value ioData)
{
    wxWindow *parent = 0;
    wxString message;
    wxString caption;
    int style;
 
    ValueToWX(val_field(ioData,val_id("parent")),parent);
    ValueToWX(val_field(ioData,val_id("message")),message);
    ValueToWX(val_field(ioData,val_id("caption")),caption);
    ValueToWX(val_field(ioData,val_id("style")),style);
 
    wxMessageDialog *dlg = new wxMessageDialog(parent,message, caption, style);
    int result = dlg->ShowModal();
 
    dlg->Destroy();
 
   return alloc_int(result);
}
Exemple #22
0
static int sni_callback( void *arg, mbedtls_ssl_context *ctx, const unsigned char *name, size_t len ){
	if( name && arg ){
	 	value ret = val_call1((value)arg, alloc_string((const char*)name)) ;
		if( !val_is_null(ret) ){
			// TODO authmode and ca
			return mbedtls_ssl_set_hs_own_cert( ctx, val_cert(val_field(ret, val_id("cert"))), val_pkey(val_field(ret, val_id("key"))) );
		}
	}
	return -1;
}
Exemple #23
0
static int execute_file( neko_vm *vm, char *file, value mload ) {
	value args[] = { alloc_string(file), mload };
	value exc = NULL;
	val_callEx(mload,val_field(mload,val_id("loadmodule")),args,2,&exc);
	if( exc != NULL ) {
		report(vm,exc,1);
		return 1;
	}
	return 0;
}
Exemple #24
0
SOCKET val_sock(value inValue)
{
   if (!val_is_null(inValue))
   {
      if (val_is_kind(inValue,k_socket) )
         return ((SOCKET)(socket_int)val_data(inValue));
      inValue = val_field(inValue,id___s);
      if (val_is_kind(inValue,k_socket) )
         return ((SOCKET)(socket_int)val_data(inValue));
   }
   val_throw(alloc_string("Invalid socket handle"));
   return 0;
}
Exemple #25
0
value ftRenderGlyph( value font, value _index, value _size, value _hint ) {
    if( !val_is_object(font) ) {
        ft_failure_v("not a freetype font face: ", font );
    }
    value __f = val_field( font, val_id("__f") );
    if( __f == NULL || !val_is_abstract( __f ) || !val_is_kind( __f, k_ft_face ) ) {
        ft_failure_v("not a freetype font face: ", font );
    }
    FT_Face *face = val_data( __f );

    val_check( _size, number );
    int size = val_number(_size);
    FT_Set_Char_Size( *face, size, size, 72, 72 );
    
    val_check( _hint, bool );
    int hint = val_bool(_hint);
    
    val_check(_index,number);
    /*
    int index = FT_Get_Char_Index( *face, (FT_UInt) val_number(_index) );
    fprintf( stderr, "char %i is glyph %i\n", (int)val_number(_index), (int)index );
    int err = FT_Load_Glyph( *face, index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING );
        fprintf( stderr, "Load Glyph idx %i->%i/%i, sz %i, face %p: err 0x%x\n",
                (int)val_number(_index), index, 
                (int)((*face)->num_glyphs), size>>6, face, err );
    */
    int err = FT_Load_Char( *face, (FT_ULong)val_number(_index), FT_LOAD_RENDER | (hint?0:FT_LOAD_NO_HINTING) );
    if( err ) { 
        
        fprintf( stderr, "Load_Char failed: %x char index %i\n", err, FT_Get_Char_Index( *face, (FT_UInt) val_number(_index) ) );
        val_throw(alloc_string("Could not load requested Glyph"));
   //     return( val_null );
    }
    FT_GlyphSlot glyph = (*face)->glyph;
    /*
    err = FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL );
    if( err || glyph->format != ft_glyph_format_bitmap ) {
        val_throw(alloc_string("Could not render requested Glyph"));
    }
    */
    FT_Bitmap bitmap = glyph->bitmap;

    value ret = alloc_object(NULL);
    alloc_field( ret, val_id("width"), alloc_int(bitmap.width) );
    alloc_field( ret, val_id("height"), alloc_int(bitmap.rows) );
    alloc_field( ret, val_id("bitmap"), copy_string( (char*)bitmap.buffer, bitmap.width*bitmap.rows ) );
    alloc_field( ret, val_id("x"), alloc_int( glyph->metrics.horiBearingX ) );
    alloc_field( ret, val_id("y"), alloc_int( glyph->metrics.horiBearingY ) );
    alloc_field( ret, val_id("advance"), alloc_float( glyph->advance.x ));
    return ret;
}
Exemple #26
0
static value loader_loadmodule( value mname, value vthis ) {
	value o = val_this();
	value cache;
	val_check(o,object);
	val_check(mname,string);
	val_check(vthis,object);
	cache = val_field(o,id_cache);
	val_check(cache,object);
	{
		reader r;
		readp p;
		neko_module *m;
		neko_vm *vm = NEKO_VM();
		field mid = val_id(val_string(mname));
		value mv = val_field(cache,mid);
		if( val_is_kind(mv,neko_kind_module) ) {
			m = (neko_module*)val_data(mv);
			return m->exports;
		}
		open_module(val_field(o,id_path),val_string(mname),&r,&p);
		if( vm->fstats ) vm->fstats(vm,"neko_read_module",1);
		m = neko_read_module(r,p,vthis);
		if( vm->fstats ) vm->fstats(vm,"neko_read_module",0);
		close_module(p);
		if( m == NULL ) {
			buffer b = alloc_buffer("Invalid module : ");
			val_buffer(b,mname);
			bfailure(b);
		}
		m->name = alloc_string(val_string(mname));
		mv = alloc_abstract(neko_kind_module,m);
		alloc_field(cache,mid,mv);
		if( vm->fstats ) vm->fstats(vm,val_string(mname),1);
		neko_vm_execute(neko_vm_current(),m);
		if( vm->fstats ) vm->fstats(vm,val_string(mname),0);
		return m->exports;
	}
}
Exemple #27
0
char *Val2Str(value inVal)
{
   if (val_is_string(inVal))
      return  (char *)val_string(inVal);
   if (val_is_object(inVal))
   {
      value __s = val_field(inVal, val_id("__s"));
      if (val_is_string(__s))
         return  (char *)val_string(__s);
   }
   else if (val_is_object(inVal))
      return val_bool(inVal) ? (char *)"true":(char *)"false";
   return (char *)"";
}
Exemple #28
0
// Determine value type
int api_val_type(value  arg1)
{
	int t=val_type(arg1);
	if (t==VAL_OBJECT)
	{
		value __a = val_field(arg1,__a_id);
		if (val_is_array(__a))
			return valtArray;
		value __s = val_field(arg1,__s_id);
		if (val_is_string(__s))
			return valtString;
	}
	if (t<7)
		return (ValueType)t;
	if (t==VAL_ABSTRACT)
		return valtAbstractBase;

	if (t==VAL_PRIMITIVE || t==VAL_JITFUN)
		return valtFunction;
	if (t==VAL_32_BITS || t==VAL_INT)
		return valtInt;
	return valtNull;
}
Exemple #29
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;
				
			}
			
		}
		
	}
Exemple #30
0
	value AudioBuffer::Value (value audioBuffer) {

		if (!init) {

			id_bitsPerSample = val_id ("bitsPerSample");
			id_channels = val_id ("channels");
			id_data = val_id ("data");
			id_sampleRate = val_id ("sampleRate");
			init = true;

		}

		alloc_field (audioBuffer, id_bitsPerSample, alloc_int (bitsPerSample));
		alloc_field (audioBuffer, id_channels, alloc_int (channels));
		alloc_field (audioBuffer, id_data, data ? data->Value (val_field (audioBuffer, id_data)) : alloc_null ());
		alloc_field (audioBuffer, id_sampleRate, alloc_int (sampleRate));
		return audioBuffer;

	}