types.monkey2 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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 Static Type of the variant value.
  244. #end
  245. Property Type:TypeInfo()="getType"
  246. #rem monkeydoc Dynamic type of the variant value.
  247. #end
  248. Property DynamicType:TypeInfo()="getDynamicType"
  249. #rem monkeydoc Gets the integer enum value of an enum variant.
  250. The type of the variant must be an enum type, or a runtime error will occur.
  251. #end
  252. Property EnumValue:Int()="enumValue"
  253. #rem monkeydoc Gets the length of an array.
  254. The type of the variant must be an array type, or a runtime error will occur.
  255. #end
  256. Method GetArrayLength:Int()="getArrayLength"
  257. #rem monkeydoc Gets an element from an array.
  258. The type of the variant must be an array type, or a runtime error will occur.
  259. #end
  260. Method GetArrayElement:Variant( index:Int )="getArrayElement"
  261. #rem monkeydoc Sets an element of an array.
  262. The type of the variant must be an array type, or a runtime error will occur.
  263. #end
  264. Method SetArrayElement( index:Int,value:Variant )="setArrayElement"
  265. End
  266. #rem monkeydoc Primtive array type.
  267. This is a 'pseduo type' extended by all array types.
  268. #end
  269. Struct @Array<T>
  270. #rem monkeydoc The raw memory used by the array.
  271. #end
  272. Property Data:T Ptr()="data"
  273. #rem monkeydoc The length of the array.
  274. In the case of multi-dimensional arrays, the length of the array is the product of the sizes of all dimensions.
  275. #end
  276. Property Length:Int()="length"
  277. #rem monkeydoc Extracts a subarray from the array.
  278. 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.
  279. If either `from` or `tail` is negative, it represents an offset from the end of the array.
  280. @param `from` The starting index.
  281. @param `tail` The ending index.
  282. @return A subarray.
  283. #end
  284. Method Slice:T[]( from:Int )="slice"
  285. Method Slice:T[]( from:Int,term:Int )="slice"
  286. #rem monkeydoc Resizes an array.
  287. Returns a copy of the array resized to length `newLength`.
  288. Note that this method does not modify this array in any way.
  289. @param newLength The length of the new array.
  290. @return A new array.
  291. #end
  292. Method Resize:T[]( newLength:Int )="resize"
  293. #rem monkeydoc Gets the size of a single array dimension.
  294. Returns The size of the array in the given dimension.
  295. @param dimensions The dimension.
  296. @return The size of the array in the given dimension.
  297. #end
  298. Method GetSize:Int( dimension:Int )="size"
  299. #rem monkeydoc Copies a range of elements from this array to another.
  300. In debug mode, a runtime error will occur if the copy is outside the range of the array.
  301. @param dstArray destination of the copy.
  302. @param srcOffset First element to copy from this array.
  303. @param dstOffset First element to copy to in destination array.
  304. @param count Number of elements to copy.
  305. #end
  306. Method CopyTo( dstArray:T[],srcOffset:Int,dstOffset:Int,count:Int )="copyTo"
  307. End
  308. #rem monkeydoc Base class of all objects.
  309. #end
  310. Class @Object="bbObject"
  311. #rem monkeydoc The dynamic type of the object.
  312. #end
  313. Property DynamicType:TypeInfo()="typeof"
  314. #rem monkeydoc @deprecated use [[DynamicType]].
  315. #end
  316. Property InstanceType:TypeInfo()="typeof"
  317. '#rem monkeydoc Finalize method.
  318. '#end
  319. 'Method Finalize() Virtual="gcFinalize"
  320. #rem monkeydoc @hidden
  321. #end
  322. Method typeName:Void Ptr()="typeName"
  323. End
  324. #rem monkeydoc Base class of all throwable objects.
  325. #end
  326. Class @Throwable="bbThrowable"
  327. End
  328. '***** Reflecftion types *****
  329. #rem monkeydoc Runtime type information.
  330. #End
  331. Class @TypeInfo Extends Void="bbTypeInfo"
  332. #rem monkeydoc Type name.
  333. #end
  334. Property Name:String()="getName"
  335. #rem monkeydoc Type kind.
  336. Will be one of: Unknown, Primitive, Pointer, Array, Function, Class, Interface, Struct, Namespace.
  337. #end
  338. Property Kind:String()="getKind"
  339. #rem monkeydoc A variant containing a null value of this type.
  340. #end
  341. Property NullValue:Variant()="nullValue"
  342. #rem monkeydoc Pointer pointee type.
  343. If the type is a pointer type, returns the type of what it's pointing at.
  344. If the type is not a pointer type a runtime exception occurs.
  345. #end
  346. Property PointeeType:TypeInfo()="pointeeType"
  347. #rem monkeydoc Array element type.
  348. If the type is an array type, returns the array element type.
  349. If the type is not an array type a runtime exception occurs.
  350. #end
  351. Property ElementType:TypeInfo()="elementType"
  352. #rem monkeydoc Array rank.
  353. If the type is an array type, returns rank of the array.
  354. If the type is not an array type a runtime exception occurs.
  355. #end
  356. Property ArrayRank:Int()="arrayRank"
  357. #rem monkeydoc Function return type.
  358. If the type is a function type, returns the return type of the functions.
  359. If the type is not a function type a runtime exception occurs.
  360. #end
  361. Property ReturnType:TypeInfo()="returnType"
  362. #rem monkeydoc Function parameter types.
  363. If the type is a function type, returns the types of the function parameters.
  364. If the type is not a function type a runtime exception occurs.
  365. #end
  366. Property ParamTypes:TypeInfo[]()="paramTypes"
  367. #rem monkeydoc Class super type.
  368. If the type is a class type, returns the type of the super class.
  369. If the type is not a class type a runtime exception occurs.
  370. #end
  371. Property SuperType:TypeInfo()="superType"
  372. #rem monkeydoc Implemented interfaces.
  373. The interfaces implemented by the class or interface type.
  374. If the type is not a class or interface type a runtime exception occurs.
  375. #end
  376. Property InterfaceTypes:TypeInfo[]()="interfaceTypes"
  377. #rem monkeydoc Gets string representation of type.
  378. #end
  379. Method To:String()="toString"
  380. #rem monkeydoc class or namespace member decls.
  381. If the type is a class or namespace type, returns the members of the type.
  382. If the type is not a class or namespace type a runtime exception occurs.
  383. #end
  384. Method GetDecls:DeclInfo[]()="getDecls"
  385. #rem monkeydoc Gets the unique member decl with the given name.
  386. If there are multiple members with the same name, null is returned.
  387. #end
  388. Method GetDecl:DeclInfo( name:String )="getDecl"
  389. #rem monkeydoc Gets the member decl with the given name and type.
  390. #end
  391. Method GetDecl:DeclInfo( name:String,type:TypeInfo )="getDecl"
  392. #rem monkeydoc Gets the member decls with the given name.
  393. #end
  394. Method GetDecls:DeclInfo[]( name:String )="getDecls"
  395. #rem monkeydoc Checks whether a class extends a class.
  396. #end
  397. Method ExtendsType:Bool( type:TypeInfo )="extendsType"
  398. #rem monkeydoc Creates an enum variant from an arbitrary int value.
  399. This type must represent an enum type.
  400. #end
  401. Method MakeEnum:Variant( enumValue:Int )="makeEnum"
  402. #rem monkeydoc Creates a new array of this type.
  403. #end
  404. Method NewArray:Variant( length:Int )="newArray"
  405. #rem monkeydoc Gets a user defined type by name.
  406. Only user defined types are returned by this function.
  407. #end
  408. Function GetType:TypeInfo( name:String )="bbTypeInfo::getType"
  409. #rem monkeydoc Gets all user defined types.
  410. Only user defined types are returned by this function.
  411. #end
  412. Function GetTypes:TypeInfo[]()="bbTypeInfo::getTypes"
  413. End
  414. #rem monkeydoc Runtime declaration information.
  415. #end
  416. Class DeclInfo Extends Void="bbDeclInfo"
  417. #rem monkeydoc Declaration name.
  418. #end
  419. Property Name:String()="getName"
  420. #rem monkeydoc Declaration kind.
  421. This will be one of: Const, Field, Global, Property, Method, Function, Constructor.
  422. #end
  423. Property Kind:String()="getKind"
  424. #rem monkeydoc Declaration type.
  425. #end
  426. Property Type:TypeInfo()="getType"
  427. #rem monkeydoc True if Get can be used with this declaration.
  428. #end
  429. Property Gettable:Bool()="gettable"
  430. #rem monkeydoc True if Set can be used with this declaration.
  431. #end
  432. Property Settable:Bool()="settable"
  433. #rem monkeydoc True if Invoke can be used with this declaration.
  434. #end
  435. Property Invokable:Bool()="invokable"
  436. #rem monkeydoc Gets string representation of decl.
  437. #end
  438. Method To:String()="toString"
  439. #rem monkeydoc Gets meta data keys.
  440. #end
  441. Method GetMetaKeys:String[]()="getMetaKeys"
  442. #rem monkeydoc Gets meta data value for a key.
  443. #end
  444. Method GetMetaValue:String( key:String )="getMetaValue"
  445. #rem monkeydoc Gets field, property or global value.
  446. If the declaration kind is 'Global', the `instance` parameter is ignored.
  447. A runtime error will occur if the declaration kind is not 'Field' or 'Global'.
  448. #end
  449. Method Get:Variant( instance:Variant )="get"
  450. #rem monkeydoc Sets field, property or global value.
  451. If the declaration kind is 'Global', the `instance` parameter is ignored.
  452. A runtime error will occur if the declaration kind is not 'Field' or 'Global'.
  453. #end
  454. Method Set( instance:Variant,value:Variant )="set"
  455. #rem monkeydoc Invokes method or function.
  456. If the declaration kind is 'Function', the `instance` parameter is ignored.
  457. A runtime error will occur if the declaration kind is not 'Method' or 'Function'.
  458. #end
  459. Method Invoke:Variant( instance:Variant,params:Variant[] )="invoke"
  460. End