Bridges

The Language Bridges are for programmers who know another language and want to write JaiScript. The Code Migrations are for C++ code that uses a library JaiScript replaces.

Language Bridges

Each bridge sets a language beside JaiScript idiom by idiom, then lists where a habit from it gets a different answer, with a sample of what JaiScript does. To run a sample, save it as try.jai and run jaiscript try.jai (Hello & Basics has the setup). Every bridge points first to Value Semantics & References, where the Language Guide takes over.

  1. From JavaScript

    var, function, template strings and ?. carry over, with let, arrow functions, ??, do ... while and the array helpers (map, reduce, find, ...). Assignment copies arrays and objects, == compares contents and never converts, 7 / 2 is 3, lambdas name what they capture.

  2. From C++

    Value classes, references, destructors, operators and capture lists mean what they mean in C++. No pointers or templates, a narrow const; a defined evaluation order, checked overflow, no slicing, and a switch that never falls through.

  3. From C#

    Classes, override, statics and yield look familiar, but a class is a value type: new makes the shared reference. var is dynamic and auto is C#'s var; properties are accessor methods, and coroutines replace async.

Code Migrations

Each migration maps a C++ library's types and calls to their JaiScript spelling, converts an example, and lists what has no counterpart and where a straight translation gives another result.

  1. From Cereal

    Archives, names, save/load splits, versions, polymorphic registration and pointer identity; the JAI_PROPERTY route that deletes the serialize functions; both libraries in one function during the transition; converting existing files once. Boost.Serialization spellings included.

  2. From Boost.Signals2

    signal, connection, scoped_connection, track, blocks and combiners mapped to jai::signal, and what behaves differently: the private emitter, a handle that is the connection, the per-signal lock. Notes for Qt and sigslot code.

  3. From ChaiScript Bindings

    fun, user_type, constructor, base_class, modules, globals, eval and eval_error mapped to the engine and dynamic_binder; then the script habits that change: arguments copy, interpolation uses backticks, integers are 64-bit and checked.

  4. From sol2 (Lua) Bindings

    new_usertype, constructors, property, overload, bases, meta functions, tables and protected calls; then the Lua habits that change: tables become values, indexes start at 0, / truncates between integers, 0 is false.

  5. From Squirrel Bindings

    The stack-based C API (sq_newclosure, sq_newclass with type tags, sq_call, sq_getlasterror); then the Squirrel habits that change: instances, arrays and tables copy, the empty string is false, generators become coroutines.

  6. From pybind11 and Boost.Python

    class_, init, def_readwrite, def_property, overload_cast, holders, error_already_set and calls into Python, and what has no counterpart: keyword arguments, trampolines, the GIL.

  7. From nlohmann::json

    NLOHMANN_DEFINE_TYPE_*, dump and get<T> mapped to the archives and the record format they write; plain JSON documents through the script's from_json and to_json.

  8. From Qt Properties, RTTR and refl-cpp

    Q_PROPERTY, RTTR registration and REFL_AUTO mapped to JAI_PROPERTY: declaring, walking, reading and writing by name, NOTIFY as an observable property, and what has no counterpart: metadata, compile-time iteration, dynamic properties.

  9. From Lua Coroutines and C++20 Schedulers

    coroutine.create, yield, resume and status, and C++20 promise types and schedulers, mapped to coroutine functions with next(), next(n) and done(); hosting handles from C++, budgets and hot reload.