Script.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Addons.h"
  24. #include "Context.h"
  25. #include "EngineEvents.h"
  26. #include "File.h"
  27. #include "FileSystem.h"
  28. #include "Log.h"
  29. #include "Profiler.h"
  30. #include "Scene.h"
  31. #include "Script.h"
  32. #include "ScriptAPI.h"
  33. #include "ScriptFile.h"
  34. #include "ScriptInstance.h"
  35. #include <angelscript.h>
  36. #include "DebugNew.h"
  37. namespace Urho3D
  38. {
  39. /// %Object property info for scripting API dump.
  40. struct PropertyInfo
  41. {
  42. /// Construct.
  43. PropertyInfo() :
  44. read_(false),
  45. write_(false),
  46. indexed_(false)
  47. {
  48. }
  49. /// Property name.
  50. String name_;
  51. /// Property data type.
  52. String type_;
  53. /// Reading supported flag.
  54. bool read_;
  55. /// Writing supported flag.
  56. bool write_;
  57. /// Indexed flag.
  58. bool indexed_;
  59. };
  60. void ExtractPropertyInfo(const String& functionName, const String& declaration, Vector<PropertyInfo>& propertyInfos)
  61. {
  62. String propertyName = functionName.Substring(4);
  63. PropertyInfo* info = 0;
  64. for (unsigned k = 0; k < propertyInfos.Size(); ++k)
  65. {
  66. if (propertyInfos[k].name_ == propertyName)
  67. {
  68. info = &propertyInfos[k];
  69. break;
  70. }
  71. }
  72. if (!info)
  73. {
  74. propertyInfos.Resize(propertyInfos.Size() + 1);
  75. info = &propertyInfos.Back();
  76. info->name_ = propertyName;
  77. }
  78. if (functionName.Contains("get_"))
  79. {
  80. info->read_ = true;
  81. // Extract type from the return value
  82. Vector<String> parts = declaration.Split(' ');
  83. if (parts.Size())
  84. {
  85. if (parts[0] != "const")
  86. info->type_ = parts[0];
  87. else if (parts.Size() > 1)
  88. info->type_ = parts[1];
  89. }
  90. // If get method has parameters, it is indexed
  91. if (!declaration.Contains("()"))
  92. {
  93. info->indexed_ = true;
  94. info->type_ += "[]";
  95. }
  96. // Sanitate the reference operator away
  97. info->type_.Replace("&", "");
  98. }
  99. if (functionName.Contains("set_"))
  100. {
  101. info->write_ = true;
  102. if (info->type_.Empty())
  103. {
  104. // Extract type from parameters
  105. unsigned begin = declaration.Find(',');
  106. if (begin == String::NPOS)
  107. begin = declaration.Find('(');
  108. else
  109. info->indexed_ = true;
  110. if (begin != String::NPOS)
  111. {
  112. ++begin;
  113. unsigned end = declaration.Find(')');
  114. if (end != String::NPOS)
  115. {
  116. info->type_ = declaration.Substring(begin, end - begin);
  117. // Sanitate const & reference operator away
  118. info->type_.Replace("const ", "");
  119. info->type_.Replace("&in", "");
  120. info->type_.Replace("&", "");
  121. }
  122. }
  123. }
  124. }
  125. }
  126. Script::Script(Context* context) :
  127. Object(context),
  128. scriptEngine_(0),
  129. immediateContext_(0),
  130. scriptNestingLevel_(0)
  131. {
  132. scriptEngine_ = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  133. if (!scriptEngine_)
  134. {
  135. LOGERROR("Could not create AngelScript engine");
  136. return;
  137. }
  138. scriptEngine_->SetUserData(this);
  139. scriptEngine_->SetEngineProperty(asEP_USE_CHARACTER_LITERALS, true);
  140. scriptEngine_->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);
  141. scriptEngine_->SetEngineProperty(asEP_ALLOW_IMPLICIT_HANDLE_TYPES, true);
  142. scriptEngine_->SetEngineProperty(asEP_BUILD_WITHOUT_LINE_CUES, true);
  143. scriptEngine_->SetMessageCallback(asMETHOD(Script, MessageCallback), this, asCALL_THISCALL);
  144. // Create the context for immediate execution
  145. immediateContext_ = scriptEngine_->CreateContext();
  146. immediateContext_->SetExceptionCallback(asMETHOD(Script, ExceptionCallback), this, asCALL_THISCALL);
  147. // Register Script library object factories
  148. RegisterScriptLibrary(context_);
  149. // Register the Array, String & Dictionary API
  150. RegisterArray(scriptEngine_);
  151. RegisterString(scriptEngine_);
  152. RegisterDictionary(scriptEngine_);
  153. // Register the rest of the script API
  154. RegisterMathAPI(scriptEngine_);
  155. RegisterCoreAPI(scriptEngine_);
  156. RegisterIOAPI(scriptEngine_);
  157. RegisterResourceAPI(scriptEngine_);
  158. RegisterSceneAPI(scriptEngine_);
  159. RegisterGraphicsAPI(scriptEngine_);
  160. RegisterInputAPI(scriptEngine_);
  161. RegisterAudioAPI(scriptEngine_);
  162. RegisterUIAPI(scriptEngine_);
  163. RegisterNetworkAPI(scriptEngine_);
  164. RegisterPhysicsAPI(scriptEngine_);
  165. RegisterNavigationAPI(scriptEngine_);
  166. RegisterScriptAPI(scriptEngine_);
  167. RegisterEngineAPI(scriptEngine_);
  168. // Subscribe to console commands
  169. SubscribeToEvent(E_CONSOLECOMMAND, HANDLER(Script, HandleConsoleCommand));
  170. }
  171. Script::~Script()
  172. {
  173. if (immediateContext_)
  174. {
  175. immediateContext_->Release();
  176. immediateContext_ = 0;
  177. }
  178. for (unsigned i = 0 ; i < scriptFileContexts_.Size(); ++i)
  179. scriptFileContexts_[i]->Release();
  180. if (scriptEngine_)
  181. {
  182. scriptEngine_->Release();
  183. scriptEngine_ = 0;
  184. }
  185. }
  186. bool Script::Execute(const String& line)
  187. {
  188. // Note: compiling code each time is slow. Not to be used for performance-critical or repeating activity
  189. PROFILE(ExecuteImmediate);
  190. ClearObjectTypeCache();
  191. String wrappedLine = "void f(){\n" + line + ";\n}";
  192. // If no immediate mode script file set, create a dummy module for compiling the line
  193. asIScriptModule* module = 0;
  194. if (defaultScriptFile_)
  195. module = defaultScriptFile_->GetScriptModule();
  196. if (!module)
  197. module = scriptEngine_->GetModule("ExecuteImmediate", asGM_CREATE_IF_NOT_EXISTS);
  198. if (!module)
  199. return false;
  200. asIScriptFunction *function = 0;
  201. if (module->CompileFunction("", wrappedLine.CString(), -1, 0, &function) < 0)
  202. return false;
  203. if (immediateContext_->Prepare(function) < 0)
  204. {
  205. function->Release();
  206. return false;
  207. }
  208. bool success = immediateContext_->Execute() >= 0;
  209. immediateContext_->Unprepare();
  210. function->Release();
  211. return success;
  212. }
  213. void Script::SetDefaultScriptFile(ScriptFile* file)
  214. {
  215. defaultScriptFile_ = file;
  216. }
  217. void Script::SetDefaultScene(Scene* scene)
  218. {
  219. defaultScene_ = scene;
  220. }
  221. void Script::DumpAPI(DumpMode mode)
  222. {
  223. // Does not use LOGRAW macro here to ensure the messages are always dumped regardless of ENABLE_LOGGING compiler directive and of Log subsystem availability
  224. if (mode == DOXYGEN)
  225. Log::WriteRaw("namespace Urho3D\n{\n\n/**\n\\page ScriptAPI Scripting API\n\n");
  226. else if (mode == C_HEADER)
  227. Log::WriteRaw("// Script API header intended to be 'force included' in IDE for AngelScript content assist / code completion\n\n"
  228. "#define int8 signed char\n"
  229. "#define int16 signed short\n"
  230. "#define int64 long\n"
  231. "#define uint8 unsigned char\n"
  232. "#define uint16 unsigned short\n"
  233. "#define uint64 unsigned long\n"
  234. "#define null 0\n");
  235. if (mode == DOXYGEN)
  236. Log::WriteRaw("\\section ScriptAPI_Enums Enumerations\n");
  237. else if (mode == C_HEADER)
  238. Log::WriteRaw("\n// Enumerations\n");
  239. unsigned enums = scriptEngine_->GetEnumCount();
  240. for (unsigned i = 0; i < enums; ++i)
  241. {
  242. int typeId;
  243. if (mode == DOXYGEN)
  244. Log::WriteRaw("\n### " + String(scriptEngine_->GetEnumByIndex(i, &typeId)) + "\n\n");
  245. else if (mode == C_HEADER)
  246. Log::WriteRaw("\nenum " + String(scriptEngine_->GetEnumByIndex(i, &typeId)) + "\n{\n");
  247. for (unsigned j = 0; j < (unsigned)scriptEngine_->GetEnumValueCount(typeId); ++j)
  248. {
  249. int value = 0;
  250. const char* name = scriptEngine_->GetEnumValueByIndex(typeId, j, &value);
  251. OutputAPIRow(mode, String(name), false, ",");
  252. }
  253. if (mode == DOXYGEN)
  254. Log::WriteRaw("\n");
  255. else if (mode == C_HEADER)
  256. Log::WriteRaw("};\n");
  257. }
  258. if (mode == DOXYGEN)
  259. Log::WriteRaw("\\section ScriptAPI_Classes Classes\n");
  260. else if (mode == C_HEADER)
  261. Log::WriteRaw("\n// Classes\n");
  262. unsigned types = scriptEngine_->GetObjectTypeCount();
  263. for (unsigned i = 0; i < types; ++i)
  264. {
  265. asIObjectType* type = scriptEngine_->GetObjectTypeByIndex(i);
  266. if (type)
  267. {
  268. String typeName(type->GetName());
  269. Vector<String> methodDeclarations;
  270. Vector<PropertyInfo> propertyInfos;
  271. if (mode == DOXYGEN)
  272. Log::WriteRaw("\n### " + typeName + "\n");
  273. else if (mode == C_HEADER)
  274. {
  275. ///\todo Find a cleaner way to do this instead of hardcoding
  276. if (typeName == "Array")
  277. Log::WriteRaw("\ntemplate <class T> class " + typeName + "\n{\n");
  278. else
  279. Log::WriteRaw("\nclass " + typeName + "\n{\n");
  280. }
  281. unsigned methods = type->GetMethodCount();
  282. for (unsigned j = 0; j < methods; ++j)
  283. {
  284. asIScriptFunction* method = type->GetMethodByIndex(j);
  285. String methodName(method->GetName());
  286. String declaration(method->GetDeclaration());
  287. if (methodName.Contains("get_") || methodName.Contains("set_"))
  288. ExtractPropertyInfo(methodName, declaration, propertyInfos);
  289. else
  290. {
  291. // Sanitate the method name. \todo For now, skip the operators
  292. if (!declaration.Contains("::op"))
  293. {
  294. String prefix(typeName + "::");
  295. declaration.Replace(prefix, "");
  296. methodDeclarations.Push(declaration);
  297. }
  298. }
  299. }
  300. // Assume that the same property is never both an accessor property, and a direct one
  301. unsigned properties = type->GetPropertyCount();
  302. for (unsigned j = 0; j < properties; ++j)
  303. {
  304. const char* propertyName;
  305. const char* propertyDeclaration;
  306. int typeId;
  307. type->GetProperty(j, &propertyName, &typeId);
  308. propertyDeclaration = scriptEngine_->GetTypeDeclaration(typeId);
  309. PropertyInfo newInfo;
  310. newInfo.name_ = String(propertyName);
  311. newInfo.type_ = String(propertyDeclaration);
  312. newInfo.read_ = newInfo.write_ = true;
  313. propertyInfos.Push(newInfo);
  314. }
  315. if (!methodDeclarations.Empty())
  316. {
  317. if (mode == DOXYGEN)
  318. Log::WriteRaw("\nMethods:\n\n");
  319. else if (mode == C_HEADER)
  320. Log::WriteRaw("// Methods:\n");
  321. for (unsigned j = 0; j < methodDeclarations.Size(); ++j)
  322. OutputAPIRow(mode, methodDeclarations[j]);
  323. }
  324. if (!propertyInfos.Empty())
  325. {
  326. if (mode == DOXYGEN)
  327. Log::WriteRaw("\nProperties:\n\n");
  328. else if (mode == C_HEADER)
  329. Log::WriteRaw("\n// Properties:\n");
  330. for (unsigned j = 0; j < propertyInfos.Size(); ++j)
  331. {
  332. String remark;
  333. String cppdoc;
  334. if (!propertyInfos[j].write_)
  335. remark = " (readonly)";
  336. else if (!propertyInfos[j].read_)
  337. remark = " (writeonly)";
  338. if (mode == C_HEADER && !remark.Empty())
  339. {
  340. cppdoc = "/*" + remark + " */\n";
  341. remark.Clear();
  342. }
  343. OutputAPIRow(mode, cppdoc + propertyInfos[j].type_ + " " + propertyInfos[j].name_ + remark);
  344. }
  345. }
  346. if (mode == DOXYGEN)
  347. Log::WriteRaw("\n");
  348. else if (mode == C_HEADER)
  349. Log::WriteRaw("};\n");
  350. }
  351. }
  352. Vector<PropertyInfo> globalPropertyInfos;
  353. Vector<String> globalFunctions;
  354. unsigned functions = scriptEngine_->GetGlobalFunctionCount();
  355. for (unsigned i = 0; i < functions; ++i)
  356. {
  357. asIScriptFunction* function = scriptEngine_->GetGlobalFunctionByIndex(i);
  358. String functionName(function->GetName());
  359. String declaration(function->GetDeclaration());
  360. if (functionName.Contains("set_") || functionName.Contains("get_"))
  361. ExtractPropertyInfo(functionName, declaration, globalPropertyInfos);
  362. else
  363. globalFunctions.Push(declaration);
  364. }
  365. if (mode == DOXYGEN)
  366. Log::WriteRaw("\\section ScriptAPI_GlobalFunctions Global functions\n");
  367. else if (mode == C_HEADER)
  368. Log::WriteRaw("\n// Global functions\n");
  369. for (unsigned i = 0; i < globalFunctions.Size(); ++i)
  370. OutputAPIRow(mode, globalFunctions[i]);
  371. if (mode == DOXYGEN)
  372. Log::WriteRaw("\\section ScriptAPI_GlobalProperties Global properties\n");
  373. else if (mode == C_HEADER)
  374. Log::WriteRaw("\n// Global properties\n");
  375. for (unsigned i = 0; i < globalPropertyInfos.Size(); ++i)
  376. OutputAPIRow(mode, globalPropertyInfos[i].type_ + " " + globalPropertyInfos[i].name_, true);
  377. if (mode == DOXYGEN)
  378. Log::WriteRaw("\\section ScriptAPI_GlobalConstants Global constants\n");
  379. else if (mode == C_HEADER)
  380. Log::WriteRaw("\n// Global constants\n");
  381. unsigned properties = scriptEngine_->GetGlobalPropertyCount();
  382. for (unsigned i = 0; i < properties; ++i)
  383. {
  384. const char* propertyName;
  385. const char* propertyDeclaration;
  386. int typeId;
  387. scriptEngine_->GetGlobalPropertyByIndex(i, &propertyName, 0, &typeId);
  388. propertyDeclaration = scriptEngine_->GetTypeDeclaration(typeId);
  389. String type(propertyDeclaration);
  390. OutputAPIRow(mode, type + " " + String(propertyName), true);
  391. }
  392. // Dump event descriptions in Doxygen mode. This means going through the header files, as the information is not
  393. // available otherwise
  394. if (mode == DOXYGEN)
  395. {
  396. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  397. Vector<String> headerFiles;
  398. String path = fileSystem->GetProgramDir();
  399. path.Replace("/Bin", "/Source/Engine");
  400. fileSystem->ScanDir(headerFiles, path, "*.h", SCAN_FILES, true);
  401. if (!headerFiles.Empty())
  402. {
  403. Log::WriteRaw("\n\\page EventList Event list\n");
  404. Sort(headerFiles.Begin(), headerFiles.End());
  405. }
  406. for (unsigned i = 0; i < headerFiles.Size(); ++i)
  407. {
  408. if (headerFiles[i].EndsWith("Events.h"))
  409. {
  410. SharedPtr<File> file(new File(context_, path + headerFiles[i], FILE_READ));
  411. if (!file->IsOpen())
  412. continue;
  413. unsigned start = headerFiles[i].Find('/') + 1;
  414. unsigned end = headerFiles[i].Find("Events.h");
  415. Log::WriteRaw("\n## %" + headerFiles[i].Substring(start, end - start) + " events\n");
  416. while (!file->IsEof())
  417. {
  418. String line = file->ReadLine();
  419. if (line.StartsWith("EVENT"))
  420. {
  421. Vector<String> parts = line.Split(',');
  422. if (parts.Size() == 2)
  423. Log::WriteRaw("\n### " + parts[1].Substring(0, parts[1].Length() - 1).Trimmed() + "\n");
  424. }
  425. if (line.Contains("PARAM"))
  426. {
  427. Vector<String> parts = line.Split(',');
  428. if (parts.Size() == 2)
  429. {
  430. String paramName = parts[1].Substring(0, parts[1].Find(')')).Trimmed();
  431. String paramType = parts[1].Substring(parts[1].Find("// ") + 3);
  432. if (!paramName.Empty() && !paramType.Empty())
  433. Log::WriteRaw("- %" + paramName + " : " + paramType + "\n");
  434. }
  435. }
  436. }
  437. }
  438. }
  439. if (!headerFiles.Empty())
  440. Log::WriteRaw("\n");
  441. }
  442. if (mode == DOXYGEN)
  443. Log::WriteRaw("*/\n\n}\n");
  444. }
  445. void Script::MessageCallback(const asSMessageInfo* msg)
  446. {
  447. String message;
  448. message.AppendWithFormat("%s:%d,%d %s", msg->section, msg->row, msg->col, msg->message);
  449. switch (msg->type)
  450. {
  451. case asMSGTYPE_ERROR:
  452. LOGERROR(message);
  453. break;
  454. case asMSGTYPE_WARNING:
  455. LOGWARNING(message);
  456. break;
  457. default:
  458. LOGINFO(message);
  459. break;
  460. }
  461. }
  462. void Script::ExceptionCallback(asIScriptContext* context)
  463. {
  464. String message;
  465. message.AppendWithFormat("- Exception '%s' in '%s'\n%s", context->GetExceptionString(), context->GetExceptionFunction()->GetDeclaration(), GetCallStack(context).CString());
  466. asSMessageInfo msg;
  467. msg.row = context->GetExceptionLineNumber(&msg.col, &msg.section);
  468. msg.type = asMSGTYPE_ERROR;
  469. msg.message = message.CString();
  470. MessageCallback(&msg);
  471. }
  472. String Script::GetCallStack(asIScriptContext* context)
  473. {
  474. String str("AngelScript callstack:\n");
  475. // Append the call stack
  476. for (asUINT i = 0; i < context->GetCallstackSize(); i++)
  477. {
  478. asIScriptFunction* func;
  479. const char* scriptSection;
  480. int line, column;
  481. func = context->GetFunction(i);
  482. line = context->GetLineNumber(i, &column, &scriptSection);
  483. str.AppendWithFormat("\t%s:%s:%d,%d\n", scriptSection, func->GetDeclaration(), line, column);
  484. }
  485. return str;
  486. }
  487. ScriptFile* Script::GetDefaultScriptFile() const
  488. {
  489. return defaultScriptFile_;
  490. }
  491. Scene* Script::GetDefaultScene() const
  492. {
  493. return defaultScene_;
  494. }
  495. void Script::ClearObjectTypeCache()
  496. {
  497. objectTypes_.Clear();
  498. }
  499. asIObjectType* Script::GetObjectType(const char* declaration)
  500. {
  501. HashMap<const char*, asIObjectType*>::ConstIterator i = objectTypes_.Find(declaration);
  502. if (i != objectTypes_.End())
  503. return i->second_;
  504. asIObjectType* type = scriptEngine_->GetObjectTypeById(scriptEngine_->GetTypeIdByDecl(declaration));
  505. objectTypes_[declaration] = type;
  506. return type;
  507. }
  508. asIScriptContext* Script::GetScriptFileContext()
  509. {
  510. while (scriptNestingLevel_ >= scriptFileContexts_.Size())
  511. {
  512. asIScriptContext* newContext = scriptEngine_->CreateContext();
  513. newContext->SetExceptionCallback(asMETHOD(Script, ExceptionCallback), this, asCALL_THISCALL);
  514. scriptFileContexts_.Push(newContext);
  515. }
  516. return scriptFileContexts_[scriptNestingLevel_];
  517. }
  518. void Script::OutputAPIRow(DumpMode mode, const String& row, bool removeReference, String separator)
  519. {
  520. String out(row);
  521. ///\todo We need C++11 <regex> in String class to handle REGEX whole-word replacement correctly. Can't do that since we still support VS2008.
  522. // Commenting out to temporary fix property name like 'doubleClickInterval' from being wrongly replaced.
  523. // Fortunately, there is no occurence of type 'double' in the API at the moment.
  524. //out.Replace("double", "float"); // s/\bdouble\b/float/g
  525. out.Replace("&in", "&");
  526. out.Replace("&out", "&");
  527. if (removeReference)
  528. out.Replace("&", "");
  529. if (mode == DOXYGEN)
  530. Log::WriteRaw("- " + out + "\n");
  531. else if (mode == C_HEADER)
  532. {
  533. out.Replace("@", "");
  534. out.Replace("?&", "void*");
  535. // s/(\w+)\[\]/Array<\1>/g
  536. unsigned posBegin = String::NPOS;
  537. while (1) // Loop to cater for array of array of T
  538. {
  539. unsigned posEnd = out.Find("[]");
  540. if (posEnd == String::NPOS)
  541. break;
  542. if (posBegin > posEnd)
  543. posBegin = posEnd - 1;
  544. while (posBegin < posEnd && isalnum(out[posBegin]))
  545. --posBegin;
  546. ++posBegin;
  547. out.Replace(posBegin, posEnd - posBegin + 2, "Array<" + out.Substring(posBegin, posEnd - posBegin) + ">");
  548. }
  549. Log::WriteRaw(out + separator + "\n");
  550. }
  551. }
  552. void Script::HandleConsoleCommand(StringHash eventType, VariantMap& eventData)
  553. {
  554. using namespace ConsoleCommand;
  555. Execute(eventData[P_COMMAND].GetString());
  556. }
  557. void RegisterScriptLibrary(Context* context)
  558. {
  559. ScriptFile::RegisterObject(context);
  560. ScriptInstance::RegisterObject(context);
  561. }
  562. }