Addons.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Addons.h"
  25. #include "StringBase.h"
  26. #include <cstring>
  27. #include <stdio.h>
  28. // Adapted from Angelscript's scriptarray & scriptstdstring add-ons, but with garbage collection disabled
  29. /// %Script array buffer.
  30. struct SArrayBuffer
  31. {
  32. asDWORD numElements;
  33. asBYTE data[1];
  34. };
  35. static CScriptArray* ScriptArrayFactory2(asIObjectType *ot, asUINT length)
  36. {
  37. CScriptArray *a = new CScriptArray(length, ot);
  38. // It's possible the constructor raised a script exception, in which case we
  39. // need to free the memory and return null instead, else we get a memory leak.
  40. asIScriptContext *ctx = asGetActiveContext();
  41. if( ctx && ctx->GetState() == asEXECUTION_EXCEPTION )
  42. {
  43. delete a;
  44. return 0;
  45. }
  46. return a;
  47. }
  48. static CScriptArray* ScriptArrayFactoryDefVal(asIObjectType *ot, asUINT length, void *defVal)
  49. {
  50. CScriptArray *a = new CScriptArray(length, defVal, ot);
  51. // It's possible the constructor raised a script exception, in which case we
  52. // need to free the memory and return null instead, else we get a memory leak.
  53. asIScriptContext *ctx = asGetActiveContext();
  54. if( ctx && ctx->GetState() == asEXECUTION_EXCEPTION )
  55. {
  56. delete a;
  57. return 0;
  58. }
  59. return a;
  60. }
  61. static CScriptArray* ScriptArrayFactory(asIObjectType *ot)
  62. {
  63. return ScriptArrayFactory2(ot, 0);
  64. }
  65. // This optional callback is called when the template type is first used by the compiler.
  66. // It allows the application to validate if the template can be instanciated for the requested
  67. // subtype at compile time, instead of at runtime.
  68. static bool ScriptArrayTemplateCallback(asIObjectType *ot)
  69. {
  70. // Make sure the subtype can be instanciated with a default factory/constructor,
  71. // otherwise we won't be able to instanciate the elements. Script classes always
  72. // have default factories, so we don't have to worry about those.
  73. int typeId = ot->GetSubTypeId();
  74. if( typeId == asTYPEID_VOID )
  75. return false;
  76. if( (typeId & asTYPEID_MASK_OBJECT) && !(typeId & asTYPEID_OBJHANDLE) && !(typeId & asTYPEID_SCRIPTOBJECT) )
  77. {
  78. asIObjectType *subtype = ot->GetEngine()->GetObjectTypeById(typeId);
  79. asDWORD flags = subtype->GetFlags();
  80. if( (flags & asOBJ_VALUE) && !(flags & asOBJ_POD) )
  81. {
  82. // Verify that there is a default constructor
  83. for( asUINT n = 0; n < subtype->GetBehaviourCount(); n++ )
  84. {
  85. asEBehaviours beh;
  86. int funcId = subtype->GetBehaviourByIndex(n, &beh);
  87. if( beh != asBEHAVE_CONSTRUCT ) continue;
  88. asIScriptFunction *func = ot->GetEngine()->GetFunctionById(funcId);
  89. if( func->GetParamCount() == 0 )
  90. {
  91. // Found the default constructor
  92. return true;
  93. }
  94. }
  95. // There is no default constructor
  96. return false;
  97. }
  98. else if( (flags & asOBJ_REF) )
  99. {
  100. // Verify that there is a default factory
  101. for( asUINT n = 0; n < subtype->GetFactoryCount(); n++ )
  102. {
  103. int funcId = subtype->GetFactoryIdByIndex(n);
  104. asIScriptFunction *func = ot->GetEngine()->GetFunctionById(funcId);
  105. if( func->GetParamCount() == 0 )
  106. {
  107. // Found the default factory
  108. return true;
  109. }
  110. }
  111. // No default factory
  112. return false;
  113. }
  114. }
  115. // The type is ok
  116. return true;
  117. }
  118. CScriptArray &CScriptArray::operator=(const CScriptArray &other)
  119. {
  120. // Only perform the copy if the array types are the same
  121. if( &other != this &&
  122. other.GetArrayObjectType() == GetArrayObjectType() )
  123. {
  124. if( buffer )
  125. {
  126. DeleteBuffer(buffer);
  127. buffer = 0;
  128. }
  129. // Copy all elements from the other array
  130. CreateBuffer(&buffer, other.buffer->numElements);
  131. CopyBuffer(buffer, other.buffer);
  132. }
  133. return *this;
  134. }
  135. CScriptArray::CScriptArray(asUINT length, asIObjectType *ot)
  136. {
  137. refCount = 1;
  138. gcFlag = false;
  139. objType = ot;
  140. objType->AddRef();
  141. buffer = 0;
  142. Precache();
  143. // Determine element size
  144. if( subTypeId & asTYPEID_MASK_OBJECT )
  145. {
  146. elementSize = sizeof(asPWORD);
  147. }
  148. else
  149. {
  150. elementSize = objType->GetEngine()->GetSizeOfPrimitiveType(subTypeId);
  151. }
  152. // Make sure the array size isn't too large for us to handle
  153. if( !CheckMaxSize(length) )
  154. {
  155. // Don't continue with the initialization
  156. return;
  157. }
  158. CreateBuffer(&buffer, length);
  159. }
  160. CScriptArray::CScriptArray(asUINT length, void *defVal, asIObjectType *ot)
  161. {
  162. refCount = 1;
  163. gcFlag = false;
  164. objType = ot;
  165. objType->AddRef();
  166. buffer = 0;
  167. Precache();
  168. // Determine element size
  169. if( subTypeId & asTYPEID_MASK_OBJECT )
  170. {
  171. elementSize = sizeof(asPWORD);
  172. }
  173. else
  174. {
  175. elementSize = objType->GetEngine()->GetSizeOfPrimitiveType(subTypeId);
  176. }
  177. // Make sure the array size isn't too large for us to handle
  178. if( !CheckMaxSize(length) )
  179. {
  180. // Don't continue with the initialization
  181. return;
  182. }
  183. CreateBuffer(&buffer, length);
  184. // Initialize the elements with the default value
  185. for( asUINT n = 0; n < GetSize(); n++ )
  186. SetValue(n, defVal);
  187. }
  188. // Internal
  189. void CScriptArray::SetValue(asUINT index, void *value)
  190. {
  191. if( (subTypeId & ~0x03FFFFFF) && !(subTypeId & asTYPEID_OBJHANDLE) )
  192. objType->GetEngine()->CopyScriptObject(At(index), value, subTypeId);
  193. else if( subTypeId & asTYPEID_OBJHANDLE )
  194. {
  195. *(void**)At(index) = *(void**)value;
  196. objType->GetEngine()->AddRefScriptObject(*(void**)value, objType->GetSubType());
  197. }
  198. else if( subTypeId == asTYPEID_BOOL ||
  199. subTypeId == asTYPEID_INT8 ||
  200. subTypeId == asTYPEID_UINT8 )
  201. *(char*)At(index) = *(char*)value;
  202. else if( subTypeId == asTYPEID_INT16 ||
  203. subTypeId == asTYPEID_UINT16 )
  204. *(short*)At(index) = *(short*)value;
  205. else if( subTypeId == asTYPEID_INT32 ||
  206. subTypeId == asTYPEID_UINT32 ||
  207. subTypeId == asTYPEID_FLOAT )
  208. *(int*)At(index) = *(int*)value;
  209. else if( subTypeId == asTYPEID_INT64 ||
  210. subTypeId == asTYPEID_UINT64 ||
  211. subTypeId == asTYPEID_DOUBLE )
  212. *(double*)At(index) = *(double*)value;
  213. }
  214. CScriptArray::~CScriptArray()
  215. {
  216. if( buffer )
  217. {
  218. DeleteBuffer(buffer);
  219. buffer = 0;
  220. }
  221. if( objType ) objType->Release();
  222. }
  223. asUINT CScriptArray::GetSize() const
  224. {
  225. return buffer->numElements;
  226. }
  227. void CScriptArray::Resize(asUINT numElements)
  228. {
  229. if( numElements & 0x80000000 )
  230. {
  231. CheckMaxSize(numElements);
  232. return;
  233. }
  234. Resize((int)numElements - (int)buffer->numElements, (asUINT)-1);
  235. }
  236. // Internal
  237. void CScriptArray::Resize(int delta, asUINT at)
  238. {
  239. if( delta < 0 )
  240. {
  241. if( -delta > (int)buffer->numElements )
  242. delta = -(int)buffer->numElements;
  243. if( at > buffer->numElements + delta )
  244. at = buffer->numElements + delta;
  245. }
  246. else if( delta > 0 )
  247. {
  248. // Make sure the array size isn't too large for us to handle
  249. if( delta > 0 && !CheckMaxSize(buffer->numElements + delta) )
  250. return;
  251. if( at > buffer->numElements )
  252. at = buffer->numElements;
  253. }
  254. if( delta == 0 ) return;
  255. // Allocate memory for the buffer
  256. SArrayBuffer *newBuffer;
  257. newBuffer = (SArrayBuffer*)new asBYTE[sizeof(SArrayBuffer)-1 + elementSize*(buffer->numElements + delta)];
  258. newBuffer->numElements = buffer->numElements + delta;
  259. memcpy(newBuffer->data, buffer->data, at*elementSize);
  260. if( delta > 0 && at < buffer->numElements )
  261. memcpy(newBuffer->data + (at+delta)*elementSize, buffer->data + at*elementSize, (buffer->numElements-at)*elementSize);
  262. else if( delta < 0 && at < buffer->numElements )
  263. memcpy(newBuffer->data + at*elementSize, buffer->data + (at-delta)*elementSize, (buffer->numElements-at+delta)*elementSize);
  264. if( subTypeId & asTYPEID_MASK_OBJECT )
  265. {
  266. if( delta > 0 )
  267. Construct(newBuffer, at, at+delta);
  268. else if( delta < 0 )
  269. Destruct(buffer, at, at-delta);
  270. }
  271. // Release the old buffer
  272. delete[] (asBYTE*)buffer;
  273. buffer = newBuffer;
  274. }
  275. // internal
  276. bool CScriptArray::CheckMaxSize(asUINT numElements)
  277. {
  278. // This code makes sure the size of the buffer that is allocated
  279. // for the array doesn't overflow and becomes smaller than requested
  280. asUINT maxSize = 0xFFFFFFFFul - sizeof(SArrayBuffer) + 1;
  281. if( subTypeId & asTYPEID_MASK_OBJECT )
  282. maxSize /= sizeof(void*);
  283. else if( elementSize > 0 )
  284. maxSize /= elementSize;
  285. if( numElements > maxSize )
  286. {
  287. asIScriptContext *ctx = asGetActiveContext();
  288. if( ctx )
  289. {
  290. // Set a script exception
  291. ctx->SetException("Too large array size");
  292. }
  293. return false;
  294. }
  295. // OK
  296. return true;
  297. }
  298. asIObjectType *CScriptArray::GetArrayObjectType() const
  299. {
  300. return objType;
  301. }
  302. int CScriptArray::GetArrayTypeId() const
  303. {
  304. return objType->GetTypeId();
  305. }
  306. int CScriptArray::GetElementTypeId() const
  307. {
  308. return subTypeId;
  309. }
  310. void CScriptArray::InsertAt(asUINT index, void *value)
  311. {
  312. if( index > buffer->numElements )
  313. {
  314. // If this is called from a script we raise a script exception
  315. asIScriptContext *ctx = asGetActiveContext();
  316. if( ctx )
  317. ctx->SetException("Index out of bounds");
  318. return;
  319. }
  320. // Make room for the new element
  321. Resize(1, index);
  322. // Set the value of the new element
  323. SetValue(index, value);
  324. }
  325. void CScriptArray::InsertLast(void *value)
  326. {
  327. InsertAt(buffer->numElements, value);
  328. }
  329. void CScriptArray::RemoveAt(asUINT index)
  330. {
  331. if( index >= buffer->numElements )
  332. {
  333. // If this is called from a script we raise a script exception
  334. asIScriptContext *ctx = asGetActiveContext();
  335. if( ctx )
  336. ctx->SetException("Index out of bounds");
  337. return;
  338. }
  339. // Remove the element
  340. Resize(-1, index);
  341. }
  342. void CScriptArray::RemoveLast()
  343. {
  344. RemoveAt(buffer->numElements-1);
  345. }
  346. // Return a pointer to the array element. Returns 0 if the index is out of bounds
  347. void *CScriptArray::At(asUINT index)
  348. {
  349. if( index >= buffer->numElements )
  350. {
  351. // If this is called from a script we raise a script exception
  352. asIScriptContext *ctx = asGetActiveContext();
  353. if( ctx )
  354. ctx->SetException("Index out of bounds");
  355. return 0;
  356. }
  357. else
  358. {
  359. if( (subTypeId & asTYPEID_MASK_OBJECT) && !(subTypeId & asTYPEID_OBJHANDLE) )
  360. return (void*)((size_t*)buffer->data)[index];
  361. else
  362. return buffer->data + elementSize*index;
  363. }
  364. }
  365. // internal
  366. void CScriptArray::CreateBuffer(SArrayBuffer **buf, asUINT numElements)
  367. {
  368. if( subTypeId & asTYPEID_MASK_OBJECT )
  369. {
  370. *buf = (SArrayBuffer*)new asBYTE[sizeof(SArrayBuffer)-1+sizeof(void*)*numElements];
  371. (*buf)->numElements = numElements;
  372. }
  373. else
  374. {
  375. *buf = (SArrayBuffer*)new asBYTE[sizeof(SArrayBuffer)-1+elementSize*numElements];
  376. (*buf)->numElements = numElements;
  377. }
  378. Construct(*buf, 0, numElements);
  379. }
  380. // internal
  381. void CScriptArray::DeleteBuffer(SArrayBuffer *buf)
  382. {
  383. Destruct(buf, 0, buf->numElements);
  384. // Free the buffer
  385. delete[] (asBYTE*)buf;
  386. }
  387. // internal
  388. void CScriptArray::Construct(SArrayBuffer *buf, asUINT start, asUINT end)
  389. {
  390. if( subTypeId & asTYPEID_OBJHANDLE )
  391. {
  392. // Set all object handles to null
  393. void *d = (void*)(buf->data + start * sizeof(void*));
  394. memset(d, 0, (end-start)*sizeof(void*));
  395. }
  396. else if( subTypeId & asTYPEID_MASK_OBJECT )
  397. {
  398. void **max = (void**)(buf->data + end * sizeof(void*));
  399. void **d = (void**)(buf->data + start * sizeof(void*));
  400. asIScriptEngine *engine = objType->GetEngine();
  401. for( ; d < max; d++ )
  402. *d = (void*)engine->CreateScriptObject(subTypeId);
  403. }
  404. }
  405. // internal
  406. void CScriptArray::Destruct(SArrayBuffer *buf, asUINT start, asUINT end)
  407. {
  408. if( subTypeId & asTYPEID_MASK_OBJECT )
  409. {
  410. asIScriptEngine *engine = objType->GetEngine();
  411. void **max = (void**)(buf->data + end * sizeof(void*));
  412. void **d = (void**)(buf->data + start * sizeof(void*));
  413. for( ; d < max; d++ )
  414. {
  415. if( *d )
  416. engine->ReleaseScriptObject(*d, objType->GetSubType());
  417. }
  418. }
  419. }
  420. // internal
  421. bool CScriptArray::Less(const void *a, const void *b, bool asc, asIScriptContext *ctx)
  422. {
  423. if( !asc )
  424. {
  425. // Swap items
  426. const void *TEMP = a;
  427. a = b;
  428. b = TEMP;
  429. }
  430. if( subTypeId <= asTYPEID_DOUBLE )
  431. {
  432. // Simple compare of values
  433. switch( subTypeId )
  434. {
  435. #define COMPARE(T) *((T*)a) < *((T*)b)
  436. case asTYPEID_BOOL: return COMPARE(bool);
  437. case asTYPEID_INT8: return COMPARE(signed char);
  438. case asTYPEID_UINT8: return COMPARE(unsigned char);
  439. case asTYPEID_INT16: return COMPARE(signed short);
  440. case asTYPEID_UINT16: return COMPARE(unsigned short);
  441. case asTYPEID_INT32: return COMPARE(signed int);
  442. case asTYPEID_UINT32: return COMPARE(unsigned int);
  443. case asTYPEID_FLOAT: return COMPARE(float);
  444. case asTYPEID_DOUBLE: return COMPARE(double);
  445. #undef COMPARE
  446. }
  447. }
  448. else
  449. {
  450. int r = 0;
  451. // Execute object opCmp
  452. // TODO: Add proper error handling
  453. r = ctx->Prepare(cmpFuncId); assert(r >= 0);
  454. r = ctx->SetObject((void*)a); assert(r >= 0);
  455. r = ctx->SetArgAddress(0, (void*)b); assert(r >= 0);
  456. r = ctx->Execute();
  457. if( r == asEXECUTION_FINISHED )
  458. {
  459. return (int)ctx->GetReturnDWord() < 0;
  460. }
  461. }
  462. return false;
  463. }
  464. void CScriptArray::Reverse()
  465. {
  466. asUINT size = GetSize();
  467. if( size >= 2 )
  468. {
  469. asBYTE TEMP[16];
  470. for( asUINT i = 0; i < size / 2; i++ )
  471. {
  472. Copy(TEMP, GetArrayItemPointer(i));
  473. Copy(GetArrayItemPointer(i), GetArrayItemPointer(size - i - 1));
  474. Copy(GetArrayItemPointer(size - i - 1), TEMP);
  475. }
  476. }
  477. }
  478. // internal
  479. bool CScriptArray::Equals(const void *a, const void *b, asIScriptContext *ctx)
  480. {
  481. if( subTypeId <= asTYPEID_DOUBLE )
  482. {
  483. // Simple compare of values
  484. switch( subTypeId )
  485. {
  486. #define COMPARE(T) *((T*)a) == *((T*)b)
  487. case asTYPEID_BOOL: return COMPARE(bool);
  488. case asTYPEID_INT8: return COMPARE(signed char);
  489. case asTYPEID_UINT8: return COMPARE(unsigned char);
  490. case asTYPEID_INT16: return COMPARE(signed short);
  491. case asTYPEID_UINT16: return COMPARE(unsigned short);
  492. case asTYPEID_INT32: return COMPARE(signed int);
  493. case asTYPEID_UINT32: return COMPARE(unsigned int);
  494. case asTYPEID_FLOAT: return COMPARE(float);
  495. case asTYPEID_DOUBLE: return COMPARE(double);
  496. #undef COMPARE
  497. }
  498. }
  499. else
  500. {
  501. int r = 0;
  502. // Execute object opEquals if available
  503. if( eqFuncId >= 0 )
  504. {
  505. // TODO: Add proper error handling
  506. r = ctx->Prepare(eqFuncId); assert(r >= 0);
  507. r = ctx->SetObject((void*)a); assert(r >= 0);
  508. r = ctx->SetArgAddress(0, (void*)b); assert(r >= 0);
  509. r = ctx->Execute();
  510. if( r == asEXECUTION_FINISHED )
  511. {
  512. return ctx->GetReturnByte() != 0;
  513. }
  514. }
  515. // Execute object opCmp if available
  516. if( cmpFuncId >= 0 )
  517. {
  518. // TODO: Add proper error handling
  519. r = ctx->Prepare(cmpFuncId); assert(r >= 0);
  520. r = ctx->SetObject((void*)a); assert(r >= 0);
  521. r = ctx->SetArgAddress(0, (void*)b); assert(r >= 0);
  522. r = ctx->Execute();
  523. if( r == asEXECUTION_FINISHED )
  524. {
  525. return (int)ctx->GetReturnDWord() == 0;
  526. }
  527. }
  528. }
  529. return false;
  530. }
  531. int CScriptArray::Find(void *value)
  532. {
  533. return Find(0, value);
  534. }
  535. int CScriptArray::Find(asUINT index, void *value)
  536. {
  537. // Subtype isn't primitive and doesn't have opEquals / opCmp
  538. if( subTypeId > asTYPEID_DOUBLE && (cmpFuncId <= 0 && eqFuncId <= 0) )
  539. {
  540. asIScriptContext *ctx = asGetActiveContext();
  541. asIObjectType* subType = objType->GetEngine()->GetObjectTypeById(subTypeId);
  542. // Throw an exception
  543. if( ctx )
  544. {
  545. char tmp[512];
  546. #if defined(_MSC_VER) && _MSC_VER >= 1500
  547. sprintf_s(tmp, 512, "Type '%s' does not have opEquals / opCmp", subType->GetName());
  548. #else
  549. sprintf(tmp, "Type '%s' does not have opEquals / opCmp", subType->GetName());
  550. #endif
  551. ctx->SetException(tmp);
  552. }
  553. return -1;
  554. }
  555. asIScriptContext *cmpContext = 0;
  556. if( subTypeId > asTYPEID_DOUBLE )
  557. {
  558. // TODO: Ideally this context would be retrieved from a pool, so we don't have to
  559. // create a new one everytime. We could keep a context with the array object
  560. // but that would consume a lot of resources as each context is quite heavy.
  561. cmpContext = objType->GetEngine()->CreateContext();
  562. }
  563. int ret = -1;
  564. asUINT size = GetSize();
  565. if( index < size )
  566. {
  567. for( asUINT i = index; i < size; i++ )
  568. {
  569. // value passed by reference
  570. if( Equals(At(i), (value), cmpContext) )
  571. {
  572. ret = (int)i;
  573. break;
  574. }
  575. }
  576. }
  577. if( cmpContext )
  578. cmpContext->Release();
  579. return ret;
  580. }
  581. // internal
  582. // Copy object handle or primitive value
  583. void CScriptArray::Copy(void *dst, void *src)
  584. {
  585. memcpy(dst, src, elementSize);
  586. }
  587. // internal
  588. // Return pointer to array item (object handle or primitive value)
  589. void *CScriptArray::GetArrayItemPointer(int index)
  590. {
  591. return buffer->data + index * elementSize;
  592. }
  593. // internal
  594. // Return pointer to data in buffer (object or primitive)
  595. void *CScriptArray::GetDataPointer(void *buffer)
  596. {
  597. if ((subTypeId & asTYPEID_MASK_OBJECT) && !(subTypeId & asTYPEID_OBJHANDLE) )
  598. {
  599. // Real address of object
  600. return reinterpret_cast<void*>(*(size_t*)buffer);
  601. }
  602. else
  603. {
  604. // Primitive is just a raw data
  605. return buffer;
  606. }
  607. }
  608. // Sort ascending
  609. void CScriptArray::SortAsc()
  610. {
  611. Sort(0, GetSize(), true);
  612. }
  613. // Sort ascending
  614. void CScriptArray::SortAsc(asUINT index, asUINT count)
  615. {
  616. Sort(index, count, true);
  617. }
  618. // Sort descending
  619. void CScriptArray::SortDesc()
  620. {
  621. Sort(0, GetSize(), false);
  622. }
  623. // Sort descending
  624. void CScriptArray::SortDesc(asUINT index, asUINT count)
  625. {
  626. Sort(index, count, false);
  627. }
  628. // internal
  629. void CScriptArray::Sort(asUINT index, asUINT count, bool asc)
  630. {
  631. // Subtype isn't primitive and doesn't have opCmp
  632. if( subTypeId > asTYPEID_DOUBLE && cmpFuncId <= 0 )
  633. {
  634. asIScriptContext *ctx = asGetActiveContext();
  635. asIObjectType* subType = objType->GetEngine()->GetObjectTypeById(subTypeId);
  636. // Throw an exception
  637. if( ctx )
  638. {
  639. char tmp[512];
  640. #if defined(_MSC_VER) && _MSC_VER >= 1500
  641. sprintf_s(tmp, 512, "Type '%s' does not have opCmp", subType->GetName());
  642. #else
  643. sprintf(tmp, "Type '%s' does not have opCmp", subType->GetName());
  644. #endif
  645. ctx->SetException(tmp);
  646. }
  647. return;
  648. }
  649. // No need to sort
  650. if( count < 2 )
  651. {
  652. return;
  653. }
  654. int start = index;
  655. int end = index + count;
  656. // Check if we could access invalid item while sorting
  657. if( start >= (int)buffer->numElements || end > (int)buffer->numElements )
  658. {
  659. asIScriptContext *ctx = asGetActiveContext();
  660. // Throw an exception
  661. if( ctx )
  662. {
  663. ctx->SetException("Index out of bounds");
  664. }
  665. return;
  666. }
  667. asBYTE tmp[16];
  668. asIScriptContext *cmpContext = 0;
  669. if( subTypeId > asTYPEID_DOUBLE )
  670. {
  671. // TODO: Ideally this context would be retrieved from a pool, so we don't have to
  672. // create a new one everytime. We could keep a context with the array object
  673. // but that would consume a lot of resources as each context is quite heavy.
  674. cmpContext = objType->GetEngine()->CreateContext();
  675. }
  676. // Insertion sort
  677. for( int i = start + 1; i < end; i++ )
  678. {
  679. Copy(tmp, GetArrayItemPointer(i));
  680. int j = i - 1;
  681. while( j >= start && Less(GetDataPointer(tmp), At(j), asc, cmpContext) )
  682. {
  683. Copy(GetArrayItemPointer(j + 1), GetArrayItemPointer(j));
  684. j--;
  685. }
  686. Copy(GetArrayItemPointer(j + 1), tmp);
  687. }
  688. if( cmpContext )
  689. cmpContext->Release();
  690. }
  691. // internal
  692. void CScriptArray::CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src)
  693. {
  694. asIScriptEngine *engine = objType->GetEngine();
  695. if( subTypeId & asTYPEID_OBJHANDLE )
  696. {
  697. // Copy the references and increase the reference counters
  698. if( dst->numElements > 0 && src->numElements > 0 )
  699. {
  700. int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
  701. void **max = (void**)(dst->data + count * sizeof(void*));
  702. void **d = (void**)dst->data;
  703. void **s = (void**)src->data;
  704. for( ; d < max; d++, s++ )
  705. {
  706. *d = *s;
  707. if( *d )
  708. engine->AddRefScriptObject(*d, objType->GetSubType());
  709. }
  710. }
  711. }
  712. else
  713. {
  714. if( dst->numElements > 0 && src->numElements > 0 )
  715. {
  716. int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
  717. if( subTypeId & asTYPEID_MASK_OBJECT )
  718. {
  719. // Call the assignment operator on all of the objects
  720. void **max = (void**)(dst->data + count * sizeof(void*));
  721. void **d = (void**)dst->data;
  722. void **s = (void**)src->data;
  723. for( ; d < max; d++, s++ )
  724. engine->CopyScriptObject(*d, *s, subTypeId);
  725. }
  726. else
  727. {
  728. // Primitives are copied byte for byte
  729. memcpy(dst->data, src->data, count*elementSize);
  730. }
  731. }
  732. }
  733. }
  734. // internal
  735. // Precache some info
  736. void CScriptArray::Precache()
  737. {
  738. // TODO: optimize: This information could be stored in the object type as user data,
  739. // then it wouldn't be necessary to look for this for each array initialization
  740. subTypeId = objType->GetSubTypeId();
  741. cmpFuncId = -1;
  742. eqFuncId = -1;
  743. // Object - search for opCmp / opEquals
  744. if( subTypeId > asTYPEID_DOUBLE )
  745. {
  746. asIObjectType *subType = objType->GetEngine()->GetObjectTypeById(subTypeId);
  747. if( subType )
  748. {
  749. for( asUINT i = 0; i < subType->GetMethodCount(); i++ )
  750. {
  751. asIScriptFunction *func = subType->GetMethodByIndex(i);
  752. if( func->GetParamCount() == 1 /* && func->IsReadOnly() */ )
  753. {
  754. asDWORD flags = 0;
  755. int returnTypeId = func->GetReturnTypeId();
  756. int paramTypeId = func->GetParamTypeId(0, &flags);
  757. if( flags == asTM_INREF && paramTypeId == subTypeId )
  758. {
  759. if( returnTypeId == asTYPEID_INT32 && strcmp(func->GetName(), "opCmp") == 0 )
  760. {
  761. cmpFuncId = subType->GetMethodIdByIndex(i);
  762. }
  763. if( returnTypeId == asTYPEID_BOOL && strcmp(func->GetName(), "opEquals") == 0 )
  764. {
  765. eqFuncId = subType->GetMethodIdByIndex(i);
  766. }
  767. if( cmpFuncId >= 0 && eqFuncId >= 0 )
  768. {
  769. break;
  770. }
  771. }
  772. }
  773. }
  774. }
  775. }
  776. }
  777. void CScriptArray::AddRef() const
  778. {
  779. // Clear the GC flag then increase the counter
  780. gcFlag = false;
  781. refCount++;
  782. }
  783. void CScriptArray::Release() const
  784. {
  785. // Now do the actual releasing (clearing the flag set by GC)
  786. gcFlag = false;
  787. if( --refCount == 0 )
  788. {
  789. delete this;
  790. }
  791. }
  792. static void ScriptArrayClear(CScriptArray* ptr)
  793. {
  794. ptr->Resize(0);
  795. }
  796. static bool ScriptArrayIsEmpty(CScriptArray* ptr)
  797. {
  798. return ptr->GetSize() == 0;
  799. }
  800. void RegisterArray(asIScriptEngine* engine)
  801. {
  802. engine->RegisterObjectType("Array<class T>", 0, asOBJ_REF | asOBJ_TEMPLATE);
  803. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_TEMPLATE_CALLBACK, "bool f(int&in)", asFUNCTION(ScriptArrayTemplateCallback), asCALL_CDECL);
  804. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_FACTORY, "Array<T>@ f(int& in)", asFUNCTIONPR(ScriptArrayFactory, (asIObjectType*), CScriptArray*), asCALL_CDECL);
  805. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_FACTORY, "Array<T>@ f(int& in, uint)", asFUNCTIONPR(ScriptArrayFactory2, (asIObjectType*, asUINT), CScriptArray*), asCALL_CDECL);
  806. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_FACTORY, "Array<T>@ f(int& in, uint, const T& in)", asFUNCTIONPR(ScriptArrayFactoryDefVal, (asIObjectType*, asUINT, void *), CScriptArray*), asCALL_CDECL);
  807. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_LIST_FACTORY, "Array<T>@ f(int& in, uint)", asFUNCTIONPR(ScriptArrayFactory2, (asIObjectType*, asUINT), CScriptArray*), asCALL_CDECL);
  808. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_ADDREF, "void f()", asMETHOD(CScriptArray,AddRef), asCALL_THISCALL);
  809. engine->RegisterObjectBehaviour("Array<T>", asBEHAVE_RELEASE, "void f()", asMETHOD(CScriptArray,Release), asCALL_THISCALL);
  810. engine->RegisterObjectMethod("Array<T>", "T& opIndex(uint)", asMETHOD(CScriptArray, At), asCALL_THISCALL);
  811. engine->RegisterObjectMethod("Array<T>", "const T& opIndex(uint) const", asMETHOD(CScriptArray, At), asCALL_THISCALL);
  812. engine->RegisterObjectMethod("Array<T>", "Array<T>& opAssign(const Array<T>& in)", asMETHOD(CScriptArray, operator=), asCALL_THISCALL);
  813. engine->RegisterObjectMethod("Array<T>", "void Insert(uint, const T& in)", asMETHOD(CScriptArray, InsertAt), asCALL_THISCALL);
  814. engine->RegisterObjectMethod("Array<T>", "void Erase(uint)", asMETHOD(CScriptArray, RemoveAt), asCALL_THISCALL);
  815. engine->RegisterObjectMethod("Array<T>", "void Push(const T& in)", asMETHOD(CScriptArray, InsertLast), asCALL_THISCALL);
  816. engine->RegisterObjectMethod("Array<T>", "void Pop()", asMETHOD(CScriptArray, RemoveLast), asCALL_THISCALL);
  817. engine->RegisterObjectMethod("Array<T>", "void Resize(uint)", asMETHODPR(CScriptArray, Resize, (asUINT), void), asCALL_THISCALL);
  818. engine->RegisterObjectMethod("Array<T>", "void Clear()", asFUNCTION(ScriptArrayClear), asCALL_CDECL_OBJLAST);
  819. engine->RegisterObjectMethod("Array<T>", "void Sort()", asMETHODPR(CScriptArray, SortAsc, (), void), asCALL_THISCALL);
  820. engine->RegisterObjectMethod("Array<T>", "void Sort(uint, uint)", asMETHODPR(CScriptArray, SortAsc, (asUINT, asUINT), void), asCALL_THISCALL);
  821. engine->RegisterObjectMethod("Array<T>", "void SortReverse()", asMETHODPR(CScriptArray, SortDesc, (), void), asCALL_THISCALL);
  822. engine->RegisterObjectMethod("Array<T>", "void SortReverse(uint, uint)", asMETHODPR(CScriptArray, SortDesc, (asUINT, asUINT), void), asCALL_THISCALL);
  823. engine->RegisterObjectMethod("Array<T>", "void Reverse()", asMETHOD(CScriptArray, Reverse), asCALL_THISCALL);
  824. engine->RegisterObjectMethod("Array<T>", "int Find(const T&in) const", asMETHODPR(CScriptArray, Find, (void*), int), asCALL_THISCALL);
  825. engine->RegisterObjectMethod("Array<T>", "int Find(uint, const T&in) const", asMETHODPR(CScriptArray, Find, (asUINT, void*), int), asCALL_THISCALL);
  826. engine->RegisterObjectMethod("Array<T>", "uint get_length() const", asMETHOD(CScriptArray, GetSize), asCALL_THISCALL);
  827. engine->RegisterObjectMethod("Array<T>", "void set_length(uint)", asMETHODPR(CScriptArray, Resize, (asUINT), void), asCALL_THISCALL);
  828. engine->RegisterObjectMethod("Array<T>", "bool get_empty() const", asFUNCTION(ScriptArrayIsEmpty), asCALL_CDECL_OBJLAST);
  829. engine->RegisterDefaultArrayType("Array<T>");
  830. }
  831. static String StringFactory(asUINT length, const char* s)
  832. {
  833. return String(s, length);
  834. }
  835. static void ConstructString(String* ptr)
  836. {
  837. new(ptr) String();
  838. }
  839. static void ConstructStringCopy(const String& str, String* ptr)
  840. {
  841. new(ptr) String(str);
  842. }
  843. static void DestructString(String* ptr)
  844. {
  845. ptr->~String();
  846. }
  847. static char* StringCharAt(unsigned int i, String& str)
  848. {
  849. if (i >= str.Length())
  850. {
  851. asIScriptContext* context = asGetActiveContext();
  852. if (context)
  853. context->SetException("Index out of bounds");
  854. return 0;
  855. }
  856. return &str[i];
  857. }
  858. static int StringCmp(const String& lhs, const String& rhs)
  859. {
  860. int cmp = 0;
  861. if (lhs < rhs)
  862. cmp = -1;
  863. else if (lhs > rhs)
  864. cmp = 1;
  865. return cmp;
  866. }
  867. void StringResize(unsigned newSize, String& str)
  868. {
  869. unsigned oldSize = str.Length();
  870. str.Resize(newSize);
  871. for (unsigned i = oldSize; i < newSize; ++i)
  872. str[i] = ' ';
  873. }
  874. static void ConstructStringInt(int value, String* ptr)
  875. {
  876. new(ptr) String(value);
  877. }
  878. static void ConstructStringUInt(unsigned value, String* ptr)
  879. {
  880. new(ptr) String(value);
  881. }
  882. static void ConstructStringFloat(float value, String* ptr)
  883. {
  884. new(ptr) String(value);
  885. }
  886. static void ConstructStringBool(bool value, String* ptr)
  887. {
  888. new(ptr) String(value);
  889. }
  890. static String& StringAssignInt(int value, String& str)
  891. {
  892. str = String(value);
  893. return str;
  894. }
  895. static String& StringAddAssignInt(int value, String& str)
  896. {
  897. str += String(value);
  898. return str;
  899. }
  900. static String StringAddInt(int value, const String& str)
  901. {
  902. return str + String(value);
  903. }
  904. static String StringAddIntReverse(int value, const String& str)
  905. {
  906. return String(value) + str;
  907. }
  908. static String& StringAssignUInt(unsigned value, String& str)
  909. {
  910. str = String(value);
  911. return str;
  912. }
  913. static String& StringAddAssignUInt(unsigned value, String& str)
  914. {
  915. str += String(value);
  916. return str;
  917. }
  918. static String StringAddUInt(unsigned value, const String& str)
  919. {
  920. return str + String(value);
  921. }
  922. static String StringAddUIntReverse(unsigned value, const String& str)
  923. {
  924. return String(value) + str;
  925. }
  926. static String& StringAssignFloat(float value, String& str)
  927. {
  928. str = String(value);
  929. return str;
  930. }
  931. static String& StringAddAssignFloat(float value, String& str)
  932. {
  933. str += String(value);
  934. return str;
  935. }
  936. static String StringAddFloat(float value, const String& str)
  937. {
  938. return str + String(value);
  939. }
  940. static String StringAddFloatReverse(float value, const String& str)
  941. {
  942. return String(value) + str;
  943. }
  944. static String& StringAssignBool(bool value, String& str)
  945. {
  946. str = String(value);
  947. return str;
  948. }
  949. static String& StringAddAssignBool(bool value, String& str)
  950. {
  951. str += String(value);
  952. return str;
  953. }
  954. static String StringAddBool(bool value, const String& str)
  955. {
  956. return str + String(value);
  957. }
  958. static String StringAddBoolReverse(bool value, const String& str)
  959. {
  960. return String(value) + str;
  961. }
  962. void RegisterString(asIScriptEngine *engine)
  963. {
  964. engine->RegisterObjectType("String", sizeof(String), asOBJ_VALUE | asOBJ_APP_CLASS_CDA);
  965. engine->RegisterStringFactory("String", asFUNCTION(StringFactory), asCALL_CDECL);
  966. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST);
  967. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f(const String&in)", asFUNCTION(ConstructStringCopy), asCALL_CDECL_OBJLAST);
  968. engine->RegisterObjectBehaviour("String", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST);
  969. engine->RegisterObjectMethod("String", "String& opAssign(const String&in)", asMETHODPR(String, operator =, (const String&), String&), asCALL_THISCALL);
  970. engine->RegisterObjectMethod("String", "String& opAddAssign(const String&in)", asMETHODPR(String, operator +=, (const String&), String&), asCALL_THISCALL);
  971. engine->RegisterObjectMethod("String", "bool opEquals(const String&in) const", asMETHODPR(String, operator ==, (const String&) const, bool), asCALL_THISCALL);
  972. engine->RegisterObjectMethod("String", "int opCmp(const String&in) const", asFUNCTION(StringCmp), asCALL_CDECL_OBJFIRST);
  973. engine->RegisterObjectMethod("String", "String opAdd(const String&in) const", asMETHODPR(String, operator +, (const String&) const, String), asCALL_THISCALL);
  974. engine->RegisterObjectMethod("String", "uint8 &opIndex(uint)", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST);
  975. engine->RegisterObjectMethod("String", "const uint8 &opIndex(uint) const", asFUNCTION(StringCharAt), asCALL_CDECL_OBJLAST);
  976. engine->RegisterObjectMethod("String", "void Replace(uint8, uint8)", asMETHODPR(String, Replace, (char, char), void), asCALL_THISCALL);
  977. engine->RegisterObjectMethod("String", "void Replace(const String&in, const String&in)", asMETHODPR(String, Replace, (const String&, const String&), void), asCALL_THISCALL);
  978. engine->RegisterObjectMethod("String", "String Replaced(uint8, uint8) const", asMETHODPR(String, Replaced, (char, char) const, String), asCALL_THISCALL);
  979. engine->RegisterObjectMethod("String", "String Replaced(const String&in, const String&in) const", asMETHODPR(String, Replaced, (const String&, const String&) const, String), asCALL_THISCALL);
  980. engine->RegisterObjectMethod("String", "void Resize(uint)", asFUNCTION(StringResize), asCALL_CDECL_OBJLAST);
  981. engine->RegisterObjectMethod("String", "int Find(const String&in, uint start = 0) const", asMETHODPR(String, Find, (const String&, unsigned) const, unsigned), asCALL_THISCALL);
  982. engine->RegisterObjectMethod("String", "int Find(uint8, uint start = 0) const", asMETHODPR(String, Find, (char, unsigned) const, unsigned), asCALL_THISCALL);
  983. engine->RegisterObjectMethod("String", "int FindLast(const String&in, uint start = 0xffffffff) const", asMETHODPR(String, FindLast, (const String&, unsigned) const, unsigned), asCALL_THISCALL);
  984. engine->RegisterObjectMethod("String", "int FindLast(uint8, uint start = 0xffffffff) const", asMETHODPR(String, FindLast, (char, unsigned) const, unsigned), asCALL_THISCALL);
  985. engine->RegisterObjectMethod("String", "bool StartsWith(const String&in) const", asMETHOD(String, StartsWith), asCALL_THISCALL);
  986. engine->RegisterObjectMethod("String", "bool EndsWith(const String&in) const", asMETHOD(String, EndsWith), asCALL_THISCALL);
  987. engine->RegisterObjectMethod("String", "String Substring(uint) const", asMETHODPR(String, Substring, (unsigned) const, String), asCALL_THISCALL);
  988. engine->RegisterObjectMethod("String", "String Substring(uint, uint) const", asMETHODPR(String, Substring, (unsigned, unsigned) const, String), asCALL_THISCALL);
  989. engine->RegisterObjectMethod("String", "String ToUpper() const", asMETHOD(String, ToUpper), asCALL_THISCALL);
  990. engine->RegisterObjectMethod("String", "String ToLower() const", asMETHOD(String, ToLower), asCALL_THISCALL);
  991. engine->RegisterObjectMethod("String", "String Trimmed() const", asMETHOD(String, Trimmed), asCALL_THISCALL);
  992. engine->RegisterObjectMethod("String", "uint get_length() const", asMETHOD(String, Length), asCALL_THISCALL);
  993. engine->RegisterObjectMethod("String", "bool get_empty() const", asMETHOD(String, Empty), asCALL_THISCALL);
  994. engine->RegisterObjectMethod("String", "int Compare(const String&in, bool caseSensitive = true) const", asMETHODPR(String, Compare, (const String&, bool) const, int), asCALL_THISCALL);
  995. // Register automatic conversion functions for convenience
  996. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f(int)", asFUNCTION(ConstructStringInt), asCALL_CDECL_OBJLAST);
  997. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f(uint)", asFUNCTION(ConstructStringUInt), asCALL_CDECL_OBJLAST);
  998. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f(float)", asFUNCTION(ConstructStringFloat), asCALL_CDECL_OBJLAST);
  999. engine->RegisterObjectBehaviour("String", asBEHAVE_CONSTRUCT, "void f(bool)", asFUNCTION(ConstructStringBool), asCALL_CDECL_OBJLAST);
  1000. engine->RegisterObjectMethod("String", "String& opAssign(int)", asFUNCTION(StringAssignInt), asCALL_CDECL_OBJLAST);
  1001. engine->RegisterObjectMethod("String", "String& opAddAssign(int)", asFUNCTION(StringAddAssignInt), asCALL_CDECL_OBJLAST);
  1002. engine->RegisterObjectMethod("String", "String opAdd(int) const", asFUNCTION(StringAddInt), asCALL_CDECL_OBJLAST);
  1003. engine->RegisterObjectMethod("String", "String opAdd_r(int) const", asFUNCTION(StringAddIntReverse), asCALL_CDECL_OBJLAST);
  1004. engine->RegisterObjectMethod("String", "String& opAssign(uint)", asFUNCTION(StringAssignUInt), asCALL_CDECL_OBJLAST);
  1005. engine->RegisterObjectMethod("String", "String& opAddAssign(uint)", asFUNCTION(StringAddAssignUInt), asCALL_CDECL_OBJLAST);
  1006. engine->RegisterObjectMethod("String", "String opAdd(uint) const", asFUNCTION(StringAddUInt), asCALL_CDECL_OBJLAST);
  1007. engine->RegisterObjectMethod("String", "String opAdd_r(uint) const", asFUNCTION(StringAddUIntReverse), asCALL_CDECL_OBJLAST);
  1008. engine->RegisterObjectMethod("String", "String& opAssign(float)", asFUNCTION(StringAssignFloat), asCALL_CDECL_OBJLAST);
  1009. engine->RegisterObjectMethod("String", "String& opAddAssign(float)", asFUNCTION(StringAddAssignFloat), asCALL_CDECL_OBJLAST);
  1010. engine->RegisterObjectMethod("String", "String opAdd(float) const", asFUNCTION(StringAddFloat), asCALL_CDECL_OBJLAST);
  1011. engine->RegisterObjectMethod("String", "String opAdd_r(float) const", asFUNCTION(StringAddFloatReverse), asCALL_CDECL_OBJLAST);
  1012. engine->RegisterObjectMethod("String", "String& opAssign(bool)", asFUNCTION(StringAssignBool), asCALL_CDECL_OBJLAST);
  1013. engine->RegisterObjectMethod("String", "String& opAddAssign(bool)", asFUNCTION(StringAddAssignBool), asCALL_CDECL_OBJLAST);
  1014. engine->RegisterObjectMethod("String", "String opAdd(bool) const", asFUNCTION(StringAddBool), asCALL_CDECL_OBJLAST);
  1015. engine->RegisterObjectMethod("String", "String opAdd_r(bool) const", asFUNCTION(StringAddBoolReverse), asCALL_CDECL_OBJLAST);
  1016. }