types.monkey2 18 KB

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