types.monkey2 20 KB

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