potatoengine / potato

Hobby C++ game engine
MIT License
38 stars 2 forks source link

Determine direction for scripting language #102

Open seanmiddleditch opened 5 years ago

seanmiddleditch commented 5 years ago

For scripting, we have a few choices. More than a few, really.

The goal of this task is to make a choice about which direction we wish to head, at least in the short term. Each option has its pros and cons and probably shouldn't be eliminated outright, but a decision will have to be made eventually.

Some criteria to consider (but we have to figure out which are important to us):

seanmiddleditch commented 5 years ago

Some thoughts on various scripting language choices.

Languages like Lua or Python have real problems in the efficiency domain for modern uses. Namely, the lack of by-value (stack-allocated) types and the lack of SIMD types really hurts. This boils over into usability concerns, e.g. SIMD types being by-reference makes a large class of obnoxious bug very easy to cause. Lua has LuaJit and Python has a very alternative runtimes, but these tend not to track the latest versions of their respective languages and may not be maintained well.

Languages like Lua, Python, or JavaScript tend to be really great at small scripts, but poor for large codebases meant to be maintained. JavaScript has tools like TypeScript which help a great deal in this area, but the base language is very easy to misuse in ways that create very buggy and unmaintainable scripts.

Languages like C# or WebAsm have non-trivial integration costs, especially considering platform support where we can't use a JIT. Tooling will require AOT compilation modes that may require a great deal of our time to build and maintain. See for example the ridiculous amount of engineering that Unity has had to put into C# with tools like IL2CPP and now their Burst compiler in order to make C# usable-ish as a game language outside of indie or Windows PC use cases.

Custom languages are a ton of (fun!) work to build out, and will forever suffer the problem that the community will be tiny or non-existent. Users will have little documentation, an anemic standard library, no readily-available package ecosystem, and no support on sites like StackExchange. This also applies to niche languages (like ChaiScript or AngelScript).

Languages like Python, C#, and JavaScript have huge standard libraries or package ecosystems. This means that users have billions of lines of code to draw upon that we don't have to write for them.

Languages like Lua, Python, JavaScript, and C# have very mature integration stories for C++ applications. Integrating and maintaining one of those (sans the optimizations and AOT cases) will be very easy compared to most alternatives.

WebAsm is a theoretical choice at best. The idea is that it allows the benefits of hot-reload C++, which in turn means you can embed most scripting runtimes, and it can be used for safe C++ modding on platforms that allow JIT compilation or where we can accept interpreter overhead. WebAsm is effectively designed to make C++ run in a sandbox on arbitrary hardware while embeddeed in another application's domain. It's also only really been used at scale in Web browsers until very very recently (and even Web browser uses are recent because WebAsm is new).

seanmiddleditch commented 5 years ago

Personal feeling time (don't consider these objective arguments):

Lua is a toy language at best. It's great as a glue scripting language (e.g., hooking buttons up in UI or making an event in-game open a door or whatever) but that's about it.

Python is garbage as an embedded scripting language, especially in games. It's the slowest of the mainstream scripting language, and other than a huge standard library, has no real language or development benefits over Lua.

JavaScript is the current reigning champion of dynamic scripting languages. The most cutting-edge research in interpreter and dynamic JIT technology takes place for JavaScript. The package ecosystem and community support/documentation is the largest of any language, period. Old JS is basically just less-weird Lua, and modern JS outshines every other mainstream dynamic language in capability. JS has a billion transpilers that provide easy paths to custom DSLs or dev aides like TypeScript or Babel. JS is gaining support for threads, SIMD, and other features that are traditionally very problematic for dynamic languages. There are multiple high-quality JS embedding APIs (Spidermonkey, V8, Chakra).

C# is the hands-down reigning champ for tools and serious server development. I don't think I'd want to script in it (there's already Unity for people who want that), but it might still make the absolute best extension language for PC Editor use cases.

As a language nerd, I want to play with ChaiScript, AngelScript, or a custom language. I think they're all three just terrible choices for Potato.

Hot-Reload C++ is non-trivial to get working and get working well. There's a huge set of benefits to getting it working, though. I think WebAsm is a better path forward on that, though maybe not quite today (we need runtimes like Wasmer to mature a bit, for Wasm64 support to land, and for SIMD/threading support to get finalized).

blockspacer commented 4 years ago

Hot-Reload C++ is also possible with cling

https://root.cern.ch/root/htmldoc/guides/users-guide/Cling.html https://github.com/vkhristenko/test-cpp/tree/master/cling/test_project

blockspacer commented 4 years ago

For wasm: see https://github.com/intel/wasm-micro-runtime https://github.com/intel/wasm-micro-runtime/issues/100

blockspacer commented 4 years ago

cling based C++ as scripting language. Why? Able to run C++ script in runtime or compile it for max speed ( as in example https://github.com/derofim/cling-cmake )