Quellcode durchsuchen

makedocs fixes, docs cleanups and file rearrangement.

Mark Sibly vor 9 Jahren
Ursprung
Commit
09c9f5b639

BIN
bin/mx2cc_linux


BIN
bin/mx2cc_macos


BIN
bin/mx2cc_raspbian


BIN
bin/mx2cc_windows.exe


+ 64 - 35
modules/std/filesystem/filesystem.monkey2

@@ -24,12 +24,19 @@ Function AppPath:String()="bbFileSystem::appPath"
 
 
 #rem monkeydoc Gets application command line arguments.
 #rem monkeydoc Gets application command line arguments.
 
 
+The first argument is always the application name.
+
 @return The application command line arguments.
 @return The application command line arguments.
+
 #end
 #end
 Function AppArgs:String[]()="bbFileSystem::appArgs"
 Function AppArgs:String[]()="bbFileSystem::appArgs"
 
 
 #rem monkeydoc Copies a file.
 #rem monkeydoc Copies a file.
 
 
+Copies a file from `srcPath` to `dstPath`, overwriting `dstpath` if it alreay exits.
+
+Returns true if successful.
+
 @return True if the file was successfully copied.
 @return True if the file was successfully copied.
 
 
 #end
 #end
@@ -72,47 +79,47 @@ Const FILETYPE_DIR:=FileType.Directory
 #end
 #end
 Const FILETYPE_UNKNOWN:=FileType.Unknown
 Const FILETYPE_UNKNOWN:=FileType.Unknown
 
 
-#rem monkeydoc Gets the filesystem directory of the assets folder.
+#rem monkeydoc Gets the filesystem directory of the assets directory.
+
+Note that assets are only stored in the filesystem on the desktop and emscripten targets. Other targets will return an empty string.
 
 
 @return The directory app assets are stored in.
 @return The directory app assets are stored in.
 
 
 #end
 #end
 Function AssetsDir:String()
 Function AssetsDir:String()
-
 #If __TARGET__="macos"
 #If __TARGET__="macos"
-
 	Return AppDir()+"../Resources/"
 	Return AppDir()+"../Resources/"
-	
 #Else If __DESKTOP_TARGET__ Or __TARGET__="emscripten"
 #Else If __DESKTOP_TARGET__ Or __TARGET__="emscripten"
-
 	Return AppDir()+"assets/"
 	Return AppDir()+"assets/"
-	
 #Else
 #Else
-
 	Return ""
 	Return ""
-	
 #Endif
 #Endif
-
 End
 End
 
 
-Function DesktopDir:String()
+#rem monkeydoc Gets the filesystem directory of the desktop directory.
+
+Note that only the desktop targets have a desktop directory. Other targets will return an empty string.
 
 
+@return The desktop directory.
+
+#end
+Function DesktopDir:String()
 #If __TARGET__="windows"
 #If __TARGET__="windows"
-	
 	Return (String.FromCString( getenv( "HOMEDRIVE" ) )+String.FromCString( getenv( "HOMEPATH" ) )).Replace( "\","/" )+"/Desktop/"
 	Return (String.FromCString( getenv( "HOMEDRIVE" ) )+String.FromCString( getenv( "HOMEPATH" ) )).Replace( "\","/" )+"/Desktop/"
-	
 #Else If __DESKTOP_TARGET__
 #Else If __DESKTOP_TARGET__
-
 	Return String.FromCString( getenv( "HOME" ) )+"/Desktop/"
 	Return String.FromCString( getenv( "HOME" ) )+"/Desktop/"
-
 #Endif
 #Endif
-
 	Return ""
 	Return ""
-
 End
 End
 
 
 #rem monkeydoc Extracts the root directory from a file system path.
 #rem monkeydoc Extracts the root directory from a file system path.
 
 
+A root directory is a directory path that:
+
+* Starts with '//' or '/', or...
+
+* Starts with 'blah:/', 'blah://' or 'blah::'.
+
 @param path The filesystem path.
 @param path The filesystem path.
 
 
 @return The root directory of `path`, or an empty string if `path` is not an absolute path.
 @return The root directory of `path`, or an empty string if `path` is not an absolute path.
@@ -264,7 +271,7 @@ Function ExtractExt:String( path:String )
 	Return ""
 	Return ""
 End
 End
 
 
-#rem monkeydoc Strips the extension component from a filesystem path
+#rem monkeydoc Strips the extension component from a filesystem path.
 
 
 @param path The filesystem path.
 @param path The filesystem path.
 
 
@@ -403,6 +410,10 @@ End
 
 
 #rem monkeydoc Loads a directory.
 #rem monkeydoc Loads a directory.
 
 
+Loads the contents of directory into an array.
+
+Does not return any '.' or '..' entries in a directory.
+
 @param path The filesystem path of the directory to load.
 @param path The filesystem path of the directory to load.
 
 
 @return An array containing all filenames in the `path`, excluding '.' and '..' entries.
 @return An array containing all filenames in the `path`, excluding '.' and '..' entries.
@@ -436,6 +447,8 @@ End
 
 
 Any existing file at the path will be overwritten.
 Any existing file at the path will be overwritten.
 
 
+Returns true if successful.
+
 @param path The filesystem path of the file file to create.
 @param path The filesystem path of the file file to create.
 
 
 @param createDir If true, also creates the file directory if necessary.
 @param createDir If true, also creates the file directory if necessary.
@@ -460,10 +473,12 @@ End
 
 
 @param recursive If true, any required parent directories are also created.
 @param recursive If true, any required parent directories are also created.
 
 
+@param clean If true, any existing directory at `dir` is first deleted.
+
 @return True if a directory at `path` was successfully created or already existed.
 @return True if a directory at `path` was successfully created or already existed.
 
 
 #end
 #end
-Function CreateDir:Bool( dir:String,recursive:Bool=True )
+Function CreateDir:Bool( dir:String,recursive:Bool=True,clean:Bool=False )
 
 
 	If recursive
 	If recursive
 	
 	
@@ -472,7 +487,7 @@ Function CreateDir:Bool( dir:String,recursive:Bool=True )
 		
 		
 			Select GetFileType( parent )
 			Select GetFileType( parent )
 			Case FileType.None
 			Case FileType.None
-				If Not CreateDir( parent,True ) Return False
+				If Not CreateDir( parent,True,False ) Return False
 			Case FileType.File
 			Case FileType.File
 				Return False
 				Return False
 			End
 			End
@@ -480,6 +495,8 @@ Function CreateDir:Bool( dir:String,recursive:Bool=True )
 		Endif
 		Endif
 		
 		
 	Endif
 	Endif
+	
+	If clean And Not DeleteDir( dir,True ) Return False
 
 
 	mkdir( StripSlashes( dir ),$1ff )
 	mkdir( StripSlashes( dir ),$1ff )
 	Return GetFileType( dir )=FileType.Directory
 	Return GetFileType( dir )=FileType.Directory
@@ -487,6 +504,8 @@ End
 
 
 #rem monkeydoc Deletes a file at a filesystem path.
 #rem monkeydoc Deletes a file at a filesystem path.
 
 
+Returns true if successful.
+
 @param path The filesystem path.
 @param path The filesystem path.
 
 
 @return True if the file was successfully deleted.
 @return True if the file was successfully deleted.
@@ -500,6 +519,10 @@ End
 
 
 #rem monkeydoc Deletes a directory at a filesystem path.
 #rem monkeydoc Deletes a directory at a filesystem path.
 
 
+If `recursive` is true, all subdirectories are also deleted.
+
+Returns true if successful.
+
 @param path The filesystem path.
 @param path The filesystem path.
 
 
 @param recursive True to delete subdirectories too.
 @param recursive True to delete subdirectories too.
@@ -509,19 +532,11 @@ End
 #end
 #end
 Function DeleteDir:Bool( dir:String,recursive:Bool=False )
 Function DeleteDir:Bool( dir:String,recursive:Bool=False )
 
 
-	Select GetFileType( dir )
-	Case FileType.None
-	
-		Return True
-		
-	Case FileType.Directory
-	
+	If GetFileType( dir )=FileType.Directory
+
 		If recursive
 		If recursive
-		
 			For Local f:=Eachin LoadDir( dir )
 			For Local f:=Eachin LoadDir( dir )
-			
 				Local p:=dir+"/"+f
 				Local p:=dir+"/"+f
-				
 				Select GetFileType( p )
 				Select GetFileType( p )
 				Case FileType.File
 				Case FileType.File
 					If Not DeleteFile( p ) Return False
 					If Not DeleteFile( p ) Return False
@@ -529,17 +544,32 @@ Function DeleteDir:Bool( dir:String,recursive:Bool=False )
 					If Not DeleteDir( p,True ) Return false
 					If Not DeleteDir( p,True ) Return false
 				End
 				End
 			Next
 			Next
-			
 		Endif
 		Endif
 		
 		
 		rmdir( StripSlashes( dir ) )
 		rmdir( StripSlashes( dir ) )
-		
-		Return GetFileType( dir )=FileType.None
-	End
+	Endif
 	
 	
-	Return False
+	Return GetFileType( dir )=FileType.None
 End
 End
 
 
+
+#rem monkeydoc Copies a directory.
+
+Copies a directory from `srcDir` to `dstDir`.
+
+If `recursive` is true, all subdirectories are also copied.
+
+Returns true if successful.
+
+@param srcDir Source directory.
+
+@param dstDir Destination directory.
+
+@param recursive Recursive flag.
+
+@return True if successful.
+
+#end
 Function CopyDir:Bool( srcDir:String,dstDir:String,recursive:Bool=True )
 Function CopyDir:Bool( srcDir:String,dstDir:String,recursive:Bool=True )
 
 
 	If GetFileType( srcDir )<>FileType.Directory Return False
 	If GetFileType( srcDir )<>FileType.Directory Return False
@@ -563,4 +593,3 @@ Function CopyDir:Bool( srcDir:String,dstDir:String,recursive:Bool=True )
 	Return True
 	Return True
 
 
 End
 End
-

+ 66 - 40
modules/std/memory/databuffer.monkey2

@@ -37,11 +37,13 @@ Class DataBuffer
 	
 	
 	@param length The length of the databuffer to create, in bytes.
 	@param length The length of the databuffer to create, in bytes.
 	
 	
+	@param byteOrder Initial byte order of the data.
+	
 	#end
 	#end
-	Method New( length:Int )
+	Method New( length:Int,byteOrder:ByteOrder=std.memory.ByteOrder.LittleEndian )
 		_length=length
 		_length=length
 		_data=Cast<UByte Ptr>( libc.malloc( length ) )
 		_data=Cast<UByte Ptr>( libc.malloc( length ) )
-		_byteOrder=ByteOrder.LittleEndian
+		_byteOrder=byteOrder
 		_swapEndian=False
 		_swapEndian=False
 	End
 	End
 	
 	
@@ -82,7 +84,7 @@ Class DataBuffer
 
 
 	#rem monkeydoc Resizes the databuffer.
 	#rem monkeydoc Resizes the databuffer.
 	
 	
-	Note: This method reallocates the internal memory buffer and will cause the Data property to change.
+	Note: This method reallocates the internal memory buffer and will cause the [[Data]] property to change.
 	
 	
 	@param length The new length of the databuffer.
 	@param length The new length of the databuffer.
 	
 	
@@ -98,9 +100,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The byte read from `offset`.
+	@return The byte read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekByte:Byte( offset:Int )
 	Method PeekByte:Byte( offset:Int )
@@ -113,9 +115,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The ubyte read from `offset`.
+	@return The ubyte read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekUByte:UByte( offset:Int )
 	Method PeekUByte:UByte( offset:Int )
@@ -128,9 +130,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The short read from `offset`.
+	@return The short read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekShort:Short( offset:Int )
 	Method PeekShort:Short( offset:Int )
@@ -145,9 +147,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The ushort read from `offset`.
+	@return The ushort read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekUShort:UShort( offset:Int )
 	Method PeekUShort:UShort( offset:Int )
@@ -162,9 +164,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The int read from `offset`.
+	@return The int read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekInt:Int( offset:Int )
 	Method PeekInt:Int( offset:Int )
@@ -179,9 +181,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The uint read from `offset`.
+	@return The uint read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekUInt:UInt( offset:Int )
 	Method PeekUInt:UInt( offset:Int )
@@ -196,9 +198,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The long read from `offset`.
+	@return The long read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekLong:Long( offset:Int )
 	Method PeekLong:Long( offset:Int )
@@ -213,9 +215,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The ulong read from `offset`.
+	@return The ulong read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekULong:ULong( offset:Int )
 	Method PeekULong:ULong( offset:Int )
@@ -230,9 +232,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The float read from `offset`.
+	@return The float read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekFloat:Float( offset:Int )
 	Method PeekFloat:Float( offset:Int )
@@ -247,9 +249,9 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to read.
+	@param offset The offset to read.
 	
 	
-	#return The double read from `offset`.
+	@return The double read from `offset`.
 	
 	
 	#end
 	#end
 	Method PeekDouble:Double( offset:Int )
 	Method PeekDouble:Double( offset:Int )
@@ -260,7 +262,18 @@ Class DataBuffer
 		Return t
 		Return t
 	End
 	End
 	
 	
-	#rem monkeydoc Reads a utf8 string from the databuffer.
+	#rem monkeydoc Reads a string from the databuffer.
+	
+	If `count` is omitted, all bytes from `offset` until the end of the data buffer are read.
+	
+	`encoding` should be one of "utf8" or "ascii".
+
+	@param offset Byte offset to read the string.
+	
+	@param count Number of bytes to read.
+	
+	@param encoding The encoding to use.
+	
 	#end
 	#end
 	Method PeekString:String( offset:Int,encoding:String="utf8" )
 	Method PeekString:String( offset:Int,encoding:String="utf8" )
 		DebugAssert( offset>=0 And offset<=_length )
 		DebugAssert( offset>=0 And offset<=_length )
@@ -270,6 +283,7 @@ Class DataBuffer
 	
 	
 	Method PeekString:String( offset:Int,count:Int,encoding:String="utf8" )
 	Method PeekString:String( offset:Int,count:Int,encoding:String="utf8" )
 		DebugAssert( offset>=0 And count>=0 And offset+count<=_length )
 		DebugAssert( offset>=0 And count>=0 And offset+count<=_length )
+		DebugAssert( encoding="utf8" Or encoding="ascii" )
 		
 		
 		If encoding="utf8" Return String.FromUtf8Data( _data+offset,count )
 		If encoding="utf8" Return String.FromUtf8Data( _data+offset,count )
 		
 		
@@ -280,7 +294,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeByte( offset:Int,value:Byte )
 	Method PokeByte( offset:Int,value:Byte )
@@ -293,7 +307,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeUByte( offset:Int,value:UByte )
 	Method PokeUByte( offset:Int,value:UByte )
@@ -306,7 +320,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeShort( offset:Int,value:Short )
 	Method PokeShort( offset:Int,value:Short )
@@ -320,7 +334,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeUShort( offset:Int,value:UShort )
 	Method PokeUShort( offset:Int,value:UShort )
@@ -334,7 +348,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeInt( offset:Int,value:Int )
 	Method PokeInt( offset:Int,value:Int )
@@ -348,7 +362,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeUInt( offset:Int,value:UInt )
 	Method PokeUInt( offset:Int,value:UInt )
@@ -362,7 +376,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeLong( offset:Int,value:Long )
 	Method PokeLong( offset:Int,value:Long )
@@ -376,7 +390,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeULong( offset:Int,value:ULong )
 	Method PokeULong( offset:Int,value:ULong )
@@ -390,7 +404,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeFloat( offset:Int,value:Float )
 	Method PokeFloat( offset:Int,value:Float )
@@ -404,7 +418,7 @@ Class DataBuffer
 	
 	
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	In debug builds, a runtime error will occur if `offset` is outside the range of the databuffer.
 	
 	
-	#param offset The offset to write.
+	@param offset The offset to write.
 	
 	
 	#end
 	#end
 	Method PokeDouble( offset:Int,value:Double )
 	Method PokeDouble( offset:Int,value:Double )
@@ -414,12 +428,24 @@ Class DataBuffer
 		Cast<Double Ptr>( _data+offset )[0]=value
 		Cast<Double Ptr>( _data+offset )[0]=value
 	End
 	End
 
 
-	#rem monkeydoc Write a string to the databuffer in utf8 format.
+	#rem monkeydoc Write a string to the databuffer.
+
+	`encoding` should be one of "utf8" or "ascii".
+	
+	If there is not enough room in the data buffer, the string data is truncated.
+	
+	@param offset Byte offset to write the string.
+	
+	@param value The string to write.
+	
+	@param encoding The encoding to use.
 	
 	
 	#end	
 	#end	
 	Method PokeString( offset:Int,value:String,encoding:String="utf8" )
 	Method PokeString( offset:Int,value:String,encoding:String="utf8" )
 		DebugAssert( offset>=0 And offset<=_length )
 		DebugAssert( offset>=0 And offset<=_length )
 		
 		
+		DebugAssert( encoding="utf8" Or encoding="ascii" )
+		
 		If encoding="utf8"
 		If encoding="utf8"
 			Local count:=value.Utf8Length
 			Local count:=value.Utf8Length
 			If offset+count>_length count=_length-offset
 			If offset+count>_length count=_length-offset
@@ -429,6 +455,7 @@ Class DataBuffer
 			If offset+count>_length count=_length-offset
 			If offset+count>_length count=_length-offset
 			value.ToCString( _data+offset,count )
 			value.ToCString( _data+offset,count )
 		Endif
 		Endif
+
 	End
 	End
 
 
 	#rem monkeydoc Creates a slice of the databuffer.
 	#rem monkeydoc Creates a slice of the databuffer.
@@ -463,7 +490,7 @@ Class DataBuffer
 		Return data
 		Return data
 	End
 	End
 	
 	
-	#rem monkeydoc Copies databuffer data.
+	#rem monkeydoc Copies databuffer data to another databuffer.
 	
 	
 	In debug builds, a runtime error while occur if an attempt it made to copy data outside the range of either databuffer.
 	In debug builds, a runtime error while occur if an attempt it made to copy data outside the range of either databuffer.
 	
 	
@@ -513,12 +540,11 @@ Class DataBuffer
 		Local stream:=Stream.Open( path,"r" )
 		Local stream:=Stream.Open( path,"r" )
 		If Not stream Return Null
 		If Not stream Return Null
 		
 		
-		Local length:=stream.Length
-		Local buf:=New DataBuffer( length )
-		stream.Read( buf.Data,length )
+		Local data:=stream.ReadAll()
 		
 		
 		stream.Close()
 		stream.Close()
-		Return buf
+		
+		Return data
 	End
 	End
 
 
 	Private
 	Private

+ 43 - 17
modules/std/stream/datastream.monkey2 → modules/std/memory/datastream.monkey2

@@ -1,22 +1,41 @@
 
 
-Namespace std.stream
+Namespace std.memory
 
 
 #rem monkeydoc DataStream class.
 #rem monkeydoc DataStream class.
 #end
 #end
-Class DataStream Extends Stream
+Class DataStream Extends std.stream.Stream
 
 
 	#rem monkeydoc Creates a new datastream.
 	#rem monkeydoc Creates a new datastream.
+	
+	A datastream wraps a databuffer so it can be used as if it were a stream.
+	
+	In debug mode, a RuntimeError will occur if `offset` or `count` are outside the range of the databuffer.
+	
+	@param data The databuffer to wrap.
+	
+	@param offset The starting offset.
+	
+	@param count The number of bytes.
+	
 	#end
 	#end
-	Method New( buf:DataBuffer )
+	Method New( buf:DataBuffer,offset:Int=0 )
+		Self.New( buf,offset,buf.Length-offset )
+		
+	End
+
+	Method New( buf:DataBuffer,offset:Int,count:Int )
+		DebugAssert( offset>=0 And count>=0 And offset+count<=buf.Length )
+		
 		_buf=buf
 		_buf=buf
+		_off=offset
+		_len=count
 		_pos=0
 		_pos=0
-		_end=_buf.Length
 	End
 	End
 	
 	
 	#rem monkeydoc True if no more data can be read from or written to the stream.
 	#rem monkeydoc True if no more data can be read from or written to the stream.
 	#end
 	#end
 	Property Eof:Bool() Override
 	Property Eof:Bool() Override
-		Return _pos>=_end
+		Return _pos>=_len
 	End
 	End
 	
 	
 	#rem monkeydoc Current datastream position.
 	#rem monkeydoc Current datastream position.
@@ -28,19 +47,18 @@ Class DataStream Extends Stream
 	#rem monkeydoc Current datastream length.
 	#rem monkeydoc Current datastream length.
 	#end
 	#end
 	Property Length:Int() Override
 	Property Length:Int() Override
-		Return _end
+		Return _len
 	End
 	End
 	
 	
 	#rem monkeydoc Closes the datastream.
 	#rem monkeydoc Closes the datastream.
 	
 	
-	Closing a datastream also sets its position and length to 0.
-	
 	#end
 	#end
 	Method Close() Override
 	Method Close() Override
 		If Not _buf Return
 		If Not _buf Return
 		_buf=Null
 		_buf=Null
+		_off=0
 		_pos=0
 		_pos=0
-		_end=0
+		_len=0
 	End
 	End
 	
 	
 	#rem monkeydoc Seeks to a position in the datastream.
 	#rem monkeydoc Seeks to a position in the datastream.
@@ -49,9 +67,8 @@ Class DataStream Extends Stream
 	
 	
 	#end
 	#end
 	Method Seek( position:Int ) Override
 	Method Seek( position:Int ) Override
-		DebugAssert( position>=0 And position<=_end )
-		
-		_pos=position
+
+		_pos=Clamp( position,0,_len )
 	End
 	End
 	
 	
 	#rem monkeydoc Reads data from the datastream.
 	#rem monkeydoc Reads data from the datastream.
@@ -64,9 +81,13 @@ Class DataStream Extends Stream
 	
 	
 	#end
 	#end
 	Method Read:Int( buf:Void Ptr,count:Int ) Override
 	Method Read:Int( buf:Void Ptr,count:Int ) Override
-		count=Clamp( count,0,_end-_pos )
-		libc.memcpy( buf,_buf.Data+_pos,count )
+	
+		count=Clamp( count,0,_len-_pos )
+		
+		libc.memcpy( buf,_buf.Data+_off+_pos,count )
+		
 		_pos+=count
 		_pos+=count
+		
 		Return count
 		Return count
 	End
 	End
 	
 	
@@ -80,16 +101,21 @@ Class DataStream Extends Stream
 	
 	
 	#end
 	#end
 	Method Write:Int( buf:Void Ptr,count:Int ) Override
 	Method Write:Int( buf:Void Ptr,count:Int ) Override
-		count=Clamp( count,0,_end-_pos )
-		libc.memcpy( _buf.Data+_pos,buf,count )
+	
+		count=Clamp( count,0,_len-_pos )
+		
+		libc.memcpy( _buf.Data+_off+_pos,buf,count )
+		
 		_pos+=count
 		_pos+=count
+		
 		Return count
 		Return count
 	End
 	End
 
 
 	Private
 	Private
 	
 	
 	Field _buf:DataBuffer
 	Field _buf:DataBuffer
+	Field _off:Int
 	Field _pos:Int
 	Field _pos:Int
-	Field _end:Int
+	Field _len:Int
 
 
 End
 End

+ 2 - 0
modules/std/misc/zipfile.monkey2

@@ -1,6 +1,8 @@
 
 
 Namespace std.zipfile
 Namespace std.zipfile
 
 
+Using miniz
+
 #rem monkeydoc @hidden
 #rem monkeydoc @hidden
 #end
 #end
 Class ZipFile
 Class ZipFile

+ 31 - 3
modules/std/socket/socket.monkey2

@@ -49,6 +49,7 @@ Class Socket Extends std.stream.Stream
 	#rem monkeydoc True if socket has been closed.
 	#rem monkeydoc True if socket has been closed.
 	#end
 	#end
 	Property Eof:Bool() Override
 	Property Eof:Bool() Override
+
 		Return _socket<0
 		Return _socket<0
 	End
 	End
 
 
@@ -59,11 +60,11 @@ Class Socket Extends std.stream.Stream
 		Return 0
 		Return 0
 	End
 	End
 
 
-	#rem monkeydoc Always 0.
+	#rem monkeydoc Always -1.
 	#end
 	#end
 	Property Length:Int() Override
 	Property Length:Int() Override
 	
 	
-		Return 0
+		Return -1
 	End
 	End
 
 
 	#rem monkeydoc Closes the socket.
 	#rem monkeydoc Closes the socket.
@@ -87,6 +88,12 @@ Class Socket Extends std.stream.Stream
 	Returns 0 if the socket has been closed by the peer.
 	Returns 0 if the socket has been closed by the peer.
 	
 	
 	Can return less than `count`, in which case you may have to read again if you know there's more data coming.
 	Can return less than `count`, in which case you may have to read again if you know there's more data coming.
+	
+	@param buf The memory buffer to read data into.
+	
+	@param count The number of bytes to read from the socket.
+	
+	@return The number of bytes actually read.
 
 
 	#end
 	#end
 	Method Read:Int( buf:Void Ptr,count:Int ) Override
 	Method Read:Int( buf:Void Ptr,count:Int ) Override
@@ -99,8 +106,16 @@ Class Socket Extends std.stream.Stream
 	
 	
 	Writes `count` bytes to the socket.
 	Writes `count` bytes to the socket.
 	
 	
+	Returns the number of bytes actually written.
+	
 	Can return less than `count` if the socket has been closed by the peer or if an error occured.
 	Can return less than `count` if the socket has been closed by the peer or if an error occured.
 	
 	
+	@param buf The memory buffer to read data from.
+	
+	@param count The number of bytes to write to the socket.
+	
+	@return The number of bytes actually written.
+
 	#end
 	#end
 	Method Write:Int( buf:Void Ptr,count:Int ) Override
 	Method Write:Int( buf:Void Ptr,count:Int ) Override
 		If _socket<0 Return 0
 		If _socket<0 Return 0
@@ -136,6 +151,10 @@ Class Socket Extends std.stream.Stream
 	
 	
 	`service` can be an integer port number.
 	`service` can be an integer port number.
 	
 	
+	@param hostname The name of the host to connect to.
+	
+	@param service The service or port to connect to.
+	
 	#end	
 	#end	
 	Function Connect:Socket( hostname:String,service:String )
 	Function Connect:Socket( hostname:String,service:String )
 	
 	
@@ -166,6 +185,11 @@ Class SocketServer
 	End
 	End
 
 
 	#rem monkeydoc Accepts a new connection.
 	#rem monkeydoc Accepts a new connection.
+	
+	Waits until a new incoming connection is available.
+	
+	@return A new connection, or null if there is a network error.
+	
 	#end
 	#end
 	Method Accept:Socket()
 	Method Accept:Socket()
 		If _socket<0 Return Null
 		If _socket<0 Return Null
@@ -176,12 +200,16 @@ Class SocketServer
 		Return New Socket( socket )
 		Return New Socket( socket )
 	End
 	End
 
 
-	#rem monkeydoc Creates a server and starts it listening.
+	#rem monkeydoc Creates a server and starts listening.
 	
 	
 	Returns a new server if successful, else null.
 	Returns a new server if successful, else null.
 	
 	
 	`service` can be an integer port number.
 	`service` can be an integer port number.
 	
 	
+	@param service The service or port to listen on.
+	
+	@param queue The number of incoming connections that can be queued.
+	
 	#end
 	#end
 	Function Listen:SocketServer( service:String,queue:Int=128 )
 	Function Listen:SocketServer( service:String,queue:Int=128 )
 	
 	

+ 12 - 13
modules/std/std.monkey2

@@ -5,6 +5,7 @@ Namespace std
 #Import "<stb-image>"
 #Import "<stb-image>"
 #Import "<stb-image-write>"
 #Import "<stb-image-write>"
 #import "<stb-vorbis>"
 #import "<stb-vorbis>"
+#Import "<miniz>"
 
 
 #Import "collections/container"
 #Import "collections/container"
 #Import "collections/stack"
 #Import "collections/stack"
@@ -12,13 +13,12 @@ Namespace std
 #Import "collections/map"
 #Import "collections/map"
 #Import "collections/deque"
 #Import "collections/deque"
 
 
-#Import "memory/byteorder"
-#Import "memory/databuffer"
-
 #Import "stream/stream"
 #Import "stream/stream"
 #Import "stream/filestream"
 #Import "stream/filestream"
-#Import "stream/datastream"
-#Import "stream/zipstream"
+
+#Import "memory/byteorder"
+#Import "memory/databuffer"
+#Import "memory/datastream"
 
 
 #Import "geom/vec2"
 #Import "geom/vec2"
 #Import "geom/vec3"
 #Import "geom/vec3"
@@ -66,20 +66,19 @@ Function Main()
 	'
 	'
 	std.time.Microsecs()
 	std.time.Microsecs()
 
 
-	Stream.OpenFuncs["zip"]=Lambda:Stream( proto:String,path:String,mode:String )
-
-		Return ZipStream.Open( path,mode )
-	End
-
+	'Add 'file::' stream protocol
+	'
 	Stream.OpenFuncs["file"]=Lambda:Stream( proto:String,path:String,mode:String )
 	Stream.OpenFuncs["file"]=Lambda:Stream( proto:String,path:String,mode:String )
 
 
 		Return FileStream.Open( path,mode )
 		Return FileStream.Open( path,mode )
 	End
 	End
 	
 	
-	'Note: "asset::" support for android/ios is in mojo, as it uses SDL_RWop and we don't want to std to be dependant on SDL2...
-	'	
 #If Not __MOBILE_TARGET__
 #If Not __MOBILE_TARGET__
-	
+
+	'Add 'asset::' stream protocol
+	'	
+	'Note: "asset::" support for android/ios is in mojo, as it uses SDL_RWop and we don't want std to be dependant on SDL2...
+	'	
 	Stream.OpenFuncs["asset"]=Lambda:Stream( proto:String,path:String,mode:String )
 	Stream.OpenFuncs["asset"]=Lambda:Stream( proto:String,path:String,mode:String )
 
 
 		Return FileStream.Open( filesystem.AssetsDir()+path,mode )
 		Return FileStream.Open( filesystem.AssetsDir()+path,mode )

+ 47 - 41
modules/std/stream/stream.monkey2

@@ -40,30 +40,56 @@ Class Stream
 	#end
 	#end
 	Method Seek( position:Int ) Abstract
 	Method Seek( position:Int ) Abstract
 	
 	
-	#rem monkeydoc Reads data from the filestream to memory.
+	#rem monkeydoc Reads data from the stream into memory.
 	
 	
-	@param mem A pointer to the memory to read the data into.
+	Reads `count` bytes of data from the stream into either a raw memory pointer or a databuffer.
 	
 	
-	@param count The number of bytes to read.
+	Returns the number of bytes actually read.
+	
+	@param buf A pointer to the memory to read the data into.
+	
+	@param data The databuffer to read the data into.
+	
+	@param count The number of bytes to read from the stream.
 	
 	
 	@return The number of bytes actually read.
 	@return The number of bytes actually read.
 	
 	
 	#end
 	#end
-	Method Read:Int( mem:Void Ptr,count:Int ) Abstract
+	Method Read:Int( buf:Void Ptr,count:Int ) Abstract
+	
+	Method Read:Int( data:DataBuffer,offset:Int,count:Int )
+		DebugAssert( offset>=0 And count>=0 And offset+count<=data.Length )
+		
+		Return Read( data.Data+offset,count )
+	End
 	
 	
 	#rem monkeydoc Writes data to the stream from memory.
 	#rem monkeydoc Writes data to the stream from memory.
 	
 	
-	@param mem A pointer to the memory to write the data from.
+	Writes `count` bytes of data to the stream from either a raw memory pointer or a databuffer.
+	
+	Returns the number of bytes actually written
 	
 	
-	@param count The number of bytes to write.
+	@param buf A pointer to the memory to write the data from.
+
+	@param data The databuffer to write the data from.
+	
+	@param count The number of bytes to write to the stream.
 	
 	
 	@return The number of bytes actually written.
 	@return The number of bytes actually written.
 	
 	
 	#end
 	#end
-	Method Write:Int( mem:Void Ptr,count:Int ) Abstract
+	Method Write:Int( buf:Void Ptr,count:Int ) Abstract
+
+	Method Write:Int( data:DataBuffer,offset:Int,count:Int )
+		DebugAssert( offset>=0 And count>=0 And offset+count<=data.Length )
 
 
+		Return Write( data.Data+offset,count )
+	End
 
 
 	#rem monkeydoc The byte order of the stream.
 	#rem monkeydoc The byte order of the stream.
+	
+	The default byte order is ByteOrder.BigEndian.
+	
 	#end
 	#end
 	Property ByteOrder:ByteOrder()
 	Property ByteOrder:ByteOrder()
 		Return _tmpbuf.ByteOrder
 		Return _tmpbuf.ByteOrder
@@ -71,42 +97,12 @@ Class Stream
 		_tmpbuf.ByteOrder=byteOrder
 		_tmpbuf.ByteOrder=byteOrder
 	End
 	End
 	
 	
-	#rem monkeydoc Reads data from the stream into a databuffer.
-	
-	@param buf The databuffer to read the data into.
-	
-	@param offset The start offset in the databuffer.
-	
-	@param count The number of bytes to transfer.
-	
-	@return The number of bytes actually read.
-	
-	#end
-	Method Read:Int( buf:DataBuffer,offset:Int,count:Int )
-		DebugAssert( offset>=0 And count>=0 And offset+count<=buf.Length )
-		
-		Return Read( buf.Data+offset,count )
-	End
-	
-	#rem monkeydoc Writes data to a stream from a databuffer.
-	
-	@param buf The databuffer to write the data from.
-	
-	@param offset The start offset in the databuffer.
-	
-	@param count The number of bytes to transfer.
+	#rem monkeydoc Reads as many bytes as possible from a stream into memory.
 	
 	
-	@return The number of bytes actually written.
+	Continously reads data from a stream until either `count` bytes are read or the end of stream is reached.
 	
 	
-	#end
-	Method Write:Int( buf:DataBuffer,offset:Int,count:Int )
-		DebugAssert( offset>=0 And count>=0 And offset+count<=buf.Length )
+	Returns the number of bytes read or the data read.
 
 
-		Return Write( buf.Data+offset,count )
-	End
-
-	#rem monkeydoc Reads as many bytes as possible from a stream into memory.
-	
 	@param buf memory to read bytes into.
 	@param buf memory to read bytes into.
 	
 	
 	@param data data buffer to read bytes into.
 	@param data data buffer to read bytes into.
@@ -117,11 +113,13 @@ Class Stream
 	Method ReadAll:Int( buf:Void Ptr,count:Int )
 	Method ReadAll:Int( buf:Void Ptr,count:Int )
 	
 	
 		Local pos:=0
 		Local pos:=0
+		
 		While pos<count
 		While pos<count
 			Local n:=Read( Cast<Byte Ptr>( buf )+pos,count-pos )
 			Local n:=Read( Cast<Byte Ptr>( buf )+pos,count-pos )
 			If n<=0 Exit
 			If n<=0 Exit
 			pos+=n
 			pos+=n
 		Wend
 		Wend
+		
 		Return pos
 		Return pos
 	End
 	End
 	
 	
@@ -139,6 +137,8 @@ Class Stream
 	End
 	End
 	
 	
 	Method ReadAll:DataBuffer()
 	Method ReadAll:DataBuffer()
+	
+		If Length>=0 Return ReadAll( Length-Position )
 
 
 		Local bufs:=New Stack<DataBuffer>
 		Local bufs:=New Stack<DataBuffer>
 		Local buf:=New DataBuffer( 4096 ),pos:=0
 		Local buf:=New DataBuffer( 4096 ),pos:=0
@@ -462,8 +462,14 @@ Class Stream
 	#end
 	#end
 	Const OpenFuncs:=New StringMap<OpenFunc>
 	Const OpenFuncs:=New StringMap<OpenFunc>
 	
 	
+	Protected
+	
+	Method New()
+		_tmpbuf=New DataBuffer( 8,ByteOrder.LittleEndian )
+	End
+	
 	Private
 	Private
 	
 	
-	Field _tmpbuf:=New DataBuffer( 8 )
+	Field _tmpbuf:DataBuffer
 
 
 End
 End

+ 0 - 69
modules/std/stream/zipstream.monkey2

@@ -1,69 +0,0 @@
-
-Namespace std.stream
-
-#Import "<miniz.monkey2>"
-
-Using libc
-Using miniz
-
-#rem monkeydoc @hidden ZipStream class.
-#end
-Class ZipStream Extends DataStream
-
-	Method New( buf:DataBuffer )
-		Super.New( buf )
-	End
-	
-	Function Open:ZipStream( path:String,mode:String )
-	
-		If mode<>"r" Return Null
-	
-		Local i:=path.FindLast( "//" )
-		If i=-1 Return Null
-		
-		Local stream:ZipStream
-		
-		Local src:=DataBuffer.Load( path.Slice( 0,i ) )
-		If src
-
-			Local zip:mz_zip_archive
-			memset( Varptr zip,0,sizeof( zip ) )
-			
-			If mz_zip_reader_init_mem( Varptr zip,src.Data,src.Length,0 )
-			
-				Local index:=mz_zip_reader_locate_file( Varptr zip,path.Slice( i+2 ),"",0 )
-				
-				If index>=0
-		
-					Local stat:mz_zip_archive_file_stat
-					memset( Varptr stat,0,sizeof( stat ) )
-					
-					If mz_zip_reader_file_stat( Varptr zip,index,Varptr stat )
-					
-						Local buf:=New DataBuffer( stat.m_uncomp_size )
-						
-						If mz_zip_reader_extract_to_mem( Varptr zip,index,buf.Data,buf.Length,0 )
-						
-							stream=New ZipStream( buf )
-							
-						Else
-						
-							buf.Discard()
-
-						Endif
-					
-					End
-				
-				End
-			
-				mz_zip_reader_end( Varptr zip )
-			End
-			
-			src.Discard()
-			
-		Endif
-		
-		Return stream
-	End
-	
-End

+ 1 - 1
scripts/rebuildmx2cc_raspbian.bat

@@ -6,7 +6,7 @@ echo.
 echo ***** Rebuilding mx2cc *****
 echo ***** Rebuilding mx2cc *****
 echo.
 echo.
 
 
-rem %mx2cc% makemods -clean -config=release -target=raspbian monkey libc miniz stb-image stb-image-write stb-vorbis std
+%mx2cc% makemods -clean -config=release -target=raspbian monkey libc miniz stb-image stb-image-write stb-vorbis std
 %mx2cc% makeapp -build -clean -apptype=console -config=release -target=raspbian ../src/mx2cc/mx2cc.monkey2
 %mx2cc% makeapp -build -clean -apptype=console -config=release -target=raspbian ../src/mx2cc/mx2cc.monkey2
 
 
 copy %mx2cc_raspbian_new% ..\bin\mx2cc_raspbian
 copy %mx2cc_raspbian_new% ..\bin\mx2cc_raspbian

+ 6 - 5
src/mx2cc/docs/docsmaker.monkey2

@@ -1,4 +1,6 @@
 
 
+'This is a MESS!!!!!
+
 Namespace mx2.docs
 Namespace mx2.docs
 
 
 Const PAGES_DIR:="docs/__PAGES__/"
 Const PAGES_DIR:="docs/__PAGES__/"
@@ -348,7 +350,7 @@ Class DocsMaker
 	End
 	End
 	
 	
 	Method SavePage( docs:String,page:String )
 	Method SavePage( docs:String,page:String )
-
+	
 		page=page.Replace( ".","-" )
 		page=page.Replace( ".","-" )
 		
 		
 		docs=_pageTemplate.Replace( "${CONTENT}",docs )
 		docs=_pageTemplate.Replace( "${CONTENT}",docs )
@@ -641,7 +643,6 @@ Class DocsMaker
 		If id.StartsWith( "@" ) id=id.Slice( 1 ).Capitalize()	
 		If id.StartsWith( "@" ) id=id.Slice( 1 ).Capitalize()	
 	
 	
 		EmitNode( id,scope,page )
 		EmitNode( id,scope,page )
-
 	End
 	End
 	
 	
 	Method EndNode()
 	Method EndNode()
@@ -733,9 +734,6 @@ Class DocsMaker
 		
 		
 		_md.Emit( "_"+md+"_" )
 		_md.Emit( "_"+md+"_" )
 	
 	
-'		_md.Emit( "_Module: &lt;"+_module.name+"&gt;_  " )
-'		_md.Emit( "_Namespace: "+nmspace.Name+"_" )
-		
 		EmitMembers( "alias",nmspace,DECL_PUBLIC,-1 )
 		EmitMembers( "alias",nmspace,DECL_PUBLIC,-1 )
 		EmitMembers( "enum",nmspace,DECL_PUBLIC,-1 )
 		EmitMembers( "enum",nmspace,DECL_PUBLIC,-1 )
 		EmitMembers( "struct",nmspace,DECL_PUBLIC,-1 )
 		EmitMembers( "struct",nmspace,DECL_PUBLIC,-1 )
@@ -971,6 +969,8 @@ Class DocsMaker
 			Local buf:StringStack
 			Local buf:StringStack
 					
 					
 			For Local func:=Eachin flist.funcs
 			For Local func:=Eachin flist.funcs
+				If func.IsMethod Or func.IsCtor And func.scope<>scope Continue
+				
 				Local decl:=func.fdecl
 				Local decl:=func.fdecl
 				
 				
 				If DocsHidden( decl,DECL_PUBLIC ) Continue
 				If DocsHidden( decl,DECL_PUBLIC ) Continue
@@ -1018,6 +1018,7 @@ Class DocsMaker
 			Local docs:=_md.Flush()
 			Local docs:=_md.Flush()
 			
 			
 			Local page:=DeclPath( flist.funcs[0].fdecl,flist.funcs[0].scope )
 			Local page:=DeclPath( flist.funcs[0].fdecl,flist.funcs[0].scope )
+
 			SavePage( docs,page )
 			SavePage( docs,page )
 			
 			
 			EmitLeaf( flist.funcs[0].fdecl,page )
 			EmitLeaf( flist.funcs[0].fdecl,page )

+ 5 - 5
src/mx2cc/docs/jsonbuffer.monkey2

@@ -9,13 +9,16 @@ Class JsonBuffer
 
 
 			_indent=_indent.Slice( 0,-2 )
 			_indent=_indent.Slice( 0,-2 )
 			_sep=False
 			_sep=False
-			
+
 			If _blks.Pop()=_buf.Length
 			If _blks.Pop()=_buf.Length
+			
 				_buf.Resize( _buf.Length-1 )
 				_buf.Resize( _buf.Length-1 )
+				
 				If _buf.Length
 				If _buf.Length
 					Local t:=_buf.Top
 					Local t:=_buf.Top
 					If Not (t.EndsWith( "{" ) Or t.EndsWith( "[" )) _sep=True
 					If Not (t.EndsWith( "{" ) Or t.EndsWith( "[" )) _sep=True
 				Endif
 				Endif
+				
 				Return
 				Return
 			Endif
 			Endif
 
 
@@ -23,6 +26,7 @@ Class JsonBuffer
 	
 	
 		If _sep json=","+json
 		If _sep json=","+json
 		_buf.Push( _indent+json )
 		_buf.Push( _indent+json )
+		_sep=True
 	
 	
 		If json.EndsWith( "{" ) Or json.EndsWith( "[" ) 
 		If json.EndsWith( "{" ) Or json.EndsWith( "[" ) 
 
 
@@ -30,11 +34,7 @@ Class JsonBuffer
 
 
 			_indent+="  "
 			_indent+="  "
 			_sep=False
 			_sep=False
-
-			Return
 		Endif
 		Endif
-
-		_sep=True
 	
 	
 	End
 	End
 	
 	

+ 42 - 22
src/mx2cc/docs/minimarkdown.monkey2

@@ -109,16 +109,21 @@ Class MarkdownConvertor
 	
 	
 	Method Find:Int( str:String,chr:String,index:Int=0 )
 	Method Find:Int( str:String,chr:String,index:Int=0 )
 
 
+		Local i0:=index
+
 		Repeat
 		Repeat
-			Local i:=str.Find( chr,index )
-			If i=-1 Return str.Length
-			If i=0 Or str[i-1]<>CHAR_ESCAPE Return i
-			index=i+1
+		
+			Local i1:=str.Find( chr,i0 )
+			If i1=-1 Return str.Length
+			
+			If i1=0 Or str[i1-1]<>CHAR_ESCAPE Return i1
+			
+			i0=i1+1
 		Forever
 		Forever
 		
 		
 		Return str.Length
 		Return str.Length
 	End
 	End
-	
+
 	Method ReplaceAll:String( str:String,find:String,rep:String,index:Int )
 	Method ReplaceAll:String( str:String,find:String,rep:String,index:Int )
 	
 	
 		Local i0:=index
 		Local i0:=index
@@ -144,21 +149,30 @@ Class MarkdownConvertor
 		
 		
 			Local i1:=str.Find( "&",i0 )
 			Local i1:=str.Find( "&",i0 )
 			If i1=-1 Exit
 			If i1=-1 Exit
-
-			Const tags:=New String[]( "nbsp;" )
-
-			For Local tag:=Eachin tags
-				If str.Slice( i1+1,i1+1+tag.Length )<>tag Continue
-				i0=i1+1+tag.Length
-				Exit
-			Next
-			If i0>i1 Continue
+			
+			Local i2:=str.Find( ";",i1+1 )
+			If i2<>-1 And i2-i1<8
+			
+				Local r:=str.Slice( i1+1,i2 )
+				
+				Const tags:=New String[]( "nbsp" )
+				
+				For Local tag:=Eachin tags
+					If r<>tag Continue
+					
+					i0=i2+1
+					Exit
+				Next
+				
+				If i0>i1 Continue
+			Endif
 			
 			
 			Local r:="&amp;"
 			Local r:="&amp;"
 			str=str.Slice( 0,i1 )+r+str.Slice( i1+1 )
 			str=str.Slice( 0,i1 )+r+str.Slice( i1+1 )
 			i0=i1+r.Length
 			i0=i1+r.Length
-		Forever
 		
 		
+		Forever
+
 		'str=str.Replace( "<","&lt;" )
 		'str=str.Replace( "<","&lt;" )
 		'str=str.Replace( ">","&gt;" )
 		'str=str.Replace( ">","&gt;" )
 		i0=0
 		i0=0
@@ -172,32 +186,38 @@ Class MarkdownConvertor
 			
 			
 			Local i2:=str.Find( ">",i1+1 )
 			Local i2:=str.Find( ">",i1+1 )
 			If i2=-1
 			If i2=-1
-				str=ReplaceAll( str,"<","&lt;",i0 )
-				str=ReplaceAll( str,">","&gt;",i0 )
+				str=ReplaceAll( str,"<","&lt;",i1 )
 				Exit
 				Exit
 			Endif
 			Endif
 			
 			
+			Local i3:=str.Find( "<",i1+1 )
+			If i3<>-1 And i3<i2
+				Local r:="&lt;"
+				str=str.Slice( 0,i1 )+r+str.Slice( i1+1 )
+				i0=i1+r.Length
+				Continue
+			Endif
+			
+			Local r:=str.Slice( i1+1,i2 )
+			
 			Const tags:=New String[]( "a href=","/a" )
 			Const tags:=New String[]( "a href=","/a" )
 			
 			
 			For Local tag:=Eachin tags
 			For Local tag:=Eachin tags
-				If str.Slice( i1+1,i1+1+tag.Length )<>tag Continue
+				If Not r.StartsWith( tag ) Continue
 				
 				
-				Local r:=str.Slice( i1+1,i2 )
-
 				r=r.Replace( "\","\\" )
 				r=r.Replace( "\","\\" )
 				r=r.Replace( "*","\*" )
 				r=r.Replace( "*","\*" )
 				r=r.Replace( "_","\_" )
 				r=r.Replace( "_","\_" )
 				r=r.Replace( "`","\`" )
 				r=r.Replace( "`","\`" )
 				
 				
 				r="<"+r+">"
 				r="<"+r+">"
-
 				str=str.Slice( 0,i1 )+r+str.Slice( i2+1 )
 				str=str.Slice( 0,i1 )+r+str.Slice( i2+1 )
 				i0=i1+r.Length
 				i0=i1+r.Length
 				Exit
 				Exit
 			Next
 			Next
 			If i0>i1 Continue
 			If i0>i1 Continue
 			
 			
-			Local r:="&lt;"+str.Slice( i1+1,i2 )+"&gt;"
+			r="&lt;"+r+"&gt;"
 			str=str.Slice( 0,i1 )+r+str.Slice( i2+1 )
 			str=str.Slice( 0,i1 )+r+str.Slice( i2+1 )
 			i0=i1+r.Length
 			i0=i1+r.Length
 		Forever
 		Forever