Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

scripting-research.html 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <head>
  5. <style>
  6. #header
  7. {
  8. background: #2BA6E3;
  9. padding: 0.7em;
  10. text-align: left;
  11. }
  12. #header a
  13. {
  14. color: white;
  15. text-decoration: none;
  16. padding: 0.5em 1em 0.5em 1em;
  17. }
  18. #lang
  19. {
  20. float: right;
  21. }
  22. .news_item
  23. {
  24. background: #FFFFFF;
  25. width: 720px;
  26. padding: 1em;
  27. margin-top: 2em;
  28. margin-bottom: 2em;
  29. border: 1px solid #E0E0E0;
  30. text-align: left;
  31. }
  32. .news_item_contents
  33. {
  34. color: #444;
  35. line-height: 1.5em;
  36. }
  37. .news_item_date
  38. {
  39. margin-bottom: 2em;
  40. color: #aaa;
  41. }
  42. html
  43. {
  44. font-family: sans-serif;
  45. }
  46. body
  47. {
  48. background: #FAFAFA;
  49. }
  50. code, pre
  51. {
  52. font-family: monospace, serif;
  53. font-size: 1em;
  54. color: #7f0a0c;
  55. }
  56. img
  57. {
  58. width: 720px;
  59. }
  60. a
  61. {
  62. color: #3A91CB;
  63. }
  64. table
  65. {
  66. border-collapse: collapse;
  67. }
  68. table, th, td
  69. {
  70. border: 1px solid #aaa;
  71. padding: 0.5em;
  72. margin-top: 0.5em;
  73. margin-bottom: 0.5em;
  74. }
  75. </style>
  76. </head>
  77. <body>
  78. <script data-goatcounter="https://services.opengamestudio.org:443/count" async src="//services.opengamestudio.org:443/count.js"></script>
  79. <div id="header">
  80. <strong id="title">Open Game Studio</strong>
  81. <a href="../../en/news/index.html">News</a>
  82. <a href="../../en/game/index.html">Games</a>
  83. <a href="../../en/tool/index.html">Tools</a>
  84. <a href="../../en/page/about.html">About</a>
  85. <div id="lang">
  86. <a href="../../en/news/scripting-research.html">EN</a>
  87. <a href="../../ru/news/scripting-research.html">RU</a>
  88. </div>
  89. </div>
  90. <center>
  91. <h1>In the news...</h1>
  92. <div class="news_item">
  93. <h2 class="news_item_title">
  94. <a href="scripting-research.html">Scripting research</a>
  95. </h2>
  96. <p class="news_item_date">
  97. 2017-08-16 00:00
  98. </p>
  99. <div class="news_item_contents">
  100. <p><img src="../../images/2017-08-scripting-research.png" alt="Textbook with a text" /></p>
  101. <p>This article describes scripting research in July 2017.</p>
  102. <p><strong>Our first goal of using a scripting language was to have a platform-independent code that runs unchanged on every supported platform.</strong></p>
  103. <p>OGS Editor 0.10 supports Python for such a code thanks to <a href="http://swig.org/">SWIG</a>. SWIG provides a way to wrap almost any C/C++ code and use it in dozens of languages like Python, Ruby, Lua, Java, C#, etc.. SWIG really helped us taste the beauty of platform-independent code. However, SWIG only works one way: from C/C++ to a target language. This means the main application must be in the target language, and C/C++ code can only be used as a library.</p>
  104. <p>Having the main application in Python works fine for the desktop, but not so great for mobile and web, where C and C++ are the only natively supported cross-platform languages. There are projects like <a href="https://kivy.org">Kivy</a>, which allow you to develop cross-platform applications in Python, but they are not supported natively. This means it's a lot of headaches when Android and iOS APIs change.</p>
  105. <p>Having the main application in C/C++ and the need to support scripting means that a scripting language should be interpreted by the application. This is what SWIG, Kivy, and similar projects are not meant to fulfill.</p>
  106. <p><strong>Our secondary goal for using a scripting language was to allow to extend C++ code.</strong></p>
  107. <p>OGS Editor 0.10 has some modules written in C++, and some in Python. The modules are equal from the perspective of the main application; it doesn't care what language the module is written in.</p>
  108. <p>To achieve such flexibility, we introduced a so-called Environment. Each module would register the keys it responds to, and Environment would deliver corresponding messages.
  109. Technically such behaviour is achieved by inheriting a base class and overriding its methods in both C++ and a scripting language.</p>
  110. <p><strong>First, we evaluated Python for the role of cross-platform scripting language.</strong></p>
  111. <p>Since we already used Python, we started to research the possibility to run Python code on every supported platform. The result was disappointing because CPython (the default Python implementation used on the desktop) does not mention mobile and web platforms. We only found some years old forks of CPython that were claimed to work either on Android or iOS. Such a disarray was not suitable for us.
  112. We also had a look at <a href="http://pypy.org">PyPy</a>, another Python implementation. It also did not mention support for mobile and web platforms.</p>
  113. <p>This was a clear indication that Python community doesn't care for mobile and web platforms. Or that nobody had time to provide the information about building Python on such platforms. Either way, it was not acceptable for us.</p>
  114. <p><strong>Second, we evaluated <a href="http://wren.io">Wren</a> for the role of cross-platform scripting language.</strong></p>
  115. <p>Wren was the first scripting language we stumbled upon in the long list of non-mainstream scripting languages.</p>
  116. <p>Wren claimed to be small and easy to learn. Wren also claimed to be intended for embedding in applications. Ironically, the author <a href="http://wren.io/embedding-api.html">had no time to document how to do the embedding in the first place</a>. When <a href="https://github.com/munificent/wren/issues/465">we asked for the time estimates of publishing</a> the critical part of the documentation, <a href="https://github.com/munificent/wren/issues/402">we just got a reference to another issue</a> where the other guy was asking the same question half a year ago!</p>
  117. <p>That's when we ended our relationship with Wren.</p>
  118. <p><strong>Third, we evaluated <a href="http://chaiscript.com">Chai</a> for the role of cross-platform scripting language.</strong></p>
  119. <p>Chai was in the long list of non-mainstream scripting languages, too. Chai was promising because it claimed to be specifically tailored for embedding in a C++ application.
  120. We successfully managed to call a C++ function from inside Chai but failed to call a member function. <a href="http://discourse.chaiscript.com/t/cannot-call-a-function-that-accepts-a-string-and-a-vector/334">We asked for help</a>, but nobody replied.</p>
  121. <p>We had to end our relationship with Chai.</p>
  122. <p><strong>Fourth, we evaluated Lua for the role of cross-platform scripting language.</strong></p>
  123. <p>Lua is the mainstream language for embedding. So we decided to try the obvious choice. Documentation looked promising, too. However, by the end of reading the <a href="https://www.lua.org/pil/24.html">C API</a> chapter we had no clue how to inherit a class inside Lua.</p>
  124. <p>This led us to search for libraries that wrap Lua C API syntax into something more meaningful for C++. That's how we found <a href="http://sol2.rtfd.io">Sol2</a>. Just as before, the first attempt to call a C++ member function from Lua failed. But unlike before, we asked for help and <a href="https://github.com/ThePhD/sol2/issues/465">got the help</a>! This was a refreshing surprise for us.
  125. Next, we tried to inherit a class in Lua and override the class methods. We failed, but <a href="https://github.com/ThePhD/sol2/issues/468">the author helped us out again</a>. In the end, we succeeded in inheriting a class and overriding its behaviour.</p>
  126. <p>That's when we understood it's a start for a long and mutual relationship with Sol2/Lua.</p>
  127. <p><strong>This search for a scripting language taught us one important lesson: people matter, not technologies.</strong></p>
  128. <p>There are lots of scripting languages that look shiny on the outside but are dead. Why? Because some authors don't have time for users. In return, users don't have time for the authors' projects.</p>
  129. <p>That's it for describing scripting research in July 2017.</p>
  130. </div>
  131. </div>
  132. <div id="footer">
  133. The site has been generated by <a href="http://opengamestudio.org/pskov">PSKOV</a>
  134. from <a href="http://github.com/ogstudio/site-opengamestudio">this source code</a>.
  135. The site is hosted by <a href="https://pages.github.com">GitHub Pages</a>.
  136. </div>
  137. </center>
  138. </body>
  139. </html>