Example #1
0
/**
	sys_exe_path : void -> string
	<doc>Return the path of the executable</doc>
**/
static value sys_exe_path() {
#ifdef HX_WINRT
   Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
   Windows::Storage::StorageFolder^ installedLocation = package->InstalledLocation;
   return(alloc_wstring(installedLocation->Path->Data()));
#elif defined(NEKO_WINDOWS)
	wchar_t path[MAX_PATH];
	if( GetModuleFileNameW(NULL,path,MAX_PATH) == 0 )
		return alloc_null();
	return alloc_wstring(path);
#elif defined(NEKO_MAC) && !defined(IPHONE)
	char path[PATH_MAX+1];
	uint32_t path_len = PATH_MAX;
	if( _NSGetExecutablePath(path, &path_len) )
		return alloc_null();
	return alloc_string(path);
#elif defined(EPPC)
	return alloc_string("");
#else
	const char *p = getenv("_");
	if( p != NULL )
		return alloc_string(p);
	{
		char path[PATH_MAX];
		int length = readlink("/proc/self/exe", path, sizeof(path));
		if( length < 0 )
			return alloc_null();
	    path[length] = '\0';
		return alloc_string(path);
	}
#endif
}
Example #2
0
/**
	get_cwd : void -> string
	<doc>Return current working directory</doc>
**/
static value get_cwd() {
   #ifdef HX_WINRT
   return alloc_string("ms-appdata:///local/");
   #elif defined(EPPC) || defined(KORE_CONSOLE)
   return alloc_null();
   #else
	#ifdef NEKO_WINDOWS
	wchar_t buf[256];
	int l;
	if( GetCurrentDirectoryW(256,buf) == NULL )
		return alloc_null();
	l = (int)wcslen(buf);
	if( buf[l-1] != '/' && buf[l-1] != '\\' ) {
		buf[l] = '/';
		buf[l+1] = 0;
	}
	return alloc_wstring(buf);
	#else
	char buf[256];
	int l;
	if( getcwd(buf,256) == NULL )
		return alloc_null();
	l = (int)strlen(buf);
	if( buf[l-1] != '/' && buf[l-1] != '\\' ) {
		buf[l] = '/';
		buf[l+1] = 0;
	}
	return alloc_string(buf);
	#endif
   #endif
}
Example #3
0
	value lime_font_get_family_name (value fontHandle) {
		
		#ifdef LIME_FREETYPE
		Font *font = (Font*)(intptr_t)val_float (fontHandle);
		return alloc_wstring (font->GetFamilyName ());
		#else
		return alloc_null ();
		#endif
		
	}
Example #4
0
	value lime_font_get_family_name (value fontHandle) {
		
		#ifdef LIME_FREETYPE
		Font *font = (Font*)val_data (fontHandle);
		wchar_t *name = font->GetFamilyName ();
		value result = alloc_wstring (name);
		delete name;
		return result;
		#else
		return 0;
		#endif
		
	}
Example #5
0
/**
	file_full_path : string -> string
	<doc>Return an absolute path from a relative one. The file or directory must exists</doc>
**/
static value file_full_path( value path ) {
#if defined(HX_WINRT) || defined(KORE_CONSOLE)
	return path;
#elif defined(NEKO_WINDOWS)
	wchar_t buf[MAX_PATH+1];
	val_check(path,string);
	if( GetFullPathNameW(val_wstring(path),MAX_PATH+1,buf,NULL) == 0 )
		return alloc_null();
	return alloc_wstring(buf);
#elif defined(EPPC)
	return path;
#else
	char buf[PATH_MAX];
	val_check(path,string);
	if( realpath(val_string(path),buf) == NULL )
		return alloc_null();
	return alloc_string(buf);
#endif
}
Example #6
0
/**
	sys_read_dir : string -> string list
	<doc>Return the content of a directory</doc>
**/
static value sys_read_dir( value p) {
	val_check(p,string);

        value result = alloc_array(0);
#ifdef HX_WINRT
   auto folder = (Windows::Storage::StorageFolder::GetFolderFromPathAsync( ref new Platform::String(val_wstring(p)) ))->GetResults();
   auto results = folder->GetFilesAsync(Windows::Storage::Search::CommonFileQuery::DefaultQuery)->GetResults();
   for(int i=0;i<results->Size;i++)
      val_array_push(result,alloc_wstring(results->GetAt(i)->Path->Data()));

#elif defined(NEKO_WINDOWS)
	const wchar_t *path = val_wstring(p);
	size_t len = wcslen(path);
   if (len>MAX_PATH)
      return alloc_null();

	WIN32_FIND_DATAW d;
	HANDLE handle;
	buffer b;
   wchar_t searchPath[ MAX_PATH + 4 ];
   memcpy(searchPath,path, len*sizeof(wchar_t));


	if( len && path[len-1] != '/' && path[len-1] != '\\' )
      searchPath[len++] = '/';
   searchPath[len++] = '*';
   searchPath[len++] = '.';
   searchPath[len++] = '*';
   searchPath[len] = '\0';

	gc_enter_blocking();
	handle = FindFirstFileW(searchPath,&d);
	if( handle == INVALID_HANDLE_VALUE )
	{
		gc_exit_blocking();
		return alloc_null();
	}
	while( true ) {
		// skip magic dirs
		if( d.cFileName[0] != '.' || (d.cFileName[1] != 0 && (d.cFileName[1] != '.' || d.cFileName[2] != 0)) ) {
		   gc_exit_blocking();
			val_array_push(result,alloc_wstring(d.cFileName));
			gc_enter_blocking();
		}
		if( !FindNextFileW(handle,&d) )
			break;
	}
	FindClose(handle);
	gc_exit_blocking();
#elif !defined(EPPC)
	DIR *d;
	struct dirent *e;
   const char *name = val_string(p);
	gc_enter_blocking();
	d = opendir(name);
	if( d == NULL )
	{
		gc_exit_blocking();
      val_throw(alloc_string("Invalid directory"));
	}
	while( true ) {
		e = readdir(d);
		if( e == NULL )
			break;
		// skip magic dirs
		if( e->d_name[0] == '.' && (e->d_name[1] == 0 || (e->d_name[1] == '.' && e->d_name[2] == 0)) )
			continue;
		gc_exit_blocking();
		val_array_push(result, alloc_string(e->d_name) );
		gc_enter_blocking();
	}
	closedir(d);
#endif
	gc_exit_blocking();
	return result;
}