CSFunctionWriter.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  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 <Atomic/IO/FileSystem.h>
  23. #include "../JSBind.h"
  24. #include "../JSBModule.h"
  25. #include "../JSBPackage.h"
  26. #include "../JSBEnum.h"
  27. #include "../JSBClass.h"
  28. #include "../JSBFunction.h"
  29. #include "CSTypeHelper.h"
  30. #include "CSFunctionWriter.h"
  31. /*
  32. *
  33. C# getters/setters
  34. local instance storage so we're not constantly creating managed Vector3, etc
  35. Vector2/Vector3/BoundingBox, etc C# structs so assign by value
  36. Object lifetime
  37. C# enum of module types for type info?
  38. C# version of push class instance?
  39. new instance from C# needs constructor
  40. wrapping does not, wrapping doesn't use constructors at all (JS needs this for prototype)
  41. Store GCHandle to keep an object alive (Component, UI) C# side?
  42. typedef const void* ClassID;
  43. which changed based on address, so need register at startup
  44. so at package startup time, need to setup mapping between
  45. IntPtr and C# class, we also need to be able to new a class
  46. instance with existing native or create a native when new'ing from C#
  47. IntPtr to RefCounted native side is the "ID", like JSHeapPtr
  48. Lifetime:
  49. // you cannot derive from native engine classes, other than script components
  50. a C# instance can be new'd, handed to native, stored in native, the C# side could be GC'd
  51. future access to this instance would be a new instance
  52. */
  53. /*
  54. // struct marshal Vector2, Vector3, BoundingBox, etc
  55. // RefCounted*
  56. // primitive bool, int, uint, float, double
  57. // String
  58. RefCounted* csb_Node_Constructor()
  59. {
  60. return new Node(NETCore::GetContext());
  61. }
  62. void csb_Node_GetPosition(Node* self, Vector3* out)
  63. {
  64. *out = self->GetPosition();
  65. }
  66. void csb_Node_SetPosition(Node* self, Vector3*__arg0)
  67. {
  68. self->SetPosition(*__arg0);
  69. }
  70. void csb_Node_SetPosition(Node* self, Vector3*__arg0)
  71. {
  72. self->SetPosition(*__arg0);
  73. }
  74. bool csb_Audio_Play(Audio* self)
  75. {
  76. bool retValue = self->Play();
  77. return retValue;
  78. }
  79. const RefCounted* csb_Node_GetParent(Node* self)
  80. {
  81. const RefCounted* retValue = self->GetParent();
  82. return RefCounted;
  83. }
  84. RefCounted* csb_ObjectAnimation_Constructor()
  85. {
  86. return new ObjectAnimation(NETCore::GetContext());
  87. }
  88. */
  89. namespace ToolCore
  90. {
  91. CSFunctionWriter::CSFunctionWriter(JSBFunction *function) : JSBFunctionWriter(function)
  92. {
  93. }
  94. void CSFunctionWriter::WriteNativeParameterMarshal(String& source)
  95. {
  96. }
  97. void CSFunctionWriter::WriteNativeConstructor(String& source)
  98. {
  99. }
  100. void CSFunctionWriter::GenNativeCallParameters(String& sig)
  101. {
  102. JSBClass* klass = function_->GetClass();
  103. Vector<JSBFunctionType*>& parameters = function_->GetParameters();
  104. Vector<String> args;
  105. if (parameters.Size())
  106. {
  107. for (unsigned int i = 0; i < parameters.Size(); i++)
  108. {
  109. JSBFunctionType* ptype = parameters.At(i);
  110. // ignore "Context" parameters
  111. if (ptype->type_->asClassType())
  112. {
  113. JSBClassType* classType = ptype->type_->asClassType();
  114. JSBClass* klass = classType->class_;
  115. if (klass->GetName() == "Context")
  116. {
  117. continue;
  118. }
  119. if (klass->IsNumberArray())
  120. args.Push(ToString("*%s", ptype->name_.CString()));
  121. else
  122. args.Push(ToString("%s", ptype->name_.CString()));
  123. }
  124. else
  125. {
  126. args.Push(ToString("%s", ptype->name_.CString()));
  127. }
  128. }
  129. }
  130. sig.Join(args, ", ");
  131. }
  132. void CSFunctionWriter::WriteNativeFunction(String& source)
  133. {
  134. JSBClass* klass = function_->GetClass();
  135. JSBPackage* package = klass->GetPackage();
  136. String fname = function_->IsConstructor() ? "Constructor" : function_->GetName();
  137. String returnType;
  138. String functionSig = CSTypeHelper::GetNativeFunctionSignature(function_, returnType);
  139. String line;
  140. line = ToString("ATOMIC_EXPORT_API %s %s\n",
  141. returnType.CString(), functionSig.CString());
  142. source += IndentLine(line);
  143. source += IndentLine("{\n");
  144. Indent();
  145. source += "\n";
  146. bool returnValue = false;
  147. bool sharedPtrReturn = false;
  148. String returnStatement;
  149. if (returnType == "const char*")
  150. {
  151. returnValue = true;
  152. source += IndentLine("static String returnValue;\n");
  153. returnStatement = "returnValue = ";
  154. }
  155. else if (function_->GetReturnClass() && function_->GetReturnClass()->IsNumberArray())
  156. {
  157. returnStatement = "*returnValue = ";
  158. }
  159. else if (function_->GetReturnClass() && function_->GetReturnType()->isSharedPtr_)
  160. {
  161. returnStatement = ToString("SharedPtr<%s> returnValue = ", function_->GetReturnClass()->GetNativeName().CString());
  162. sharedPtrReturn = true;
  163. }
  164. else
  165. {
  166. if (returnType != "void")
  167. {
  168. returnStatement = "return ";
  169. }
  170. }
  171. String callSig;
  172. GenNativeCallParameters(callSig);
  173. if (!function_->isConstructor_)
  174. line = ToString("%sself->%s(%s);\n", returnStatement.CString(), function_->GetName().CString(), callSig.CString());
  175. else
  176. {
  177. if (klass->IsAbstract())
  178. {
  179. line = "return 0; // Abstract Class\n";
  180. }
  181. else if (klass->IsObject())
  182. {
  183. if (callSig.Length())
  184. line = ToString("return new %s(NETCore::GetContext(), %s);\n", klass->GetNativeName().CString(), callSig.CString());
  185. else
  186. line = ToString("return new %s(NETCore::GetContext());\n", klass->GetNativeName().CString());
  187. }
  188. else
  189. {
  190. line = ToString("return new %s(%s);\n", klass->GetNativeName().CString(), callSig.CString());
  191. }
  192. }
  193. source += IndentLine(line);
  194. if (sharedPtrReturn)
  195. {
  196. source += IndentLine("returnValue->AddRef();\n");
  197. source += IndentLine("return returnValue;\n");
  198. }
  199. else if (returnType == "const char*")
  200. {
  201. source += IndentLine("return returnValue.CString();\n");
  202. }
  203. Dedent();
  204. source += IndentLine("}\n");
  205. source += "\n";
  206. }
  207. void CSFunctionWriter::GenerateNativeSource(String& sourceOut)
  208. {
  209. String source = "";
  210. WriteNativeFunction(source);
  211. sourceOut += source;
  212. }
  213. // MANAGED----------------------------------------------------------------------------------------
  214. void CSFunctionWriter::WriteDefaultStructParameters(String& source)
  215. {
  216. for (unsigned i = 0; i < defaultStructParameters_.Size(); i++)
  217. {
  218. const DefaultStructParameter& dparm = defaultStructParameters_[i];
  219. String line = ToString("if (default(%s).Equals(%s)) %s = %s;\n",
  220. dparm.type.CString(), dparm.parameterName.CString(), dparm.parameterName.CString(),
  221. dparm.assignment.CString());
  222. source += IndentLine(line);
  223. }
  224. }
  225. void CSFunctionWriter::WriteManagedPInvokeFunctionSignature(String& source)
  226. {
  227. source += "\n";
  228. // CoreCLR has pinvoke security demand code commented out, so we do not (currently) need this optimization:
  229. // https://github.com/dotnet/coreclr/issues/1605
  230. // line = "[SuppressUnmanagedCodeSecurity]\n";
  231. // source += IndentLine(line);
  232. String line = "[DllImport (Constants.LIBNAME, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]\n";
  233. source += IndentLine(line);
  234. JSBClass* klass = function_->GetClass();
  235. JSBPackage* package = klass->GetPackage();
  236. String returnType = CSTypeHelper::GetPInvokeTypeString(function_->GetReturnType());
  237. if (returnType == "string")
  238. returnType = "IntPtr";
  239. if (function_->IsConstructor())
  240. returnType = "IntPtr";
  241. Vector<JSBFunctionType*>& parameters = function_->GetParameters();
  242. Vector<String> args;
  243. if (!function_->IsConstructor())
  244. {
  245. args.Push("IntPtr self");
  246. }
  247. if (parameters.Size())
  248. {
  249. for (unsigned int i = 0; i < parameters.Size(); i++)
  250. {
  251. JSBFunctionType* ptype = parameters.At(i);
  252. String name = ptype->name_;
  253. if (name == "object")
  254. name = "_object";
  255. else if (name == "readonly")
  256. name = "readOnly";
  257. else if (name == "params")
  258. name = "parameters";
  259. // ignore "Context" parameters
  260. if (ptype->type_->asClassType())
  261. {
  262. JSBClassType* classType = ptype->type_->asClassType();
  263. JSBClass* klass = classType->class_;
  264. if (klass->GetName() == "Context")
  265. {
  266. continue;
  267. }
  268. if (klass->IsNumberArray())
  269. {
  270. args.Push("ref " + klass->GetName() + " " + name);
  271. }
  272. else
  273. {
  274. args.Push("IntPtr " + name);
  275. }
  276. }
  277. else
  278. {
  279. args.Push(CSTypeHelper::GetPInvokeTypeString(ptype) + " " + name);
  280. }
  281. }
  282. }
  283. if (function_->GetReturnClass())
  284. {
  285. JSBClass* retClass = function_->GetReturnClass();
  286. if (retClass->IsNumberArray())
  287. {
  288. args.Push("ref " + retClass->GetName() + " retValue");
  289. }
  290. }
  291. String pstring;
  292. pstring.Join(args, ", ");
  293. String fname = function_->IsConstructor() ? "Constructor" : function_->GetName();
  294. line = ToString("private static extern %s csb_%s_%s_%s(%s);\n",
  295. returnType.CString(), package->GetName().CString(), klass->GetName().CString(),
  296. fname.CString(), pstring.CString());
  297. source += IndentLine(line);
  298. source += "\n";
  299. }
  300. void CSFunctionWriter::GenManagedFunctionParameters(String& sig)
  301. {
  302. // generate args
  303. Vector<JSBFunctionType*>& parameters = function_->GetParameters();
  304. if (parameters.Size())
  305. {
  306. for (unsigned int i = 0; i < parameters.Size(); i++)
  307. {
  308. JSBFunctionType* ptype = parameters.At(i);
  309. // ignore "Context" parameters
  310. if (ptype->type_->asClassType())
  311. {
  312. JSBClassType* classType = ptype->type_->asClassType();
  313. JSBClass* klass = classType->class_;
  314. if (klass->GetName() == "Context")
  315. {
  316. continue;
  317. }
  318. }
  319. sig += CSTypeHelper::GetManagedTypeString(ptype);
  320. String init = ptype->initializer_;
  321. if (init.Length())
  322. {
  323. init = MapDefaultParameter(ptype);
  324. if (init.Length())
  325. sig += " = " + init;
  326. }
  327. if (i + 1 != parameters.Size())
  328. sig += ", ";
  329. }
  330. }
  331. }
  332. void CSFunctionWriter::WriteManagedConstructor(String& source)
  333. {
  334. JSBClass* klass = function_->GetClass();
  335. JSBPackage* package = klass->GetPackage();
  336. if (klass->GetName() == "RefCounted")
  337. return;
  338. // wrapping constructor
  339. String line;
  340. line = ToString("public %s (IntPtr native) : base (native)\n", klass->GetName().CString());
  341. source += IndentLine(line);
  342. source += IndentLine("{\n");
  343. source += IndentLine("}\n\n");
  344. String sig;
  345. GenManagedFunctionParameters(sig);
  346. line = ToString("public %s (%s)\n", klass->GetName().CString(), sig.CString());
  347. source += IndentLine(line);
  348. source += IndentLine("{\n");
  349. Indent();
  350. WriteDefaultStructParameters(source);
  351. line = ToString("if (typeof(%s) == this.GetType()", klass->GetName().CString());
  352. line += ToString(" || (this.GetType().BaseType == typeof(%s) && !NativeCore.GetNativeType(this.GetType())))\n", klass->GetName().CString());
  353. source += IndentLine(line);
  354. source += IndentLine("{\n");
  355. Indent();
  356. String callSig;
  357. GenPInvokeCallParameters(callSig);
  358. line = ToString("nativeInstance = NativeCore.RegisterNative (csb_%s_%s_Constructor(%s), this);\n",
  359. package->GetName().CString(), klass->GetName().CString(), callSig.CString());
  360. source += IndentLine(line);
  361. Dedent();
  362. source += IndentLine("}\n");
  363. Dedent();
  364. source += IndentLine("}\n");
  365. }
  366. void CSFunctionWriter::GenPInvokeCallParameters(String& sig)
  367. {
  368. // generate args
  369. Vector<JSBFunctionType*>& parameters = function_->GetParameters();
  370. if (parameters.Size())
  371. {
  372. for (unsigned int i = 0; i < parameters.Size(); i++)
  373. {
  374. JSBFunctionType* ptype = parameters.At(i);
  375. // ignore "Context" parameters
  376. if (ptype->type_->asClassType())
  377. {
  378. JSBClassType* classType = ptype->type_->asClassType();
  379. JSBClass* klass = classType->class_;
  380. if (klass->GetName() == "Context")
  381. {
  382. continue;
  383. }
  384. }
  385. String name = ptype->name_;
  386. if (name == "object")
  387. name = "_object";
  388. else if (name == "readonly")
  389. name = "readOnly";
  390. else if (name == "params")
  391. name = "parameters";
  392. if (ptype->type_->asClassType())
  393. {
  394. JSBClass* pclass = ptype->type_->asClassType()->class_;
  395. if (pclass->IsNumberArray())
  396. {
  397. sig += "ref " + name;
  398. }
  399. else
  400. {
  401. sig += name + " == null ? IntPtr.Zero : " + name + ".nativeInstance";
  402. }
  403. }
  404. else
  405. {
  406. sig += name;
  407. }
  408. if (i + 1 != parameters.Size())
  409. sig += ", ";
  410. }
  411. }
  412. // data marshaller
  413. if (function_->GetReturnType() && !CSTypeHelper::IsSimpleReturn(function_->GetReturnType()))
  414. {
  415. if (function_->GetReturnClass()->IsNumberArray())
  416. {
  417. if (sig.Length())
  418. sig += ", ";
  419. JSBClass* klass = function_->GetClass();
  420. sig += ToString("ref %s%sReturnValue", klass->GetName().CString(), function_->GetName().CString());
  421. }
  422. }
  423. }
  424. void CSFunctionWriter::WriteManagedFunction(String& source)
  425. {
  426. JSBClass* klass = function_->GetClass();
  427. JSBPackage* package = klass->GetPackage();
  428. String sig;
  429. String returnType = CSTypeHelper::GetManagedTypeString(function_->GetReturnType());
  430. GenManagedFunctionParameters(sig);
  431. String line = "public ";
  432. bool marked = false;
  433. JSBClass* baseClass = klass->GetBaseClass();
  434. if (baseClass)
  435. {
  436. JSBFunction* override = baseClass->MatchFunction(function_, true);
  437. if (override)
  438. {
  439. marked = true;
  440. if (override->IsVirtual())
  441. line += "override ";
  442. else
  443. line += "new ";
  444. }
  445. }
  446. if (!marked && function_->IsVirtual())
  447. line += "virtual ";
  448. line += ToString("%s %s (%s)\n", returnType.CString(), function_->GetName().CString(), sig.CString());
  449. source += IndentLine(line);
  450. source += IndentLine("{\n");
  451. Indent();
  452. WriteDefaultStructParameters(source);
  453. line.Clear();
  454. if (function_->GetReturnType())
  455. {
  456. if (function_->GetReturnType()->type_->asStringType() || function_->GetReturnType()->type_->asStringHashType())
  457. {
  458. line += "return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(";
  459. }
  460. else if (CSTypeHelper::IsSimpleReturn(function_->GetReturnType()))
  461. line += "return ";
  462. else
  463. {
  464. if (function_->GetReturnClass())
  465. {
  466. if (!function_->GetReturnClass()->IsNumberArray())
  467. line += "IntPtr retNativeInstance = ";
  468. }
  469. }
  470. }
  471. String callSig;
  472. GenPInvokeCallParameters(callSig);
  473. line += ToString("csb_%s_%s_%s(nativeInstance",
  474. package->GetName().CString(), klass->GetName().CString(), function_->GetName().CString());
  475. if (callSig.Length())
  476. {
  477. line += ", " + callSig;
  478. }
  479. if (function_->GetReturnType())
  480. {
  481. if (function_->GetReturnType()->type_->asStringType() || function_->GetReturnType()->type_->asStringHashType())
  482. line += ")";
  483. }
  484. line += ");\n";
  485. source += IndentLine(line);
  486. if (function_->GetReturnType() && !CSTypeHelper::IsSimpleReturn(function_->GetReturnType()))
  487. {
  488. if (function_->GetReturnType()->type_->asClassType())
  489. {
  490. JSBClass* retClass = function_->GetReturnClass();
  491. JSBClass* klass = function_->GetClass();
  492. if (retClass->IsNumberArray())
  493. {
  494. line = ToString("return %s%sReturnValue;", klass->GetName().CString(), function_->GetName().CString());
  495. }
  496. else
  497. {
  498. line = ToString("return retNativeInstance == IntPtr.Zero ? null : NativeCore.WrapNative<%s> (retNativeInstance);", retClass->GetName().CString());
  499. }
  500. source += IndentLine(line);
  501. }
  502. }
  503. source+= "\n";
  504. Dedent();
  505. source += IndentLine("}\n");
  506. }
  507. void CSFunctionWriter::GenerateManagedSource(String& sourceOut)
  508. {
  509. String source = "";
  510. Indent();
  511. Indent();
  512. Indent();
  513. if (function_->GetDocString().Length())
  514. {
  515. // monodocer -assembly:NETCore.dll -path:en -pretty
  516. // mdoc export-html -o htmldocs en
  517. source += IndentLine("/// <summary>\n");
  518. source += IndentLine("/// " + function_->GetDocString() + "\n");
  519. source += IndentLine("/// </summary>\n");
  520. }
  521. if (function_->IsConstructor())
  522. WriteManagedConstructor(source);
  523. else
  524. WriteManagedFunction(source);
  525. WriteManagedPInvokeFunctionSignature(source);
  526. // data marshaller
  527. if (function_->GetReturnType() && !CSTypeHelper::IsSimpleReturn(function_->GetReturnType()))
  528. {
  529. if (function_->GetReturnClass())
  530. {
  531. JSBClass* retClass = function_->GetReturnClass();
  532. if (retClass->IsNumberArray())
  533. {
  534. JSBClass* klass = function_->GetClass();
  535. String managedType = CSTypeHelper::GetManagedTypeString(function_->GetReturnType());
  536. String marshal = "private " + managedType + " ";
  537. marshal += ToString("%s%sReturnValue = new %s();\n", klass->GetName().CString(), function_->GetName().CString(), managedType.CString());
  538. sourceOut += IndentLine(marshal);
  539. }
  540. }
  541. }
  542. Dedent();
  543. Dedent();
  544. Dedent();
  545. sourceOut += source;
  546. }
  547. void CSFunctionWriter::GenerateSource(String& sourceOut)
  548. {
  549. }
  550. String CSFunctionWriter::MapDefaultParameter(JSBFunctionType* parameter)
  551. {
  552. String init = parameter->initializer_;
  553. if (!init.Length())
  554. return init;
  555. if (parameter->type_->asClassType())
  556. {
  557. if (init == "0")
  558. return "null";
  559. }
  560. if (parameter->type_->asEnumType())
  561. {
  562. return parameter->type_->asEnumType()->enum_->GetName() + "." + init;
  563. }
  564. if (function_->class_->GetPackage()->ContainsConstant(init))
  565. return "Constants." + init;
  566. if (init == "true" || init == "false")
  567. return init;
  568. if (init == "0.0f")
  569. return init;
  570. if (init == "1.0f")
  571. return init;
  572. if (init == "0.1f")
  573. return init;
  574. if (init == "0")
  575. return init;
  576. if (init == "-1")
  577. return init;
  578. if (init == "\"\\t\"")
  579. return init;
  580. if (init == "NULL")
  581. return "null";
  582. if (init == "M_MAX_UNSIGNED")
  583. return "0xffffffff";
  584. if (init == "String::EMPTY")
  585. return "\"\"";
  586. // this kind of sucks, can't define const structs
  587. // and default parameters need to be const :/
  588. DefaultStructParameter dparm;
  589. dparm.parameterName = parameter->name_;
  590. if (init == "Vector3::ZERO")
  591. {
  592. dparm.type = "Vector3";
  593. dparm.assignment = "Vector3.Zero";
  594. defaultStructParameters_.Push(dparm);
  595. return "default(Vector3)";
  596. }
  597. if (init == "Vector3::ONE")
  598. {
  599. dparm.type = "Vector3";
  600. dparm.assignment = "Vector3.One";
  601. defaultStructParameters_.Push(dparm);
  602. return "default(Vector3)";
  603. }
  604. if (init == "Vector3::UP")
  605. {
  606. dparm.type = "Vector3";
  607. dparm.assignment = "Vector3.Up";
  608. defaultStructParameters_.Push(dparm);
  609. return "default(Vector3)";
  610. }
  611. if (init == "IntVector2::ZERO")
  612. {
  613. dparm.type = "IntVector2";
  614. dparm.assignment = "IntVector2.Zero";
  615. defaultStructParameters_.Push(dparm);
  616. return "default(IntVector2)";
  617. }
  618. if (init == "Quaternion::IDENTITY")
  619. {
  620. dparm.type = "Quaternion";
  621. dparm.assignment = "Quaternion.Identity";
  622. defaultStructParameters_.Push(dparm);
  623. return "default(Quaternion)";
  624. }
  625. return String::EMPTY;
  626. }
  627. }