types.monkey2 11 KB

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