Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

7 роки тому
7 роки тому
7 роки тому
7 роки тому
7 роки тому
7 роки тому
7 роки тому
7 роки тому
7 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <!-- Set the viewport width to device width for mobile -->
  5. <meta name="viewport" content="width=device-width" />
  6. <title>Scripting research</title>
  7. <link rel="stylesheet" href="https://github.com/KaiSD/ogs-site/theme/css/normalize.css" />
  8. <link rel="stylesheet" href="https://github.com/KaiSD/ogs-site/theme/css/foundation.min.css" />
  9. <link rel="stylesheet" href="https://github.com/KaiSD/ogs-site/theme/css/style.css" />
  10. <link rel="stylesheet" href="https://github.com/KaiSD/ogs-site/theme/css/pygments.css" />
  11. <script src="https://github.com/KaiSD/ogs-site/theme/js/custom.modernizr.js"></script>
  12. <!-- So Firefox can bookmark->"abo this site" -->
  13. <link href="feeds/all.atom.xml" rel="alternate" title="Opensource Game Studio" type="application/atom+xml">
  14. </head>
  15. <body>
  16. <!-- Nav Bar -->
  17. <nav>
  18. <!-- Show menu items and pages -->
  19. <div class="row">
  20. <div class="large-12 columns top-bar">
  21. <h1><a href="https://github.com/KaiSD/ogs-site">Opensource Game Studio</a></h1>
  22. </div>
  23. </div>
  24. <div class="row top-menu">
  25. <div class="large-12 columns">
  26. <a href="/pages/projects.html" class="menu-button secondary">Projects</a>
  27. <a href="/pages/about.html" class="menu-button secondary">About</a>
  28. </div>
  29. </div>
  30. </nav>
  31. <!-- End Nav -->
  32. <!-- Main Page Content and Sidebar -->
  33. <div class="row">
  34. <!-- Main Blog Content -->
  35. <div class="large-9 columns">
  36. <article>
  37. <header>
  38. <h3 class="article-title"><a href="https://github.com/KaiSD/ogs-site/scripting-research.html" rel="bookmark"
  39. title="Permalink to Scripting research">Scripting research</a></h3>
  40. </header>
  41. <h6 class="subheader" title="2017-08-16T00:00:00+03:00">Wed 16 August 2017
  42. <a class="button secondary small translation-button" href="https://github.com/KaiSD/ogs-site/scripting-research-ru.html">ru</a>
  43. </h6> <p><img alt="Scripting research" src="https://github.com/KaiSD/ogs-site/2017-08-scripting-research.png"></p>
  44. <p>This article describes scripting research in July 2017.</p>
  45. <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>
  46. <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>
  47. <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>
  48. <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>
  49. <p><strong>Our secondary goal for using a scripting language was to allow to extend C++ code.</strong></p>
  50. <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>
  51. <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.
  52. Technically such behaviour is achieved by inheriting a base class and overriding its methods in both C++ and a scripting language.</p>
  53. <p><strong>First, we evaluated Python for the role of cross-platform scripting language.</strong></p>
  54. <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.
  55. 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>
  56. <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>
  57. <p><strong>Second, we evaluated <a href="http://wren.io">Wren</a> for the role of cross-platform scripting language.</strong></p>
  58. <p>Wren was the first scripting language we stumbled upon in the long list of non-mainstream scripting languages.</p>
  59. <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>
  60. <p>That's when we ended our relationship with Wren.</p>
  61. <p><strong>Third, we evaluated <a href="http://chaiscript.com">Chai</a> for the role of cross-platform scripting language.</strong></p>
  62. <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.
  63. 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>
  64. <p>We had to end our relationship with Chai.</p>
  65. <p><strong>Fourth, we evaluated Lua for the role of cross-platform scripting language.</strong></p>
  66. <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>
  67. <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.
  68. 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>
  69. <p>That's when we understood it's a start for a long and mutual relationship with Sol2/Lua.</p>
  70. <p><strong>This search for a scripting language taught us one important lesson: people matter, not technologies.</strong></p>
  71. <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>
  72. <p>That's it for describing scripting research in July 2017.</p>
  73. <p class="subheader">Category: <a href="https://github.com/KaiSD/ogs-site/category/news.html">News</a>
  74. </p>
  75. </article>
  76. </div>
  77. <!-- End Main Content -->
  78. <!-- Sidebar -->
  79. <aside class="large-3 columns">
  80. <!--k
  81. <h5 class="sidebar-title">Site</h5>
  82. <ul class="side-nav">
  83. <li><a href="https://github.com/KaiSD/ogs-site/archives.html">Archives</a>
  84. <li><a href="https://github.com/KaiSD/ogs-site/tags.html">Tags</a>
  85. <li><a href="https://github.com/KaiSD/ogs-site/feeds/all.atom.xml" rel="alternate">Atom feed</a></li>
  86. </ul>
  87. <h5 class="sidebar-title">Categories</h5>
  88. <ul class="side-nav">
  89. <li><a href="https://github.com/KaiSD/ogs-site/category/news.html">News</a></li>
  90. <li><a href="https://github.com/KaiSD/ogs-site/category/stub.html">Stub</a></li>
  91. </ul>
  92. -->
  93. <h5 class="sidebar-title">Projects</h5>
  94. <ul class="side-nav">
  95. <li><a href="/pages/ogs-mahjong.html">OGS Mahjong</a></li>
  96. <li><a href="/pages/ogs-editor.html">OGS Editor</a></li>
  97. <li><a href="/pages/openscenegraph-guide.html">OpenSceneGraph guide</a></li>
  98. </ul>
  99. </aside> <!-- End Sidebar -->
  100. </div> <!-- End Main Content and Sidebar -->
  101. <!-- Footer -->
  102. <footer class="row">
  103. <div class="large-12 columns">
  104. <hr />
  105. <div class="row">
  106. <div class="large-7 columns">
  107. <p>Proudly powered by <a href="http://getpelican.com">Pelican</a>, which takes great advantage of <a href="http://python.org">Python</a>.</p>
  108. </div>
  109. </div>
  110. </div>
  111. </footer>