GithubHelp home page GithubHelp logo

linecode / typescriptpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thelartians/typescriptxx

0.0 1.0 0.0 56 KB

TypeSafe scripting for C++ / embedding TypeScript in a C++ project

License: MIT License

CMake 78.14% C++ 17.22% TypeScript 4.64%

typescriptpp's Introduction

Build Status

TypeScriptPP

Example project showing how to embed the TypeScript scripting language in a C++ project with automatically generated declarations.

Motivation

Lua is a great embedded scripting language for C++ projects. Unfortunately, Lua code becomes unmaintainable as the project grows, due to the absence of reliable static type checkers. In the JavaScript world this was solved a long time ago with through the TypeScript language. Thanks to the great work of TypeScriptToLua project, it is now possible to use TypeScript for Lua projects. This project demonstrates how to use CMake to bring TypeScript, Lua and C++ together and can be used as inspiration or a starting point for further projects.

Usage

git clone https://github.com/TheLartians/TypeScriptPP.git
cd TypeScriptPP
cmake -H. -Bbuild
cmake --build build -j4 # compiles C++, updates declarations and transpiles TypeScript
./build/TypeScriptPP -d # print TypeScript declarations
./build/TypeScriptPP -s lua # runs the transpiled lua script lua/index.lua 

How it works

The C++ project is contained in source/main.cpp which contains the C++ library and a Lua interface. It also defines a simple CLI for generating and printing the declarations and executing a lua script.

The CMake script uses CPM and npm to download and configure all dependencies in the current directory. After building the C++ code, CMake uses the executable to update the TypeScript declarations and then transpiles the TypeScript code to Lua with TypeScriptToLua.

The script also adds package.json and the TypeScript sources to the dependency to automatically re-invoke TypeScriptToLua on changes. The TypeScript sources are collected using GLOB, so be sure to re-run cmake after adding new source files.

Additional commands

Recompile TypeScript without invoking CMake

npm run build

Manually update the declarations

cmake --build build --target update-declarations

typescriptpp's People

Contributors

thelartians avatar

Watchers

 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.