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

168 lines
6.7KB

  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <head>
  5. <link rel="stylesheet" href="../../style.css">
  6. </head>
  7. <body>
  8. <script data-goatcounter="https://services.opengamestudio.org:443/count" async src="//services.opengamestudio.org:443/count.js"></script>
  9. <div id="header">
  10. <div class="header2">
  11. <div class="menu">
  12. <a href="../../en/news/index.html">News</a>
  13. <a href="../../en/game/index.html">Games</a>
  14. <a href="../../en/tool/index.html">Tools</a>
  15. <a href="../../en/page/about.html">About</a>
  16. </div>
  17. <div id="lang">
  18. <a href="../../en/news/cld_ctx-gen.html">EN</a>
  19. <a href="../../ru/news/cld_ctx-gen.html">RU</a>
  20. </div>
  21. <div class="clear"></div>
  22. </div>
  23. </div>
  24. <h3 class="left_item_title">In the news...</h3>
  25. <center>
  26. <div class="news_item">
  27. <h2 class="news_item_title">
  28. <a href="cld_ctx-gen.html">CLD: Context generation</a>
  29. </h2>
  30. <p class="news_item_date">
  31. 2025-03-11 00:00
  32. </p>
  33. <div class="news_item_contents">
  34. <p><img src="../../images/2025-03_redux-data-flow.jpg" alt="splash" /></p>
  35. <h1 id="contextgeneration">Context generation</h1>
  36. <p>In February I've updated the <strong>C</strong>ross-<strong>l</strong>anguage <strong>d</strong>ialect (CLD) translator to
  37. generate Context out of YML. The generated Contexts have already been
  38. used for the following projects:</p>
  39. <ul>
  40. <li>CLD (the CLD translator generated its own Context)</li>
  41. <li>LHA</li>
  42. <li>PSKOV</li>
  43. </ul>
  44. <p>I never really took time to explain what Context is, so here's
  45. a very short explanation: Context is very close to
  46. <a href="https://redux.js.org/introduction/getting-started#basic-example">Store in Redux</a>. I'm afraid this is not yet the time
  47. to explain Context in detail because I don't yet have a good
  48. argument why you need Context. Once that time comes I do it.</p>
  49. <p>Now let's get back to the Context generation. Here's how LHA's YML for Context looks like: (<a href="https://github.com/OGStudio/local-host-access/blob/main/cld/entities.yml">entities.yml</a>):</p>
  50. <pre><code># Application state context
  51. Context:
  52. type: context
  53. fields:
  54. # Command line arguments
  55. arguments: [String]
  56. consoleOutput: String
  57. defaultDir: String
  58. didLaunch: Bool
  59. dir: String
  60. httpDefaultPort: Int
  61. httpLaunch: Bool
  62. httpPort: Int
  63. httpReply: String
  64. httpRequest: NetRequest
  65. </code></pre>
  66. <p>CLD translator converts it to the following code in Kotlin (<a href="https://github.com/OGStudio/local-host-access/blob/main/src/entities.kt#L3">entities.kt</a>):</p>
  67. <pre><code>// Application state context
  68. data class Context(
  69. // Command line arguments
  70. var arguments: Array&lt;String&gt; = arrayOf(),
  71. var consoleOutput: String = "",
  72. var defaultDir: String = "",
  73. var didLaunch: Boolean = false,
  74. var dir: String = "",
  75. var httpDefaultPort: Int = 0,
  76. var httpLaunch: Boolean = false,
  77. var httpPort: Int = 0,
  78. var httpReply: String = "",
  79. var httpRequest: NetRequest = NetRequest(),
  80. override var recentField: String = "",
  81. ): CLDContext {
  82. override fun &lt;T&gt; field(name: String): T {
  83. if (name == "arguments") {
  84. return arguments as T
  85. } else if (name == "consoleOutput") {
  86. return consoleOutput as T
  87. } else if (name == "defaultDir") {
  88. return defaultDir as T
  89. } else if (name == "didLaunch") {
  90. return didLaunch as T
  91. } else if (name == "dir") {
  92. return dir as T
  93. } else if (name == "httpDefaultPort") {
  94. return httpDefaultPort as T
  95. } else if (name == "httpLaunch") {
  96. return httpLaunch as T
  97. } else if (name == "httpPort") {
  98. return httpPort as T
  99. } else if (name == "httpReply") {
  100. return httpReply as T
  101. } else if (name == "httpRequest") {
  102. return httpRequest as T
  103. }
  104. return "unknown-field-name" as T
  105. }
  106. override fun selfCopy(): CLDContext {
  107. return this.copy()
  108. }
  109. override fun setField(
  110. name: String,
  111. value: Any?
  112. ) {
  113. if (name == "arguments") {
  114. arguments = value as Array&lt;String&gt;
  115. } else if (name == "consoleOutput") {
  116. consoleOutput = value as String
  117. } else if (name == "defaultDir") {
  118. defaultDir = value as String
  119. } else if (name == "didLaunch") {
  120. didLaunch = value as Boolean
  121. } else if (name == "dir") {
  122. dir = value as String
  123. } else if (name == "httpDefaultPort") {
  124. httpDefaultPort = value as Int
  125. } else if (name == "httpLaunch") {
  126. httpLaunch = value as Boolean
  127. } else if (name == "httpPort") {
  128. httpPort = value as Int
  129. } else if (name == "httpReply") {
  130. httpReply = value as String
  131. } else if (name == "httpRequest") {
  132. httpRequest = value as NetRequest
  133. }
  134. }
  135. }
  136. </code></pre>
  137. <h1 id="march">March</h1>
  138. <p>Kotlin is currently the anchor programming language of CLD. Thus, to use Kotlin,
  139. one would have to install related Java tools (Gradle, Android Studio or JVM itself).
  140. Such a requirement makes it impossible to have a web browser only development
  141. tool. And being able to code in a web browser is something I consider the
  142. key feature for code portability.</p>
  143. <p>That's why in March I plan to create the draft of a tool running in a web browser.</p>
  144. </div>
  145. </div>
  146. <div id="disqus_thread"></div>
  147. <script>
  148. var disqus_config = function () {
  149. this.page.url = "https://opengamestudio.org/en/news/cld_ctx-gen.html";
  150. this.page.identifier = "cld_ctx-gen.html";
  151. };
  152. (function() { // DON'T EDIT BELOW THIS LINE
  153. var d = document, s = d.createElement('script');
  154. s.src = 'https://opengamestudio.disqus.com/embed.js';
  155. s.setAttribute('data-timestamp', +new Date());
  156. (d.head || d.body).appendChild(s);
  157. })();
  158. </script>
  159. <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  160. <div id="footer">
  161. The site has been generated by <a href="http://opengamestudio.org/pskov">PSKOV</a>
  162. from <a href="http://github.com/ogstudio/site-opengamestudio">this source code</a>.
  163. </div>
  164. </center>
  165. </body>
  166. </html>