types.monkey2 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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 char The character.
  206. #end
  207. Function FromChar:String( char:Int )="bbString::fromChar"
  208. #rem monkeydoc Creates a string containing characters in an array.
  209. @param chars The array.
  210. #end
  211. Function FromChars:String( chars:Int[] )="bbString::fromChars"
  212. #rem monkeydoc Creates a string from a CString.
  213. If `bufSize` is specified, the CString may contain null characters which will be included in the string.
  214. If `bufSize` is not specified, the CString must be correctly null terminated or Bad Things Will Happen.
  215. @param buf The memory buffer containing the CString.
  216. @param bufSize The size of the memory buffer in bytes.
  217. #end
  218. Function FromCString:String( buf:Void Ptr,bufSize:Int )="bbString::fromCString"
  219. Function FromCString:String( buf:Void Ptr )="bbString::fromCString"
  220. #rem monkeydoc Creates a string from a null terminated WString.
  221. If `bufSize` is specified, the WString may contain null characters which will be included in the string.
  222. If `bufSize` is not specified, the WString must be correctly null terminated or Bad Things Will Happen.
  223. @param buf The memory buffer containing the WString.
  224. @param bufSize The size of the memory buffer in bytes.
  225. #end
  226. Function FromWString:String( buf:Void Ptr,bufSize:Int )="bbString::fromWString"
  227. Function FromWString:String( buf:Void Ptr )="bbString::fromWString"
  228. End
  229. #rem monkeydoc String wrapper type for native 'char *' strings.
  230. This type should only be used when declaring parameters for extern functions.
  231. #end
  232. Struct @CString="bbCString"
  233. End
  234. #rem monkeydoc Variant type.
  235. The 'Variant' type is a primitive type that can be used to 'box' values of any type.
  236. An uninitialized variant will contain a 'null' value (of type Void) until you assign something to it.
  237. A variant is 'true' if it contains any value with a non-void type (including a bool false value!) and 'false' if it is uninitialized and has no (void) type.
  238. Any type of value can be implicitly converted to a variant.
  239. To retrieve the value contained in a variant, you must explicitly cast the variant to the desired type. Note that the cast must specify the exact type of the value already contained in the variant, or a runtime error will occur.
  240. The one exception to this is if the variant contains a class object, in which case you can cast the variant to any valid base class of the object.
  241. #end
  242. Struct @Variant="bbVariant"
  243. #rem monkeydoc Type of the variant value.
  244. #end
  245. Property Type:TypeInfo()="getType"
  246. End
  247. #rem monkeydoc Runtime type information.
  248. #End
  249. Class @TypeInfo Extends Void="bbTypeInfo"
  250. #rem monkeydoc Type name.
  251. #end
  252. Property Name:String()="getName"
  253. #rem monkeydoc Type kind.
  254. Will be one of: Unknown, Primitve, Pointer, Array, Function, Class, Namespace.
  255. #end
  256. Property Kind:String()="getKind"
  257. #rem monkeydoc Pointer pointee type.
  258. If the type is a pointer type, returns the type of what it's pointing at.
  259. If the type is not a pointer type a runtime exception occurs.
  260. #end
  261. Property PointeeType:TypeInfo()="pointeeType"
  262. #rem monkeydoc Array element type.
  263. If the type is an array type, returns the array element type.
  264. If the type is not an array type a runtime exception occurs.
  265. #end
  266. Property ElementType:TypeInfo()="elementType"
  267. #rem monkeydoc Array rank.
  268. If the type is an array type, returns rank of the array.
  269. If the type is not an array type a runtime exception occurs.
  270. #end
  271. Property ArrayRank:Int()="arrayRank"
  272. #rem monkeydoc Function return type.
  273. If the type is a function type, returns the return type of the functions.
  274. If the type is not a function type a runtime exception occurs.
  275. #end
  276. Property ReturnType:TypeInfo()="returnType"
  277. #rem monkeydoc Function parameter types.
  278. If the type is a function type, returns the types of the function parameters.
  279. If the type is not a function type a runtime exception occurs.
  280. #end
  281. Property ParamTypes:TypeInfo[]()="paramTypes"
  282. #rem monkeydoc Class super type.
  283. If the type is a class type, returns the type of the super class.
  284. If the type is not a class type a runtime exception occurs.
  285. #end
  286. Property SuperType:TypeInfo()="superType"
  287. #rem monkeydoc Implemented interfaces.
  288. The interfaces implemented by the class or interface type.
  289. If the type is not a class or interface type a runtime exception occurs.
  290. #end
  291. Property InterfaceTypes:TypeInfo[]()="interfaceTypes"
  292. #rem monkeydoc Gets string representation of type.
  293. #end
  294. Method To:String()="toString"
  295. #rem monkeydoc class or namespace member decls.
  296. If the type is a class or namespace type, returns the members of the type.
  297. If the type is not a class or namespace type a runtime exception occurs.
  298. #end
  299. Method GetDecls:DeclInfo[]()="getDecls"
  300. #rem monkeydoc Gets the unique member decl with the given name.
  301. If there are multiple members with the same name, null is returned.
  302. #end
  303. Method GetDecl:DeclInfo( name:String )="getDecl"
  304. #rem monkeydoc Gets the member decl with the given name and type.
  305. #end
  306. Method GetDecl:DeclInfo( name:String,type:TypeInfo )="getDecl"
  307. #rem monkeydoc Gets the member decls with the given name.
  308. #end
  309. Method GetDecls:DeclInfo[]( name:String )="getDecls"
  310. #rem monkeydoc Checks whether a class extends a class.
  311. #end
  312. Method ExtendsType:Bool( type:TypeInfo )="extendsType"
  313. #rem monkeydoc Gets a user defined type by name.
  314. Only user defined types are returned by this function.
  315. #end
  316. Function GetType:TypeInfo( name:String )="bbTypeInfo::getType"
  317. #rem monkeydoc Gets all user defined types.
  318. Only user defined types are returned by this function.
  319. #end
  320. Function GetTypes:TypeInfo[]()="bbTypeInfo::getTypes"
  321. End
  322. #rem monkeydoc Runtime declaration information.
  323. #end
  324. Class DeclInfo Extends Void="bbDeclInfo"
  325. #rem monkeydoc Declaration name.
  326. #end
  327. Property Name:String()="getName"
  328. #rem monkeydoc Declaration kind.
  329. This will be one of: Field, Global, Method, Function.
  330. #end
  331. Property Kind:String()="getKind"
  332. #rem monkeydoc Declaration type.
  333. #end
  334. Property Type:TypeInfo()="getType"
  335. #rem monkeydoc True if Get can be used with this declaration.
  336. #end
  337. Property Gettable:Bool()="gettable"
  338. #rem monkeydoc True if Set can be used with this declaration.
  339. #end
  340. Property Settable:Bool()="settable"
  341. #rem monkeydoc True if Invoke can be used with this declaration.
  342. #end
  343. Property Invokable:Bool()="invokable"
  344. #rem monkeydoc Gets string representation of decl.
  345. #end
  346. Method To:String()="toString"
  347. #rem monkeydoc Gets meta data keys.
  348. #end
  349. Method GetMetaKeys:String[]()="getMetaKeys"
  350. #rem monkeydoc Gets meta data value for a key.
  351. #end
  352. Method GetMetaValue:String( key:String )="getMetaValue"
  353. #rem monkeydoc Gets field, property or global value.
  354. If the declaration kind is 'Global', the `instance` parameter is ignored.
  355. A runtime error will occur if the declaration kind is not 'Field' or 'Global'.
  356. #end
  357. Method Get:Variant( instance:Variant )="get"
  358. #rem monkeydoc Sets field, property or global value.
  359. If the declaration kind is 'Global', the `instance` parameter is ignored.
  360. A runtime error will occur if the declaration kind is not 'Field' or 'Global'.
  361. #end
  362. Method Set( instance:Variant,value:Variant )="set"
  363. #rem monkeydoc Invokes method or function.
  364. If the declaration kind is 'Function', the `instance` parameter is ignored.
  365. A runtime error will occur if the declaration kind is not 'Method' or 'Function'.
  366. #end
  367. Method Invoke:Variant( instance:Variant,params:Variant[] )="invoke"
  368. End
  369. #rem monkeydoc Primtive array type.
  370. This is a 'pseduo type' extended by all array types.
  371. #end
  372. Struct @Array<T>
  373. #rem monkeydoc The raw memory used by the array.
  374. #end
  375. Property Data:T Ptr()="data"
  376. #rem monkeydoc The length of the array.
  377. In the case of multi-dimensional arrays, the length of the array is the product of the sizes of all dimensions.
  378. #end
  379. Property Length:Int()="length"
  380. #rem monkeydoc Extracts a subarray from the array.
  381. 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.
  382. If either `from` or `tail` is negative, it represents an offset from the end of the array.
  383. @param `from` The starting index.
  384. @param `tail` The ending index.
  385. @return A subarray.
  386. #end
  387. Method Slice:T[]( from:Int )="slice"
  388. Method Slice:T[]( from:Int,term:Int )="slice"
  389. #rem monkeydoc Resizes an array.
  390. Returns a copy of the array resized to length `newLength`.
  391. Note that this method does not modify this array in any way.
  392. @param newLength The length of the new array.
  393. @return A new array.
  394. #end
  395. Method Resize:T[]( newLength:Int )="resize"
  396. #rem monkeydoc Gets the size of a single array dimension.
  397. Returns The size of the array in the given dimension.
  398. @param dimensions The dimension.
  399. @return The size of the array in the given dimension.
  400. #end
  401. Method GetSize:Int( dimension:Int )="size"
  402. #rem monkeydoc Copies a range of elements from this array to another.
  403. In debug mode, a runtime error will occur if the copy is outside the range of the array.
  404. @param dstArray destination of the copy.
  405. @param srcOffset First element to copy from this array.
  406. @param dstOffset First element to copy to in destination array.
  407. @param count Number of elements to copy.
  408. #end
  409. Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
  410. End
  411. #rem monkeydoc Base class of all objects.
  412. #end
  413. Class @Object="bbObject"
  414. #rem monkeydoc The runtime typ eof the object
  415. #end
  416. Property InstanceType:TypeInfo()="typeof"
  417. #rem monkeydoc @hidden
  418. #end
  419. Method typeName:Void Ptr()="typeName"
  420. End
  421. #rem monkeydoc Base class of all throwable objects.
  422. #end
  423. Class @Throwable="bbThrowable"
  424. End