Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thelartians/typescriptxx
๐งท Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
https://github.com/thelartians/typescriptxx
asmjs bindings browser c cmake cpp embedded embind emscripten javascript live-reload lua lua-binding nodejs scripting scripting-language typescript typescripttolua wasm webassembly
Last synced: 16 days ago
JSON representation
๐งท Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
- Host: GitHub
- URL: https://github.com/thelartians/typescriptxx
- Owner: TheLartians
- License: unlicense
- Created: 2019-08-06T09:57:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-12T01:21:52.000Z (about 3 years ago)
- Last Synced: 2024-10-03T12:35:21.846Z (about 1 month ago)
- Topics: asmjs, bindings, browser, c, cmake, cpp, embedded, embind, emscripten, javascript, live-reload, lua, lua-binding, nodejs, scripting, scripting-language, typescript, typescripttolua, wasm, webassembly
- Language: CMake
- Homepage:
- Size: 146 KB
- Stars: 40
- Watchers: 5
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Actions Status](https://github.com/TheLartians/TypeScriptXX/workflows/Lua/badge.svg)](https://github.com/TheLartians/TypeScriptXX/actions)
[![Actions Status](https://github.com/TheLartians/TypeScriptXX/workflows/JavaScript/badge.svg)](https://github.com/TheLartians/TypeScriptXX/actions)
[![Actions Status](https://github.com/TheLartians/TypeScriptXX/workflows/Test/badge.svg)](https://github.com/TheLartians/TypeScriptXX/actions)
[![Actions Status](https://github.com/TheLartians/TypeScriptXX/workflows/Check%20style/badge.svg)](https://github.com/TheLartians/TypeScriptXX/actions)
[![codecov](https://codecov.io/gh/TheLartians/TypeScriptXX/branch/master/graph/badge.svg)](https://codecov.io/gh/TheLartians/TypeScriptXX)# TypeScriptXX
## About
This is a template project that uses the [Glue](https://github.com/TheLartians/Glue) library to add type-safe scripting capability to a C++ project.
Scrips are coded in [TypeScript](https://www.typescriptlang.org), transpiled using [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) or [TSTL](https://typescripttolua.github.io) and run in by [node.js](https://nodejs.org) or an an embedded [Lua](https://www.lua.org) 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](typescript/index.ts).
```bash
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.```bash
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](https://emscripten.org/docs/getting_started/downloads.html) the emsdk.
The following commands build the project and run the [typescript script](typescript/index.ts).```bash
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](include/greeter/greeter.h) is exposed to TypeScript using [Glue bindings](source/glue.cpp).
The projects contains four standalone subprojects:
- [test](test), that check the library code
- [declarations](declarations), that simply prints the declarations
- [standaloneLua](standaloneLua), that uses [LuaGlue](https://github.com/TheLartians/LuaGlue) to bind and run lua code.
- [standaloneJS](standaloneJS), that uses [EmGlue](https://github.com/TheLartians/EmGlue) to bind to a JavaScript runtime such as node.js.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.