You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

684 lines
38KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. #if JUCE_SUPPORT_SCRIPTING
  21. #if JUCE_WIN32
  22. #undef T
  23. #undef GetObject
  24. #endif
  25. namespace angelscriptNamespace
  26. {
  27. #if JUCETICE_INCLUDE_ANGELSCRIPT_CODE
  28. #include "../../dependancies/angelscript/include/angelscript.h"
  29. #else
  30. #include <angelscript.h>
  31. #endif
  32. }
  33. #if JUCE_WIN32
  34. #define T(stringLiteral) JUCE_T(stringLiteral)
  35. #ifdef UNICODE
  36. #define GetObject GetObjectW
  37. #else
  38. #define GetObject GetObjectA
  39. #endif // !UNICODE
  40. #endif
  41. BEGIN_JUCE_NAMESPACE
  42. #include "../jucetice_ScriptableEngine.h"
  43. using namespace angelscriptNamespace;
  44. namespace Bindings {
  45. //==============================================================================
  46. asString::asString () {
  47. refCount = 1;
  48. }
  49. asString::asString (const char s) {
  50. refCount = 1;
  51. buffer << s;
  52. }
  53. asString::asString (const char *s) {
  54. refCount = 1;
  55. buffer = s;
  56. }
  57. asString::asString (const tchar s) {
  58. refCount = 1;
  59. buffer << s;
  60. }
  61. asString::asString (const tchar *s) {
  62. refCount = 1;
  63. buffer = s;
  64. }
  65. asString::asString (const String &s) {
  66. refCount = 1;
  67. buffer = s;
  68. }
  69. asString::asString (const asString &s) {
  70. refCount = 1;
  71. buffer = s.buffer;
  72. }
  73. asString::~asString() {
  74. jassert (refCount == 0);
  75. }
  76. //==============================================================================
  77. void asString::addRef()
  78. {
  79. refCount++;
  80. }
  81. void asString::release()
  82. {
  83. if( --refCount == 0 )
  84. delete this;
  85. }
  86. //==============================================================================
  87. bool asString::equalsIgnoreCase(const asString &str) {
  88. return buffer.equalsIgnoreCase(str.buffer);
  89. }
  90. int asString::compare (const asString& other) {
  91. return buffer.compare(other.buffer);
  92. }
  93. int asString::compareIgnoreCase (const asString& other) {
  94. return buffer.compareIgnoreCase(other.buffer);
  95. }
  96. int asString::compareLexicographically (const asString& other) {
  97. return buffer.compareLexicographically(other.buffer);
  98. }
  99. bool asString::startsWith (const asString& text) {
  100. return buffer.startsWith(text.buffer);
  101. }
  102. bool asString::startsWithIgnoreCase (const asString& text) {
  103. return buffer.startsWithIgnoreCase(text.buffer);
  104. }
  105. bool asString::endsWith (const asString& text) {
  106. return buffer.endsWith(text.buffer);
  107. }
  108. bool asString::endsWithIgnoreCase (const asString& text) {
  109. return buffer.endsWithIgnoreCase(text.buffer);
  110. }
  111. bool asString::contains (const asString& text) {
  112. return buffer.contains(text.buffer);
  113. }
  114. bool asString::containsIgnoreCase (const asString& text) {
  115. return buffer.containsIgnoreCase(text.buffer);
  116. }
  117. bool asString::containsWholeWord (const asString& wordToLookFor) {
  118. return buffer.containsWholeWord(wordToLookFor.buffer);
  119. }
  120. bool asString::containsWholeWordIgnoreCase (const asString& wordToLookFor) {
  121. return buffer.containsWholeWordIgnoreCase(wordToLookFor.buffer);
  122. }
  123. bool asString::containsAnyOf (const asString& charactersItMightContain) {
  124. return buffer.containsAnyOf(charactersItMightContain.buffer);
  125. }
  126. bool asString::containsOnly (const asString& charactersItMightContain) {
  127. return buffer.containsOnly(charactersItMightContain.buffer);
  128. }
  129. bool asString::matchesWildcard (const asString& wildcard, const bool ignoreCase) {
  130. return buffer.matchesWildcard(wildcard.buffer,ignoreCase);
  131. }
  132. int asString::indexOf (const asString& other) {
  133. return buffer.indexOf (other.buffer);
  134. }
  135. int asString::indexOf (const int startIndex, const asString& textToLookFor) {
  136. return buffer.indexOf (startIndex, textToLookFor.buffer);
  137. }
  138. int asString::indexOfIgnoreCase (const asString& textToLookFor) {
  139. return buffer.indexOfIgnoreCase (textToLookFor.buffer);
  140. }
  141. int asString::indexOfIgnoreCase (const int startIndex, const asString& textToLookFor) {
  142. return buffer.indexOfIgnoreCase (startIndex, textToLookFor.buffer);
  143. }
  144. int asString::lastIndexOf (const asString& textToLookFor) {
  145. return buffer.lastIndexOf (textToLookFor.buffer);
  146. }
  147. int asString::lastIndexOfIgnoreCase (const asString& textToLookFor) {
  148. return buffer.lastIndexOfIgnoreCase (textToLookFor.buffer);
  149. }
  150. asString* asString::substring (int startIndex, int endIndex) {
  151. return new asString(buffer.substring(startIndex,endIndex));
  152. }
  153. asString* asString::substring (const int startIndex) {
  154. return new asString(buffer.substring(startIndex));
  155. }
  156. asString* asString::dropLastCharacters (const int numberToDrop) {
  157. return new asString(buffer.dropLastCharacters(numberToDrop));
  158. }
  159. asString* asString::fromFirstOccurrenceOf (const asString& substringToStartFrom,
  160. const bool includeSubStringInResult,
  161. const bool ignoreCase) {
  162. return new asString(buffer.fromFirstOccurrenceOf(substringToStartFrom.buffer,includeSubStringInResult,ignoreCase));
  163. }
  164. asString* asString::fromLastOccurrenceOf (const asString& substringToFind,
  165. const bool includeSubStringInResult,
  166. const bool ignoreCase) {
  167. return new asString(buffer.fromLastOccurrenceOf(substringToFind.buffer,includeSubStringInResult,ignoreCase));
  168. }
  169. asString* asString::upToFirstOccurrenceOf (const asString& substringToEndWith,
  170. const bool includeSubStringInResult,
  171. const bool ignoreCase) {
  172. return new asString(buffer.upToFirstOccurrenceOf(substringToEndWith.buffer,includeSubStringInResult,ignoreCase));
  173. }
  174. asString* asString::upToLastOccurrenceOf (const asString& substringToFind,
  175. const bool includeSubStringInResult,
  176. const bool ignoreCase) {
  177. return new asString(buffer.upToLastOccurrenceOf(substringToFind.buffer,includeSubStringInResult,ignoreCase));
  178. }
  179. asString* asString::trim() {
  180. return new asString(buffer.trim());
  181. }
  182. asString* asString::trimStart() {
  183. return new asString(buffer.trimStart());
  184. }
  185. asString* asString::trimEnd() {
  186. return new asString(buffer.trimEnd());
  187. }
  188. asString* asString::toUpperCase() {
  189. return new asString(buffer.toUpperCase());
  190. }
  191. asString* asString::toLowerCase() {
  192. return new asString(buffer.toLowerCase());
  193. }
  194. asString* asString::replaceSection (int startIndex, int numCharactersToReplace, const asString& stringToInsert){
  195. return new asString(buffer.replaceSection(startIndex,numCharactersToReplace,stringToInsert.buffer));
  196. }
  197. asString* asString::replace (const asString& stringToReplace,const asString& stringToInsertInstead,const bool ignoreCase){
  198. return new asString(buffer.replace(stringToReplace.buffer,stringToInsertInstead.buffer,ignoreCase));
  199. }
  200. asString* asString::replaceCharacter (const asString& characterToReplace, const asString& characterToInsertInstead) {
  201. return new asString(buffer.replaceCharacter(characterToReplace.buffer[0],characterToInsertInstead.buffer[0]));
  202. }
  203. asString* asString::replaceCharacters (const asString& charactersToReplace, const asString& charactersToInsertInstead){
  204. return new asString(buffer.replaceCharacters(charactersToReplace.buffer,charactersToInsertInstead.buffer));
  205. }
  206. asString* asString::retainCharacters (const asString& charactersToRetain) {
  207. return new asString(buffer.retainCharacters(charactersToRetain.buffer));
  208. }
  209. asString* asString::removeCharacters (const asString& charactersToRemove) {
  210. return new asString(buffer.removeCharacters(charactersToRemove.buffer));
  211. }
  212. asString* asString::initialSectionContainingOnly (const asString& charactersToRetain) {
  213. return new asString(buffer.initialSectionContainingOnly(charactersToRetain.buffer));
  214. }
  215. asString* asString::initialSectionNotContaining (const asString& charactersNotToRetain) {
  216. return new asString(buffer.initialSectionNotContaining(charactersNotToRetain.buffer));
  217. }
  218. asString* asString::unquoted () {
  219. return new asString(buffer.unquoted());
  220. }
  221. asString* asString::quoted (const asString& quoteCharacter) {
  222. return new asString(buffer.quoted(quoteCharacter.buffer[0]));
  223. }
  224. //==============================================================================
  225. bool operator== (const asString &a, const asString &b) { return a.buffer == b.buffer; }
  226. bool operator!= (const asString &a, const asString &b) { return a.buffer != b.buffer; }
  227. bool operator<= (const asString &a, const asString &b) { return a.buffer <= b.buffer; }
  228. bool operator>= (const asString &a, const asString &b) { return a.buffer >= b.buffer; }
  229. bool operator< (const asString &a, const asString &b) { return a.buffer < b.buffer; }
  230. bool operator> (const asString &a, const asString &b) { return a.buffer > b.buffer; }
  231. bool operator== (const asString &a, const float b) { return a.buffer.getFloatValue() == b; }
  232. bool operator!= (const asString &a, const float b) { return a.buffer.getFloatValue() != b; }
  233. bool operator<= (const asString &a, const float b) { return a.buffer.getFloatValue() <= b; }
  234. bool operator>= (const asString &a, const float b) { return a.buffer.getFloatValue() >= b; }
  235. bool operator< (const asString &a, const float b) { return a.buffer.getFloatValue() < b; }
  236. bool operator> (const asString &a, const float b) { return a.buffer.getFloatValue() > b; }
  237. bool operator== (const asString &a, const int b) { return a.buffer.getIntValue() == b; }
  238. bool operator!= (const asString &a, const int b) { return a.buffer.getIntValue() != b; }
  239. bool operator<= (const asString &a, const int b) { return a.buffer.getIntValue() <= b; }
  240. bool operator>= (const asString &a, const int b) { return a.buffer.getIntValue() >= b; }
  241. bool operator< (const asString &a, const int b) { return a.buffer.getIntValue() < b; }
  242. bool operator> (const asString &a, const int b) { return a.buffer.getIntValue() > b; }
  243. //==============================================================================
  244. asString &asString::operator= (const asString &other) {
  245. buffer = other.buffer;
  246. return *this;
  247. }
  248. asString &asString::operator+= (const asString &other) {
  249. buffer += other.buffer;
  250. return *this;
  251. }
  252. asString *operator+ (const asString &a, const asString &b) {
  253. return new asString (a.buffer + b.buffer);
  254. }
  255. //==============================================================================
  256. asString* StringShiftLeftBool (asString* dest, bool b) {
  257. dest->buffer << ((b==true)?1:0);
  258. return dest;
  259. }
  260. asString* StringShiftLeftInt (asString* dest, int i) {
  261. dest->buffer << i;
  262. return dest;
  263. }
  264. asString* StringShiftLeftUInt (asString* dest, unsigned int ui) {
  265. dest->buffer << (int)ui;
  266. return dest;
  267. }
  268. asString* StringShiftLeftFloat (asString* dest, float f) {
  269. dest->buffer << f;
  270. return dest;
  271. }
  272. asString* StringShiftLeftDouble (asString* dest, double d) {
  273. dest->buffer << d;
  274. return dest;
  275. }
  276. asString* StringShiftLeftString (asString* dest, asString& other) {
  277. dest->buffer << other.buffer;
  278. return dest;
  279. }
  280. //==============================================================================
  281. static asString &AssignBoolToString (bool b, asString &dest)
  282. {
  283. String stream;
  284. stream << ((b==true)?1:0);
  285. dest.buffer = stream;
  286. return dest;
  287. }
  288. static asString &AssignUIntToString (unsigned int i, asString &dest)
  289. {
  290. String stream;
  291. stream.printf("%u", i);
  292. dest.buffer = stream;
  293. return dest;
  294. }
  295. static asString &AssignIntToString (int i, asString &dest)
  296. {
  297. String stream;
  298. stream << i;
  299. dest.buffer = stream;
  300. return dest;
  301. }
  302. static asString &AssignFloatToString (float f, asString &dest)
  303. {
  304. String stream;
  305. stream << f;
  306. dest.buffer = stream;
  307. return dest;
  308. }
  309. static asString &AssignDoubleToString (double f, asString &dest)
  310. {
  311. String stream;
  312. stream << f;
  313. dest.buffer = stream;
  314. return dest;
  315. }
  316. //==============================================================================
  317. static asString &AddAssignBoolToString (bool b, asString &dest)
  318. {
  319. String stream;
  320. stream << ((b==true)?1:0);
  321. dest.buffer += stream;
  322. return dest;
  323. }
  324. static asString &AddAssignUIntToString (unsigned int i, asString &dest)
  325. {
  326. String stream;
  327. stream.printf("%u", i);
  328. dest.buffer += stream;
  329. return dest;
  330. }
  331. static asString &AddAssignIntToString (int i, asString &dest)
  332. {
  333. String stream;
  334. stream << i;
  335. dest.buffer += stream;
  336. return dest;
  337. }
  338. static asString &AddAssignFloatToString (float f, asString &dest)
  339. {
  340. String stream;
  341. stream << f;
  342. dest.buffer += stream;
  343. return dest;
  344. }
  345. static asString &AddAssignDoubleToString (double f, asString &dest)
  346. {
  347. String stream;
  348. stream << f;
  349. dest.buffer += stream;
  350. return dest;
  351. }
  352. //==============================================================================
  353. static asString *AddStringBool (const asString &str,bool b)
  354. {
  355. String stream;
  356. stream << (const char*)str.buffer << ((b==true)?1:0);
  357. return new asString(stream);
  358. }
  359. static asString *AddStringUInt (const asString &str, unsigned int i)
  360. {
  361. String stream;
  362. stream.printf("%u", i );
  363. return new asString(str.buffer + stream);
  364. }
  365. static asString *AddStringInt (const asString &str, int i)
  366. {
  367. String stream;
  368. stream << (const char*) str.buffer << i;
  369. return new asString(stream);
  370. }
  371. static asString *AddStringFloat (const asString &str, float f)
  372. {
  373. String stream;
  374. stream << (const char*) str.buffer << f;
  375. return new asString(stream);
  376. }
  377. static asString *AddStringDouble (const asString &str, double f)
  378. {
  379. String stream;
  380. stream << (const char*) str.buffer << f;
  381. return new asString(stream);
  382. }
  383. //==============================================================================
  384. static asString *AddBoolString (bool b, const asString &str)
  385. {
  386. String stream;
  387. stream << ((b==true)?1:0) << (const char*)str.buffer;
  388. return new asString(stream);
  389. }
  390. static asString *AddUIntString (unsigned int i, const asString &str)
  391. {
  392. String stream;
  393. stream.printf("%u", i );
  394. return new asString(stream + str.buffer);
  395. }
  396. static asString *AddIntString (int i, const asString &str)
  397. {
  398. String stream;
  399. stream << i << (const char*)str.buffer;
  400. return new asString(stream);
  401. }
  402. static asString *AddFloatString (float f, const asString &str)
  403. {
  404. String stream;
  405. stream << f << (const char*)str.buffer;
  406. return new asString(stream);
  407. }
  408. static asString *AddDoubleString (double f, const asString &str)
  409. {
  410. String stream;
  411. stream << f << (const char*)str.buffer;
  412. return new asString(stream);
  413. }
  414. //==============================================================================
  415. static asString* StringCharAt (asUINT i, const asString &str)
  416. {
  417. if( i >= (unsigned int) str.buffer.length() )
  418. {
  419. asIScriptContext *ctx = asGetActiveContext();
  420. ctx->SetException("Out of range");
  421. return 0;
  422. }
  423. return new asString (str.buffer.substring(i, i + 1));
  424. }
  425. //==============================================================================
  426. // This is the string factory that creates new strings for the script
  427. static asString* StringFactory (asUINT length, const char* text)
  428. {
  429. return new asString (text);
  430. }
  431. static asString *StringDefaultFactory()
  432. {
  433. return new asString();
  434. }
  435. static asString* StringBoolFactory (bool b)
  436. {
  437. String text;
  438. text << (b ? 1 : 0);
  439. return new asString (text);
  440. }
  441. static asString* StringUintFactory (unsigned int i)
  442. {
  443. String text;
  444. text.printf ("%u", i);
  445. return new asString (text);
  446. }
  447. static asString* StringIntFactory (int i)
  448. {
  449. String text;
  450. text << i;
  451. return new asString (text);
  452. }
  453. static asString* StringFloatFactory (float f)
  454. {
  455. String text;
  456. text << f;
  457. return new asString (text);
  458. }
  459. static asString* StringDoubleFactory (double d)
  460. {
  461. String text;
  462. text << d;
  463. return new asString (text);
  464. }
  465. static asString *StringCopyFactory (const asString &other)
  466. {
  467. // Allocate and initialize with the copy constructor
  468. return new asString (other.buffer);
  469. }
  470. //==============================================================================
  471. // This is where we register the string type
  472. void RegisterObjectTypeString (ScriptableEngine* scriptEngine)
  473. {
  474. int r;
  475. asIScriptEngine* engine = (asIScriptEngine*) scriptEngine->getCurrentEngine ();
  476. // Register the type
  477. r = engine->RegisterObjectType ("String", sizeof(asString), asOBJ_REF); jassert( r >= 0 );
  478. // Register the object operator overloads
  479. // Note: We don't have to register the destructor, since the object uses reference counting
  480. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f()", asFUNCTION(StringDefaultFactory), asCALL_CDECL); jassert( r >= 0 );
  481. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const bool)", asFUNCTION(StringBoolFactory), asCALL_CDECL); jassert( r >= 0 );
  482. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const uint)", asFUNCTION(StringUintFactory), asCALL_CDECL); jassert( r >= 0 );
  483. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const int)", asFUNCTION(StringIntFactory), asCALL_CDECL); jassert( r >= 0 );
  484. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const float)", asFUNCTION(StringFloatFactory), asCALL_CDECL); jassert( r >= 0 );
  485. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const double)", asFUNCTION(StringDoubleFactory), asCALL_CDECL); jassert( r >= 0 );
  486. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_FACTORY, "String @f(const String &in)", asFUNCTION(StringCopyFactory), asCALL_CDECL); jassert( r >= 0 );
  487. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADDREF, "void f()", asMETHOD(asString,addRef), asCALL_THISCALL); jassert( r >= 0 );
  488. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_RELEASE, "void f()", asMETHOD(asString,release), asCALL_THISCALL); jassert( r >= 0 );
  489. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(const String &in)", asMETHODPR(asString, operator =, (const asString&), asString&), asCALL_THISCALL); jassert( r >= 0 );
  490. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(const String &in)", asMETHODPR(asString, operator+=, (const asString&), asString&), asCALL_THISCALL); jassert( r >= 0 );
  491. // Register the factory to return a handle to a new string
  492. r = engine->RegisterStringFactory ("String@", asFUNCTION(StringFactory), asCALL_CDECL); jassert( r >= 0 );
  493. #if 0
  494. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST); assertPrint (r);
  495. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(const String& in)", asFUNCTION(ConstructStringByString), asCALL_CDECL_OBJLAST); assertPrint (r);
  496. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(bool)", asFUNCTION(ConstructStringByBool), asCALL_CDECL_OBJLAST); assertPrint (r);
  497. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(uint)", asFUNCTION(ConstructStringByUInt), asCALL_CDECL_OBJLAST); assertPrint (r);
  498. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(int)", asFUNCTION(ConstructStringByInt), asCALL_CDECL_OBJLAST); assertPrint (r);
  499. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(float)", asFUNCTION(ConstructStringByFloat), asCALL_CDECL_OBJLAST); assertPrint (r);
  500. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_CONSTRUCT, "void f(double)", asFUNCTION(ConstructStringByDouble), asCALL_CDECL_OBJLAST); assertPrint (r);
  501. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST); assertPrint (r);
  502. #endif
  503. // Register the global operator overloads
  504. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, const String &in)", asFUNCTIONPR(operator +, (const asString &, const asString &), asString*), asCALL_CDECL); jassert( r >= 0 );
  505. r = engine->RegisterGlobalBehaviour (asBEHAVE_EQUAL, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator==, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  506. r = engine->RegisterGlobalBehaviour (asBEHAVE_NOTEQUAL, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator!=, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  507. r = engine->RegisterGlobalBehaviour (asBEHAVE_LEQUAL, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator<=, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  508. r = engine->RegisterGlobalBehaviour (asBEHAVE_GEQUAL, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator>=, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  509. r = engine->RegisterGlobalBehaviour (asBEHAVE_LESSTHAN, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator <, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  510. r = engine->RegisterGlobalBehaviour (asBEHAVE_GREATERTHAN, "bool f(const String &in, const String &in)", asFUNCTIONPR(operator >, (const asString &, const asString &), bool), asCALL_CDECL); jassert( r >= 0 );
  511. r = engine->RegisterGlobalBehaviour (asBEHAVE_EQUAL, "bool f(const String &in, const float)", asFUNCTIONPR(operator==, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  512. r = engine->RegisterGlobalBehaviour (asBEHAVE_NOTEQUAL, "bool f(const String &in, const float)", asFUNCTIONPR(operator!=, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  513. r = engine->RegisterGlobalBehaviour (asBEHAVE_LEQUAL, "bool f(const String &in, const float)", asFUNCTIONPR(operator<=, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  514. r = engine->RegisterGlobalBehaviour (asBEHAVE_GEQUAL, "bool f(const String &in, const float)", asFUNCTIONPR(operator>=, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  515. r = engine->RegisterGlobalBehaviour (asBEHAVE_LESSTHAN, "bool f(const String &in, const float)", asFUNCTIONPR(operator <, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  516. r = engine->RegisterGlobalBehaviour (asBEHAVE_GREATERTHAN, "bool f(const String &in, const float)", asFUNCTIONPR(operator >, (const asString &, const float), bool), asCALL_CDECL); jassert( r >= 0 );
  517. r = engine->RegisterGlobalBehaviour (asBEHAVE_EQUAL, "bool f(const String &in, const int)", asFUNCTIONPR(operator==, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  518. r = engine->RegisterGlobalBehaviour (asBEHAVE_NOTEQUAL, "bool f(const String &in, const int)", asFUNCTIONPR(operator!=, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  519. r = engine->RegisterGlobalBehaviour (asBEHAVE_LEQUAL, "bool f(const String &in, const int)", asFUNCTIONPR(operator<=, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  520. r = engine->RegisterGlobalBehaviour (asBEHAVE_GEQUAL, "bool f(const String &in, const int)", asFUNCTIONPR(operator>=, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  521. r = engine->RegisterGlobalBehaviour (asBEHAVE_LESSTHAN, "bool f(const String &in, const int)", asFUNCTIONPR(operator <, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  522. r = engine->RegisterGlobalBehaviour (asBEHAVE_GREATERTHAN, "bool f(const String &in, const int)", asFUNCTIONPR(operator >, (const asString &, const int), bool), asCALL_CDECL); jassert( r >= 0 );
  523. // Register the index operator
  524. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_INDEX, "String@ f(uint)", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  525. // r = engine->RegisterObjectBehaviour ("String", asBEHAVE_INDEX, "uint8 &f(uint)", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  526. // r = engine->RegisterObjectBehaviour ("String", asBEHAVE_INDEX, "const uint8 &f(uint) const", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  527. // Register the object methods
  528. r = engine->RegisterObjectMethod ("String", "int length() const", asMETHOD(String,length), asCALL_THISCALL); jassert( r >= 0 );
  529. r = engine->RegisterObjectMethod ("String", "int hashCode() const", asMETHOD(String,hashCode), asCALL_THISCALL); jassert( r >= 0 );
  530. r = engine->RegisterObjectMethod ("String", "bool isEmpty() const", asMETHOD(String,isEmpty), asCALL_THISCALL); jassert( r >= 0 );
  531. r = engine->RegisterObjectMethod ("String", "bool isNotEmpty() const", asMETHOD(String,isNotEmpty), asCALL_THISCALL); jassert( r >= 0 );
  532. r = engine->RegisterObjectMethod ("String", "bool equalsIgnoreCase(const String& in) const", asMETHOD(asString, equalsIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  533. r = engine->RegisterObjectMethod ("String", "int compare(const String& in) const", asMETHOD(asString, compare), asCALL_THISCALL); jassert( r >= 0 );
  534. r = engine->RegisterObjectMethod ("String", "int compareIgnoreCase(const String& in) const", asMETHOD(asString, compareIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  535. r = engine->RegisterObjectMethod ("String", "int compareLexicographically(const String& in) const", asMETHOD(asString, compareLexicographically), asCALL_THISCALL); jassert( r >= 0 );
  536. r = engine->RegisterObjectMethod ("String", "bool startsWith(const String& in) const", asMETHOD(asString, startsWith), asCALL_THISCALL); jassert( r >= 0 );
  537. r = engine->RegisterObjectMethod ("String", "bool startsWithIgnoreCase(const String& in) const", asMETHOD(asString, startsWithIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  538. r = engine->RegisterObjectMethod ("String", "bool endsWith(const String& in) const", asMETHOD(asString, endsWith), asCALL_THISCALL); jassert( r >= 0 );
  539. r = engine->RegisterObjectMethod ("String", "bool endsWithIgnoreCase(const String& in) const", asMETHOD(asString, endsWithIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  540. r = engine->RegisterObjectMethod ("String", "bool contains(const String& in) const", asMETHOD(asString, contains), asCALL_THISCALL); jassert( r >= 0 );
  541. r = engine->RegisterObjectMethod ("String", "bool containsIgnoreCase(const String& in) const", asMETHOD(asString, containsIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  542. r = engine->RegisterObjectMethod ("String", "bool containsWholeWord(const String& in) const", asMETHOD(asString, containsWholeWord), asCALL_THISCALL); jassert( r >= 0 );
  543. r = engine->RegisterObjectMethod ("String", "bool containsWholeWordIgnoreCase(const String& in) const", asMETHOD(asString, containsWholeWordIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  544. r = engine->RegisterObjectMethod ("String", "bool containsAnyOf(const String& in) const", asMETHOD(asString, containsAnyOf), asCALL_THISCALL); jassert( r >= 0 );
  545. r = engine->RegisterObjectMethod ("String", "bool containsOnly(const String& in) const", asMETHOD(asString, containsOnly), asCALL_THISCALL); jassert( r >= 0 );
  546. r = engine->RegisterObjectMethod ("String", "bool matchesWildcard(const String& in, const bool) const", asMETHOD(asString, matchesWildcard), asCALL_THISCALL); jassert( r >= 0 );
  547. r = engine->RegisterObjectMethod ("String", "int indexOf(const String& in) const", asMETHODPR(asString, indexOf, (const asString&), int), asCALL_THISCALL); jassert( r >= 0 );
  548. r = engine->RegisterObjectMethod ("String", "int indexOf(const int, const String& in) const", asMETHODPR(asString, indexOf, (const int, const asString&), int), asCALL_THISCALL); jassert( r >= 0 );
  549. r = engine->RegisterObjectMethod ("String", "int indexOfIgnoreCase(const String& in) const", asMETHODPR(asString, indexOfIgnoreCase, (const asString&), int), asCALL_THISCALL); jassert( r >= 0 );
  550. r = engine->RegisterObjectMethod ("String", "int indexOfIgnoreCase(const int, const String& in) const", asMETHODPR(asString, indexOfIgnoreCase, (const int, const asString&), int), asCALL_THISCALL); jassert( r >= 0 );
  551. r = engine->RegisterObjectMethod ("String", "int lastIndexOf(const String& in) const", asMETHOD(asString, lastIndexOf), asCALL_THISCALL); jassert( r >= 0 );
  552. r = engine->RegisterObjectMethod ("String", "int lastIndexOfIgnoreCase(const String& in) const", asMETHOD(asString, lastIndexOfIgnoreCase), asCALL_THISCALL); jassert( r >= 0 );
  553. r = engine->RegisterObjectMethod ("String", "String@ substring(int)", asMETHODPR(asString, substring, (int), asString*), asCALL_THISCALL); jassert( r >= 0 );
  554. r = engine->RegisterObjectMethod ("String", "String@ substring(int,int)", asMETHODPR(asString, substring, (int,int), asString*), asCALL_THISCALL); jassert( r >= 0 );
  555. r = engine->RegisterObjectMethod ("String", "String@ dropLastCharacters(int)", asMETHOD(asString, dropLastCharacters), asCALL_THISCALL); jassert( r >= 0 );
  556. r = engine->RegisterObjectMethod ("String", "String@ fromFirstOccurrenceOf(const String& in,bool,bool)", asMETHOD(asString, fromFirstOccurrenceOf), asCALL_THISCALL); jassert( r >= 0 );
  557. r = engine->RegisterObjectMethod ("String", "String@ fromLastOccurrenceOf(const String& in,bool,bool)", asMETHOD(asString, fromLastOccurrenceOf), asCALL_THISCALL); jassert( r >= 0 );
  558. r = engine->RegisterObjectMethod ("String", "String@ upToFirstOccurrenceOf(const String& in,bool,bool)", asMETHOD(asString, upToFirstOccurrenceOf), asCALL_THISCALL); jassert( r >= 0 );
  559. r = engine->RegisterObjectMethod ("String", "String@ upToLastOccurrenceOf(const String& in,bool,bool)", asMETHOD(asString, upToLastOccurrenceOf), asCALL_THISCALL); jassert( r >= 0 );
  560. r = engine->RegisterObjectMethod ("String", "String@ trim()", asMETHOD(asString, trim), asCALL_THISCALL); jassert( r >= 0 );
  561. r = engine->RegisterObjectMethod ("String", "String@ trimStart()", asMETHOD(asString, trimStart), asCALL_THISCALL); jassert( r >= 0 );
  562. r = engine->RegisterObjectMethod ("String", "String@ trimEnd()", asMETHOD(asString, trimEnd), asCALL_THISCALL); jassert( r >= 0 );
  563. r = engine->RegisterObjectMethod ("String", "String@ toUpperCase()", asMETHOD(asString, toUpperCase), asCALL_THISCALL); jassert( r >= 0 );
  564. r = engine->RegisterObjectMethod ("String", "String@ toLowerCase()", asMETHOD(asString, toLowerCase), asCALL_THISCALL); jassert( r >= 0 );
  565. r = engine->RegisterObjectMethod ("String", "String@ replaceSection(int,int,const String& in)", asMETHOD(asString, replaceSection), asCALL_THISCALL); jassert( r >= 0 );
  566. r = engine->RegisterObjectMethod ("String", "String@ replace(const String& in,const String& in,bool)", asMETHOD(asString, replace), asCALL_THISCALL); jassert( r >= 0 );
  567. r = engine->RegisterObjectMethod ("String", "String@ replaceCharacter(const String& in,const String& in)",asMETHOD(asString, replaceCharacter), asCALL_THISCALL); jassert( r >= 0 );
  568. r = engine->RegisterObjectMethod ("String", "String@ replaceCharacters(const String& in,const String& in)",asMETHOD(asString, replaceCharacters), asCALL_THISCALL); jassert( r >= 0 );
  569. r = engine->RegisterObjectMethod ("String", "String@ retainCharacters(const String& in)", asMETHOD(asString, retainCharacters), asCALL_THISCALL); jassert( r >= 0 );
  570. r = engine->RegisterObjectMethod ("String", "String@ removeCharacters(const String& in)", asMETHOD(asString, removeCharacters), asCALL_THISCALL); jassert( r >= 0 );
  571. r = engine->RegisterObjectMethod ("String", "String@ initialSectionContainingOnly(const String& in)", asMETHOD(asString, initialSectionContainingOnly), asCALL_THISCALL); jassert( r >= 0 );
  572. r = engine->RegisterObjectMethod ("String", "String@ initialSectionNotContaining(const String& in)", asMETHOD(asString, initialSectionNotContaining), asCALL_THISCALL); jassert( r >= 0 );
  573. r = engine->RegisterObjectMethod ("String", "bool isQuotedString() const", asMETHOD(String,isQuotedString), asCALL_THISCALL); jassert( r >= 0 );
  574. r = engine->RegisterObjectMethod ("String", "String@ unquoted()", asMETHOD(asString, unquoted), asCALL_THISCALL); jassert( r >= 0 );
  575. r = engine->RegisterObjectMethod ("String", "String@ quoted(const String& in)", asMETHOD(asString, quoted), asCALL_THISCALL); jassert( r >= 0 );
  576. // Register global operators
  577. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(double)", asFUNCTION(AssignDoubleToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  578. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(double)", asFUNCTION(AddAssignDoubleToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  579. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, double)", asFUNCTION(AddStringDouble), asCALL_CDECL); jassert( r >= 0 );
  580. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(double, const String &in)", asFUNCTION(AddDoubleString), asCALL_CDECL); jassert( r >= 0 );
  581. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(float)", asFUNCTION(AssignFloatToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  582. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(float)", asFUNCTION(AddAssignFloatToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  583. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, float)", asFUNCTION(AddStringFloat), asCALL_CDECL); jassert( r >= 0 );
  584. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(float, const String &in)", asFUNCTION(AddFloatString), asCALL_CDECL); jassert( r >= 0 );
  585. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(int)", asFUNCTION(AssignIntToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  586. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(int)", asFUNCTION(AddAssignIntToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  587. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, int)", asFUNCTION(AddStringInt), asCALL_CDECL); jassert( r >= 0 );
  588. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(int, const String &in)", asFUNCTION(AddIntString), asCALL_CDECL); jassert( r >= 0 );
  589. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(uint)", asFUNCTION(AssignUIntToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  590. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(uint)", asFUNCTION(AddAssignUIntToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  591. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, uint)", asFUNCTION(AddStringUInt), asCALL_CDECL); jassert( r >= 0 );
  592. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(uint, const String &in)", asFUNCTION(AddUIntString), asCALL_CDECL); jassert( r >= 0 );
  593. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ASSIGNMENT, "String &f(bool)", asFUNCTION(AssignBoolToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  594. r = engine->RegisterObjectBehaviour ("String", asBEHAVE_ADD_ASSIGN, "String &f(bool)", asFUNCTION(AddAssignBoolToString), asCALL_CDECL_OBJLAST); jassert( r >= 0 );
  595. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(const String &in, bool)", asFUNCTION(AddStringBool), asCALL_CDECL); jassert( r >= 0 );
  596. r = engine->RegisterGlobalBehaviour (asBEHAVE_ADD, "String@ f(bool, const String &in)", asFUNCTION(AddBoolString), asCALL_CDECL); jassert( r >= 0 );
  597. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, String &in)", asFUNCTION(StringShiftLeftString), asCALL_CDECL); jassert( r >= 0 );
  598. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, double)", asFUNCTION(StringShiftLeftDouble), asCALL_CDECL); jassert( r >= 0 );
  599. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, float)", asFUNCTION(StringShiftLeftFloat), asCALL_CDECL); jassert( r >= 0 );
  600. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, int)", asFUNCTION(StringShiftLeftInt), asCALL_CDECL); jassert( r >= 0 );
  601. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, uint)", asFUNCTION(StringShiftLeftUInt), asCALL_CDECL); jassert( r >= 0 );
  602. r = engine->RegisterGlobalBehaviour (asBEHAVE_BIT_SLL, "String& f(const String &in, bool)", asFUNCTION(StringShiftLeftBool), asCALL_CDECL); jassert( r >= 0 );
  603. }
  604. } // end namespace Bindings
  605. END_JUCE_NAMESPACE
  606. #endif // JUCE_SUPPORT_SCRIPTING