Bläddra i källkod

Module tweaks

Mark Sibly 9 år sedan
förälder
incheckning
248f59a323

+ 1 - 0
modules/modules.txt

@@ -11,3 +11,4 @@ std
 gles20
 sdl2
 sdl2-mixer
+mojo2

+ 42 - 1
modules/monkey/debug.monkey2

@@ -3,15 +3,56 @@ Namespace monkey.debug
 
 Extern
 
+#rem monkeydoc @hidden
+#end
 Function DebugStop()="bbDB::stop"
 
+#rem monkeydoc Generates a runtime error if a boolean expression is false.
+
+@param condition The boolean condition to check.
+
+@param message Runtime error message to generate.
+
+#end
 Function Assert( condition:Bool )="bbAssert"
 
 Function Assert( condition:Bool,message:String )="bbAssert"
 
+#rem monkeydoc Generates a runtime error if a boolean expression is false (Debug builds only).
+
+This function does not execute at all in release builds, so make sure that @condition doesn't inadvertantly execute
+any critical code.
+
+@param condition The boolean condition to check.
+
+@param message Runtime error message to generate.
+
+#end
 Function DebugAssert( condition:Bool )="bbDebugAssert"
 
 Function DebugAssert( condition:Bool,message:String )="bbDebugAssert"
 
-Function DebugStack:String[]()="bbDebugStack"
+#rem monkeydoc Gets the current stack state (Debug builds only).
+
+In release mode, an empty array is returned.
+
+@example
+Namespace test
+
+Function Test2()
+	Print "~n".Join( GetDebugStack() )
+End
+
+Function Test()
+	Test2()
+End
+
+Function Main()
+	Test()
+End
+@end
+
+@return A string array reprenting the current stack state.
 
+#end
+Function GetDebugStack:String[]()="bbDB::stack"

+ 150 - 29
modules/monkey/math.monkey2

@@ -3,39 +3,172 @@ Namespace monkey.math
 
 Using monkey.types
 
-Const Pi:Double=3.1415926535897932384626433832795028841971693993751058209749445923078164062
+#rem monkeydoc The value _Pi_.
+#end
+Const Pi:Double=3.1415926535897931
+
+#rem monkeydoc The value _Pi_ times 2.
+#end
+Const TwoPi:Double=6.2831853071795862
 
 Extern
 
+#rem monkeydoc Computes the sine of an angle.
+
+@param `x` the angle, in radians.
+
+@return The sine of `x`.
+
+#end
 Function Sin:Double( x:Double )="std::sin"
 
+#rem monkeydoc Computes the cosine of an angle.
+
+@param `x` the angle, in radians.
+
+@return The cosine of `x`.
+
+#end
 Function Cos:Double( x:Double )="std::cos"
 
+#rem monkeydoc Computes the tangent of an angle.
+
+@param `x` the angle, in radians.
+
+@return The tangent of `x`.
+
+#end
 Function Tan:Double( x:Double )="std::tan"
 
-Function ASin:Double( x:Double)="std::asin"
+#rem monkeydoc Computes the inverse sine of a number.
+
+@param `x` The number.
+
+@return The inverse sine of `x`, in radians.
+
+#end
+Function ASin:Double( x:Double )="std::asin"
+
+#rem monkeydoc Computes the inverse cosine of a number.
+
+@param `x` The number.
 
-Function ACos:Double( x:Double)="std::acos"
+@return The inverse cosine of `x`, in radians.
 
-Function ATan:Double( x:Double)="std::atan"
+#end
+Function ACos:Double( x:Double )="std::acos"
+
+#rem monkeydoc Computes the inverse tagent of a number.
+
+@param `x` The number.
+
+@return The inverse tangent of `x`, in radians.
+
+#end
+Function ATan:Double( x:Double )="std::atan"
 
-Function ATan2:Double( x:Double)="std::atan2"
+#rem monkeydoc Computes the inverse tangent of a ratio.
 
+The function uses the signs of `x` and `y` to compute the correct sign for the result.
+
+@param `x` The numerator.
+
+@param `y` The denominator.
+
+@return The inverse tangent of `x`/`y`, in radians.
+
+#end
+Function ATan2:Double( x:Double,y:Double )="std::atan2"
+
+#rem monkeydoc Computes the square root of a number.
+
+@param `x` The number.
+
+@return The square root of `x`.
+
+#end
 Function Sqrt:Double( x:Double )="std::sqrt"
 
+#rem monkeydoc Computes the floor of a number.
+
+@param `x` The number.
+
+@return The largest integral value not greater than `x`.
+
+#end
 Function Floor:Double( x:Double )="std::floor"
 
+#rem monkeydoc Computes the ceiling of a number.
+
+@param `x` The number.
+
+@return The smallest integral value not less than `x`.
+
+#end
 Function Ceil:Double( x:Double )="std::ceil"
 
+#rem monkeydoc Rounds a number to the nearest integral value.
+
+@param `x` The number.
+
+@return The integral value nearest to `x`.
+
+#end
 Function Round:Double( x:Double )="std::round"
 
-Public
 
-#rem monkeydoc
+#rem monkeydoc Raises a number to a power.
+
+@param `x` The number.
+
+@return `x` raised to the power of `y`.
+
+#end
+Function Pow:Double( x:Double,y:Double )="std::pow"
+
+
+#rem monkeydoc Computes the natural logarithm of a number.
+
+@param `x` The number.
+
+@return The natural logarithm of `x`.
+
+#end
+Function Log:Double( x:Double )="std::log"
+
+#rem monkeydoc Computes the base 2 logarithm of a number.
+
+@param `x` The number.
+
+@return The base 2 logarithm of `x`.
 
-Returns the smaller of two values.
+#end
+Function Log2:Double( x:Double )="std::log2"
+
+#rem monkeydoc Computes the base 10 logarithm of a number.
+
+@param `x` The number.
 
-@return the smaller of `x` and `y`.
+@return The base 10 logarithm of `x`.
+
+#end
+Function Log10:Double( x:Double )="std::log10"
+
+#rem monkeydoc Raise _e_ to a power.
+
+@param `x` The number.
+
+@return The value _e_ raised to the power of `x`.
+
+#end
+Function Exp:Double( x:Double )="std::exp"
+
+
+Public
+
+#rem monkeydoc Gets the smaller of two numbers.
+
+@return The smaller of `x` and `y`.
 
 #end
 Function Min<T>:T( x:T,y:T )
@@ -43,11 +176,9 @@ Function Min<T>:T( x:T,y:T )
 	Return y
 End
 
-#rem monkeydoc
-
-Returns the larger of two values.
+#rem monkeydoc Gets the larger of two number.
 
-@return the larger of `x` and `y`.
+@return The larger of `x` and `y`.
 
 #end
 Function Max<T>:T( x:T,y:T )
@@ -55,9 +186,7 @@ Function Max<T>:T( x:T,y:T )
 	Return y
 End
 
-#rem monkeydoc
-
-Clamps a value to a range.
+#rem monkeydoc Clamps a value to a range.
 
 If `x` is less than `min`, `min` is returned.
 
@@ -74,15 +203,13 @@ Function Clamp<T>:T( value:T,min:T,max:T )
 	Return value
 End
 
-#rem monkeydoc
-
-Returns the absolute value of a number.
+#rem monkeydoc Gets the absolute value of a number.
 
 If `x` is less than 0, then `-x` is returned.
 
 If `x` is greater than or equal to 0, then `x` is returned.
 
-@return the absolute value of `x`.
+@return The absolute value of `x`.
 
 #end
 Function Abs<T>:T( x:T ) Where T Implements INumeric
@@ -90,17 +217,11 @@ Function Abs<T>:T( x:T ) Where T Implements INumeric
 	Return -x
 End
 
-#rem monkeydoc
-
-Returns the sign of a number.
-
-If `x` is less than 0, the value -1 is returned.
-
-If `x` is equal to 0, the value 1 is returned.
+#rem monkeydoc Gets the sign of a number.
 
-Otherwise, if `x` is equal to 0, 0 is returned.
+Returns -1 is `x` less than 0, 1 if `x` is greater than 0 or 0 if `x` is equal to 0.
 
-@return the sign of `x`.
+@return The sign of `x`.
 
 #end
 Function Sgn<T>:Int( x:T ) Where T Implements IIntegral

+ 1 - 1
modules/monkey/native/bbmonkey.h

@@ -17,7 +17,7 @@
 extern int bb_argc;
 extern char **bb_argv;
 
-template<class T> int bbCompare( T x,T y ){
+template<class X,class Y> int bbCompare( X x,Y y ){
 	if( y>x ) return -1;
 	return x>y;
 }

+ 123 - 5
modules/monkey/types.monkey2

@@ -85,19 +85,76 @@ Struct @String ="bbString"
 	#end
 	Property Utf8Length:Int()="utf8Length"
 	
-	Method Find:Int( str:String,from:Int=0 )="find"
+	#rem monkeydoc Finds a substring in the string.
 	
-	Method FindLast:Int( str:String,from:Int=0 )="findLast"
+	If `substr` is not found, -1 is returned.
 	
-	Method Contains:Bool( str:String )="contains"
+	@param substr The substring to search for.
 	
+	@param from The start index for the search.
+	
+	@return The index of the first occurance of `substr` in the string, or -1 if `substr` was not found.
+	
+	#end
+	Method Find:Int( substr:String,from:Int=0 )="find"
+	
+	#rem monkeydoc Finds the last occurance of a substring in the string.
+	
+	If `substr` is not found, -1 is returned.
+	
+	@param substr The substring to search for.
+	
+	@param from The start index for the search.
+	
+	@return The index of the last occurance of `substr` in the string, or -1 if `substr` was not found.
+	
+	#end
+	Method FindLast:Int( substr:String,from:Int=0 )="findLast"
+	
+	#rem monkeydoc Checks if the string contains a substring.
+	
+	@param substr The substring to check for.
+	
+	@return True if the string contains `substr`.
+	
+	#end
+	Method Contains:Bool( substr:String )="contains"
+	
+	#rem monkeydoc Check if the string starts with another string.
+	
+	@param substr The string to check for.
+	
+	@return True if the string starts with `substr`.
+	
+	#end
 	Method StartsWith:Bool( str:String )="startsWith"
 	
+	#rem monkeydoc Check if the string ends with another string.
+	
+	@param substr The string to check for.
+	
+	@return True if the string ends with `substr`.
+	
+	#end
 	Method EndsWith:Bool( str:String )="endsWith"
 	
+	#rem monkeydoc Extracts a substring from the string.
+	
+	Returns a string consisting of all characters from `from` until (but not including) `tail`, or until the end of the string if `tail` 
+	is not specified.
+	
+	If either `from` or `tail` is negative, it represents an offset from the end of the string.
+	
+	@param `from` The starting index.
+	
+	@param `tail` The ending index.
+	
+	@return A substring.
+	
+	#end
 	Method Slice:String( from:Int )="slice"
 	
-	Method Slice:String( from:Int,term:Int )="slice"
+	Method Slice:String( from:Int,tail:Int )="slice"
 	
 	Method Left:String( count:Int )="left"
 	
@@ -105,14 +162,43 @@ Struct @String ="bbString"
 	
 	Method Mid:String( from:Int,count:Int )="mid"
 	
+	#rem monkeydoc Convert the string to uppercase.
+	
+	@return The string converted to uppercase.
+	
+	#end
 	Method ToUpper:String()="toUpper"
 	
+	#rem monkeydoc Convert the string to lowercase.
+	
+	@return The string converted to lowercase.
+	
+	#end
 	Method ToLower:String()="toLower"
+
+	#rem monkeydoc Capitalizes the string.
+	
+	@return The string with the first character converted to uppercase and the remaining characters unmodified.
 	
+	#end	
 	Method Capitalize:String()="capitalize"
 	
+	#rem monkeydoc Trim whitespace from a string.
+	
+	@return The string with leading and trailing whitespace removed.
+	
+	#end
 	Method Trim:String()="trim"
 	
+	#rem monkeydoc Replace all occurances of a substring with another string.
+	
+	@param find The string to search for.
+	
+	@param replace The string to replace with.
+	
+	@return The string with `find` replaced with `replace`.
+	
+	#end
 	Method Replace:String( find:String,replace:String )="replace"
 	
 	Method Split:String[]( separator:String )="split"
@@ -136,19 +222,51 @@ Struct @String ="bbString"
 End
 
 #rem monkeydoc Primtive array type.
+
+This is a 'pseduo type' extended by all array types.
+
 #end
 Struct @Array<T>
 
+	#rem monkeydoc The raw memory used by the array.
+	
+	#end
 	Property Data:T Ptr()="data"
 	
+	#rem monkeydoc The length of the array.
+	
+	In the case of multi-dimensional arrays, the length of the array is the product of the sizes of all dimensions.
+	
+	#end
 	Property Length:Int()="length"
 	
-	Method Size:Int( dimension:Int )="size"
+	#rem monkeydoc Extracts a subarray from the array.
+	
+	Returns an array consisting of all elements from `from` until (but not including) `tail`, or until the end of the string
+	if `tail` is not specified.
+	
+	If either `from` or `tail` is negative, it represents an offset from the end of the array.
+	
+	@param `from` The starting index.
 	
+	@param `tail` The ending index.
+	
+	@return A subarray.
+	
+	#end
 	Method Slice:T[]( from:Int )="slice"
 	
 	Method Slice:T[]( from:Int,term:Int )="slice" 
 	
+	#rem monkeydoc Gets the size of a single array dimension.
+	
+	@param dimensions The dimension.
+	
+	@return The size of array in the given dimension.
+	
+	#end
+	Method GetSize:Int( dimension:Int )="size"
+	
 	Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
 
 End

+ 1 - 0
modules/sdl2/sdl2.monkey2

@@ -38,6 +38,7 @@ Const SDL_INIT_GAMECONTROLLER:Int
 Const SDL_INIT_EVENTS:Int
 Const SDL_INIT_NOPARACHUTE:Int
 Const SDL_INIT_EVERYTHING:Int
+
 Function SDL_Init:Int(flags_:Int)
 Function SDL_InitSubSystem:Int(flags_:Int)
 Function SDL_QuitSubSystem:Void(flags_:Int)