types.monkey2 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 Replace all occurances of a substring with another string.
  123. @param find The string to search for.
  124. @param replace The string to replace with.
  125. @return The string with `find` replaced with `replace`.
  126. #end
  127. Method Replace:String( find:String,replace:String )="replace"
  128. Method Split:String[]( separator:String )="split"
  129. Method Join:String( bits:String[] )="join"
  130. #rem monkeydoc Converts the string to a CString.
  131. If there is enough room in the memory buffer, a null terminating '0' is appended to the CString.
  132. @param buf Memory buffer to write the CString to.
  133. @param bufSize Size of the memory buffer in bytes.
  134. #end
  135. Method ToCString( buf:Void Ptr,bufSize:Int )="toCString"
  136. #rem monkeydoc Converts the string to a WString
  137. If there is enough room in the memory buffer, a null terminating '0' is appended to the WString.
  138. @param buf Memory buffer to write the WString to.
  139. @param bufSize Size of the memory buffer in bytes.
  140. #end
  141. Method ToWString( buf:Void Ptr,bufSize:Int )="toWString"
  142. #rem monkeydoc Converts the string to a Utf8String
  143. If there is enough room in the memory buffer, a null terminating '0' is appended to the Utf8String.
  144. @param buf Memory buffer to write the Utf8String to.
  145. @param bufSize Size of the memory buffer in bytes.
  146. #end
  147. Method ToUtf8String( buf:Void Ptr,bufSize:Int )="toUtf8String"
  148. #rem monkeydoc Creates a string containing a single character.
  149. @param chr The character.
  150. #end
  151. Function FromChar:String( chr:Int )="bbString::fromChar"
  152. #rem monkeydoc Creates a string from a null terminated CString.
  153. Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
  154. @param buf The memory buffer containing the CString.
  155. @param bufSize The size of the memory buffer in bytes.
  156. #end
  157. Function FromCString:String( buf:Void Ptr,bufSize:Int )="bbString::fromCString"
  158. #rem monkeydoc Creates a string from a null terminated WString.
  159. Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
  160. @param buf The memory buffer containing the WString.
  161. @param bufSize The size of the memory buffer in bytes.
  162. #end
  163. Function FromWString:String( buf:Void Ptr,bufSize:Int )="bbString::fromWString"
  164. #rem monkeydoc Creates a string from a null terminated Utf8String.
  165. Note: Only `bufSize` bytes at most will be used to create the string, so this method is safe to call even if the string is not null terminated.
  166. @param buf The memory buffer containing the Utf8String.
  167. @param bufSize The size of the memory buffer in bytes.
  168. #end
  169. Function FromUtf8String:String( buf:Void Ptr,bufSize:Int )="bbString::fromUtf8String"
  170. #rem monkeydoc Creates a string from a null terminated CString.
  171. Note: The CString must be correctly null terminated, or Bad Things Will Happen.
  172. @param buf The memory buffer containing the CString.
  173. #end
  174. Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
  175. #rem monkeydoc Creates a string from a null terminated WString.
  176. Note: The WString must be correctly null terminated, or Bad Things Will Happen.
  177. @param buf The memory buffer containing the WString.
  178. #end
  179. Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
  180. #rem monkeydoc Creates a string from a null terminated Utf8String.
  181. Note: The Utf8String must be correctly null terminated, or Bad Things Will Happen.
  182. @param buf The memory buffer containing the Utf8String.
  183. #end
  184. Function FromUtf8String:String( buf:Void Ptr )="bbString::fromUtf8String"
  185. End
  186. #rem monkeydoc Primtive array type.
  187. This is a 'pseduo type' extended by all array types.
  188. #end
  189. Struct @Array<T>
  190. #rem monkeydoc The raw memory used by the array.
  191. #end
  192. Property Data:T Ptr()="data"
  193. #rem monkeydoc The length of the array.
  194. In the case of multi-dimensional arrays, the length of the array is the product of the sizes of all dimensions.
  195. #end
  196. Property Length:Int()="length"
  197. #rem monkeydoc Extracts a subarray from the array.
  198. Returns an array consisting of all elements from `from` until (but not including) `tail`, or until the end of the string
  199. if `tail` is not specified.
  200. If either `from` or `tail` is negative, it represents an offset from the end of the array.
  201. @param `from` The starting index.
  202. @param `tail` The ending index.
  203. @return A subarray.
  204. #end
  205. Method Slice:T[]( from:Int )="slice"
  206. Method Slice:T[]( from:Int,term:Int )="slice"
  207. #rem monkeydoc Gets the size of a single array dimension.
  208. @param dimensions The dimension.
  209. @return The size of array in the given dimension.
  210. #end
  211. Method GetSize:Int( dimension:Int )="size"
  212. Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
  213. End
  214. #rem monkeydoc Base class of all objects.
  215. #end
  216. Class @Object="bbObject"
  217. #rem monkeydoc @hidden
  218. #end
  219. Method typeName:Void Ptr()="typeName"
  220. End
  221. #rem monkeydoc Base class of all throwable objects.
  222. #end
  223. Class @Throwable="bbThrowable"
  224. End
  225. #rem
  226. #rem monkeydoc Base class of all exception objects.
  227. #end
  228. Class @Exception Extends Throwable="bbException"
  229. Method New()
  230. Method New( message:String )
  231. Property Message:String()="message"
  232. Property DebugStack:String[]()="debugStack"
  233. End
  234. #end
  235. #rem monkeydoc @hidden
  236. #end
  237. Function TypeName:String( type:CString )="bbTypeName"
  238. #rem monkeydoc String wrapper type for native 'char *' strings.
  239. This type should only be used when declaring parameters for extern functions.
  240. #end
  241. Struct CString="bbCString"
  242. End
  243. #rem monkeydoc String wrapper type for native 'wchar_t *' strings.
  244. This type should only be used when declaring parameters for extern functions.
  245. #end
  246. Struct WString="bbWString"
  247. End
  248. #rem monkeydoc String wrapper type for native utf8 'unsigned char*' strings.
  249. This type should only be used when declaring parameters for extern functions.
  250. #end
  251. Struct Utf8String="bbUtf8String"
  252. End