types.monkey2 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. Namespace monkey.types
  2. Extern
  3. #rem monkeydoc Implemented by numeric types.
  4. #end
  5. Interface INumeric
  6. End
  7. #rem monkeydoc Implemented by integral numeric types.
  8. #end
  9. Interface IIntegral Extends INumeric
  10. End
  11. #rem monkeydoc Implemented by real numeric types.
  12. #end
  13. Interface IReal Extends INumeric
  14. End
  15. #rem monkeydoc Primitive bool type.
  16. #end
  17. Struct @Bool ="bbBool"
  18. End
  19. #rem monkeydoc Primitive 8 bit byte type.
  20. #end
  21. Struct @Byte Implements IIntegral ="bbByte"
  22. End
  23. #rem monkeydoc Primitive 8 bit unsigned byte type.
  24. #end
  25. Struct @UByte Implements IIntegral ="bbUByte"
  26. End
  27. #rem monkeydoc Primitive 16 bit short type.
  28. #end
  29. Struct @Short Implements IIntegral ="bbShort"
  30. End
  31. #rem monkeydoc Primitive 16 bit unsigned short type.
  32. #end
  33. Struct @UShort Implements IIntegral ="bbUShort"
  34. End
  35. #rem monkeydoc Primitive 32 bit int type.
  36. #end
  37. Struct @Int Implements IIntegral ="bbInt"
  38. End
  39. #rem monkeydoc Primitive 32 bit unsigned int type.
  40. #end
  41. Struct @UInt Implements IIntegral ="bbUInt"
  42. End
  43. #rem monkeydoc Primitive 64 bit long type.
  44. #end
  45. Struct @Long Implements IIntegral ="bbLong"
  46. End
  47. #rem monkeydoc Primitive 64 bit unsigned long type.
  48. #end
  49. Struct @ULong Implements IIntegral ="bbULong"
  50. End
  51. #rem monkeydoc Primitive 32 bit float type.
  52. #end
  53. Struct @Float Implements IReal ="bbFloat"
  54. End
  55. #rem monkeydoc Primitive 64 bit double type.
  56. #end
  57. Struct @Double Implements IReal ="bbDouble"
  58. End
  59. #rem monkeydoc Primitive string type
  60. #end
  61. Struct @String ="bbString"
  62. #rem monkeydoc Gets the length of the string.
  63. @return The number of characters in the string.
  64. #end
  65. Property Length:Int()="length"
  66. #rem monkeydoc Gets the utf8 length of the string.
  67. @return The size of the buffer required to store a utf8 representation of the string.
  68. #end
  69. Property Utf8Length:Int()="utf8Length"
  70. #rem monkeydoc Gets the CString length of the string.
  71. @return The size of the buffer required to store a cstring representation of the string.
  72. #end
  73. Property CStringLength:Int()="utf8Length"
  74. #rem monkeydoc Finds a substring in the string.
  75. If `substr` is not found, -1 is returned.
  76. @param substr The substring to search for.
  77. @param from The start index for the search.
  78. @return The index of the first occurance of `substr` in the string, or -1 if `substr` was not found.
  79. #end
  80. Method Find:Int( substr:String,from:Int=0 )="find"
  81. #rem monkeydoc Finds the last occurance of a substring in the string.
  82. If `substr` is not found, -1 is returned.
  83. @param substr The substring to search for.
  84. @param from The start index for the search.
  85. @return The index of the last occurance of `substr` in the string, or -1 if `substr` was not found.
  86. #end
  87. Method FindLast:Int( substr:String,from:Int=0 )="findLast"
  88. #rem monkeydoc Checks if the string contains a substring.
  89. @param substr The substring to check for.
  90. @return True if the string contains `substr`.
  91. #end
  92. Method Contains:Bool( substr:String )="contains"
  93. #rem monkeydoc Check if the string starts with another string.
  94. @param substr The string to check for.
  95. @return True if the string starts with `substr`.
  96. #end
  97. Method StartsWith:Bool( str:String )="startsWith"
  98. #rem monkeydoc Check if the string ends with another string.
  99. @param substr The string to check for.
  100. @return True if the string ends with `substr`.
  101. #end
  102. Method EndsWith:Bool( str:String )="endsWith"
  103. #rem monkeydoc Extracts a substring from the string.
  104. Returns a string consisting of all characters from `from` until (but not including) `tail`, or until the end of the string if `tail`
  105. is not specified.
  106. If either `from` or `tail` is negative, it represents an offset from the end of the string.
  107. @param `from` The starting index.
  108. @param `tail` The ending index.
  109. @return A substring.
  110. #end
  111. Method Slice:String( from:Int )="slice"
  112. Method Slice:String( from:Int,tail:Int )="slice"
  113. #rem monkeydoc Gets a substring from the start of the string.
  114. Returns a string consisting of the first `count` characters of this string.
  115. If `count` is less than or equal to 0, an empty string is returned.
  116. If `count` is greater than the length of this string, this string is returned.
  117. @param count The number of characters to return.
  118. @return A string consisting of the first `count` characters of this string.
  119. #end
  120. Method Left:String( count:Int )="left"
  121. #rem monkeydoc Gets a substring from the end of the string.
  122. Returns a string consisting of the last `count` characters of this string.
  123. If `count` is less than or equal to 0, an empty string is returned.
  124. If `count` is greater than the length of this string, this string is returned.
  125. @param count The number of characters to return.
  126. @return A string consisting of the last `count` characters of this string.
  127. #end
  128. Method Right:String( count:Int )="right"
  129. #rem monkeydoc Gets a substring from the middle of the string.
  130. Returns a string consisting of `count` characters starting from index `from`.
  131. If `count` is less than or equal to 0, an empty string is returned.
  132. If `from`+`count` is greater than the length of the string, the returned string is truncated.
  133. @param from The index of the first character to return.
  134. @param count The number of characters to return.
  135. @return A string consisting of `count` characters starting from index `from`.
  136. #end
  137. Method Mid:String( from:Int,count:Int )="mid"
  138. #rem monkeydoc Convert the string to uppercase.
  139. Return the string converted to uppercase.
  140. @return The string converted to uppercase.
  141. #end
  142. Method ToUpper:String()="toUpper"
  143. #rem monkeydoc Convert the string to lowercase.
  144. Returns the string converted to lowercase.
  145. @return The string converted to lowercase.
  146. #end
  147. Method ToLower:String()="toLower"
  148. #rem monkeydoc Capitalizes the string.
  149. Returns the string with the first character converted to uppercase and the remaining characters unmodified.
  150. @return The string with the first character converted to uppercase and the remaining characters unmodified.
  151. #end
  152. Method Capitalize:String()="capitalize"
  153. #rem monkeydoc Trim whitespace from a string.
  154. Returns the string with leading and trailing whitespace removed.
  155. @return The string with leading and trailing whitespace removed.
  156. #end
  157. Method Trim:String()="trim"
  158. #rem monkeydoc Trim whitespace from the start a string.
  159. Returns the string with any leading whitespace removed.
  160. @return The string with any leading whitespace removed.
  161. #end
  162. Method TrimStart:String()="trimStart"
  163. #rem monkeydoc Trim whitespace from the end of a string.
  164. Returns the string with any trailing whitespace removed.
  165. @return The string with any trailing whitespace removed.
  166. #end
  167. Method TrimEnd:String()="trimEnd"
  168. #rem monkeydoc Duplicates a string.
  169. Returns the string duplicated `count` times.
  170. @return The string duplicated `count` times.
  171. #end
  172. Method Dup:String( count:Int )="dup"
  173. #rem monkeydoc Replace all occurances of a substring with another string.
  174. Returns the string with all occurances of `find` replaced with `replace`.
  175. @param find The string to search for.
  176. @param replace The string to replace with.
  177. @return The string with all occurances of `find` replaced with `replace`.
  178. #end
  179. Method Replace:String( find:String,replace:String )="replace"
  180. #rem monkeydoc Splits this string.
  181. Splits this string into an array of strings.
  182. @param separator Separator to use for splitting.
  183. @return An array of strings.
  184. #end
  185. Method Split:String[]( separator:String )="split"
  186. #rem monkeydoc Joins an array of strings.
  187. Joins an array of strings, inserting this string between elements.
  188. @param bits The strings to join.
  189. @return The joined string.
  190. #end
  191. Method Join:String( bits:String[] )="join"
  192. #rem monkeydoc Converts the string to a CString.
  193. If there is enough room in the memory buffer, a null terminating '0' is appended to the CString.
  194. @param buf Memory buffer to write the CString to.
  195. @param bufSize Size of the memory buffer in bytes.
  196. #end
  197. Method ToCString( buf:Void Ptr,bufSize:Int )="toCString"
  198. #rem monkeydoc Converts the string to a WString.
  199. If there is enough room in the memory buffer, a null terminating '0' is appended to the WString.
  200. @param buf Memory buffer to write the WString to.
  201. @param bufSize Size of the memory buffer in bytes.
  202. #end
  203. Method ToWString( buf:Void Ptr,bufSize:Int )="toWString"
  204. #rem monkeydoc Creates a string containing a single character.
  205. @param chr The character.
  206. #end
  207. Function FromChar:String( chr:Int )="bbString::fromChar"
  208. #rem monkeydoc Creates a string from a CString.
  209. If `bufSize` is specified, the CString may contain null characters which will be included in the string.
  210. If `bufsize` is not specified, the CString must be correctly null terminated or Bad Things Will Happen.
  211. @param buf The memory buffer containing the CString.
  212. @param bufSize The size of the memory buffer in bytes.
  213. #end
  214. Function FromCString:String( buf:Void Ptr,bufSize:Int )="bbString::fromCString"
  215. Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
  216. #rem monkeydoc Creates a string from a null terminated WString.
  217. If `bufSize` is specified, the WString may contain null characters which will be included in the string.
  218. If `bufsize` is not specified, the WString must be correctly null terminated or Bad Things Will Happen.
  219. @param buf The memory buffer containing the WString.
  220. @param bufSize The size of the memory buffer in bytes.
  221. #end
  222. Function FromWString:String( buf:Void Ptr,bufSize:Int )="bbString::fromWString"
  223. Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
  224. End
  225. #rem monkeydoc Primtive array type.
  226. This is a 'pseduo type' extended by all array types.
  227. #end
  228. Struct @Array<T>
  229. #rem monkeydoc The raw memory used by the array.
  230. #end
  231. Property Data:T Ptr()="data"
  232. #rem monkeydoc The length of the array.
  233. In the case of multi-dimensional arrays, the length of the array is the product of the sizes of all dimensions.
  234. #end
  235. Property Length:Int()="length"
  236. #rem monkeydoc Extracts a subarray from the array.
  237. 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.
  238. If either `from` or `tail` is negative, it represents an offset from the end of the array.
  239. @param `from` The starting index.
  240. @param `tail` The ending index.
  241. @return A subarray.
  242. #end
  243. Method Slice:T[]( from:Int )="slice"
  244. Method Slice:T[]( from:Int,term:Int )="slice"
  245. #rem monkeydoc Resizes an array.
  246. Returns a copy of the array resized to length `newLength`.
  247. Note that this method does not modify this array in any way.
  248. @param newLength The length of the new array.
  249. @return A new array.
  250. #end
  251. Method Resize:T[]( newLength:Int )="resize"
  252. #rem monkeydoc Gets the size of a single array dimension.
  253. Returns The size of the array in the given dimension.
  254. @param dimensions The dimension.
  255. @return The size of the array in the given dimension.
  256. #end
  257. Method GetSize:Int( dimension:Int )="size"
  258. #rem monkeydoc Copies a range of elements from this array to another.
  259. In debug mode, a runtime error will occur if the copy is outside the range of the array.
  260. @param dstArray destination of the copy.
  261. @param srcOffset First element to copy from this array.
  262. @param dstOffset First element to copy to in destination array.
  263. @param count Number of elements to copy.
  264. #end
  265. Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
  266. End
  267. #rem monkeydoc Base class of all objects.
  268. #end
  269. Class @Object="bbObject"
  270. #rem monkeydoc @hidden
  271. #end
  272. Method typeName:Void Ptr()="typeName"
  273. End
  274. #rem monkeydoc Base class of all throwable objects.
  275. #end
  276. Class @Throwable="bbThrowable"
  277. End
  278. #rem monkeydoc @hidden
  279. #end
  280. Function TypeName:String( type:CString )="bbTypeName"
  281. #rem monkeydoc String wrapper type for native 'char *' strings.
  282. This type should only be used when declaring parameters for extern functions.
  283. #end
  284. Struct CString="bbCString"
  285. End
  286. #rem monkeydoc String wrapper type for native 'wchar_t *' strings.
  287. This type should only be used when declaring parameters for extern functions.
  288. #end
  289. Struct WString="bbWString"
  290. End