Coder Social home page Coder Social logo

thelartians / typescriptxx Goto Github PK

View Code? Open in Web Editor NEW
38.0 5.0 4.0 150 KB

🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.

License: The Unlicense

CMake 76.85% C++ 22.25% TypeScript 0.90%
typescript cpp lua scripting embedded lua-binding cmake scripting-language typescripttolua live-reload wasm asmjs javascript bindings browser emscripten embind c nodejs webassembly

typescriptxx's Introduction

Actions Status Actions Status Actions Status Actions Status codecov

TypeScriptXX

About

This is a template project that uses the Glue library to add type-safe scripting capability to a C++ project. Scrips are coded in TypeScript, transpiled using tsc or TSTL and run in by node.js or an an embedded Lua engine. The built JavaScript target can also be run in a browser and used on a website. The TypeScript declarations are automatically generated and updated by CMake.

Usage

Transpile to Lua and run natively

The following commands build the project and run the typescript script.

cmake -HstandaloneLua -Bbuild/lua

 # Compiles C++ code, updates the declarations and transpiles TypeScript
cmake --build build/lua -j8

# runs the transpiled lua script at dist/lua/index.lua
./build/lua/TypeScriptXX --script dist/lua 

Is is also possible to enable watch mode for hot reloading. This way any code changes to the TypeScript source will be transpiled and run automatically.

npx concurrently "npm run watch:lua" "./build/lua/TypeScriptXX -s dist/lua --watch"

Transpile to JavaScript and run in node.js

First, install and activate the emsdk. The following commands build the project and run the typescript script.

emcmake cmake -HstandaloneJS -Bbuild/js

 # Compiles C++ code, updates the declarations and transpiles TypeScript
cmake --build build/js -j8

# runs the transpiled lua script at dist/js/index.js
node ./build/js/TypeScriptXX.js --script dist/js 

How it works

The example C++ library is exposed to TypeScript using Glue bindings.

The projects contains four standalone subprojects:

After building, CMake will use the latter to ensure that the declarations at typescript/cpplib.d.ts are up-to-date and then transpile the TypeScript code to Lua or JavaScript.

typescriptxx's People

Contributors

dependabot[bot] avatar thelartians avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.