Template project for ComputerCraft programs written in TypeScript.

Overview

cc-tstl-template

Template project for ComputerCraft programs written in TypeScript. Uses TypeScriptToLua to compile with ComputerCraft typing declarations.

Usage

  1. Clone the repository (or download the ZIP).
  2. Run npm install to install dependencies, including TypeScriptToLua.
  3. Customize package.json if you want - it's not used in CC.
  4. Add your code to main.ts, and add other files as desired.
  5. Build the project with npm run build.
  6. Copy main.lua to ComputerCraft, either by copying into the computer folder, dropping on the terminal, using Pastebin, or with CraftOS-PC Remote or cloud-catcher.

Libraries

Built-in CraftOS APIs

All base CraftOS APIs are available in the global namespace - no need to import them. turtle and commands are not yet available, but planned for a future version.

Peripherals are also implemented as classes that inherit from the IPeripheral interface, so you can call wrap and cast it to the desired class to get typings for the peripheral.

cc.* Modules

All modules available in /rom/modules/main/cc have typings included. To import them, just use the import statement like normal:

import * as strings from "cc.strings";
// ...
let str = strings.ensure_width(arg, 20);

Events

A library for handling events in a nicer way (e.g. using named properties rather than indexes) is included as a separate source file. The first line in main.ts includes the event library, which has classes for each event type as well as functions that can automatically or manually pull events with the specified type.

Example:

const timer = os.startTimer(5)
while (true) {
    const ev = event.pullEventAs<event.TimerEvent>("timer");
    if (ev.id == timer) break;
}

tsconfig.json Options

The tsconfig.json file contains some options used by TypeScriptToLua to adjust how Lua code is generated. Some of these may be useful for CC development. See the TSTL webpage for the rest of the options.

  • noImplicitSelf: Controls whether functions have a this/self. By default, all functions are given a self parameter (even ones not in tables!) to allow JavaScript's this value to work. This can be disabled per-function with /** @noSelf **/ or per-file with /** @noSelfInFile **/; but if you don't use this or don't want to have self added to functions, you can set this option to true to disable this/self.
  • luaLibImport: Controls how TypeScript polyfills are emitted in the Lua code. The following options are available:
    • inline: Inserts the only required boilerplate code in each file. This is the default, and is recommended for projects with few files. However, this may generate duplicate code in projects with lots of files.
    • require: Generates a single lualib_bundle.lua file with all of the boilerplate, and each script requires the file. This can generate more code than you need, however. Recommended for projects with lots of files and/or uses lots of JavaScript language features.
    • always: Appears to be the same as require.
    • none: Generates no boilerplate code. Do not use this if you use ANY JavaScript features that do not have a 1:1 conversion to Lua. Not recommended unless size is a major concern and TS is used simply for syntax. (You'll need to remove event.ts to use it.)
  • sourceMapTraceback: Overrides debug.traceback to add TypeScript source line numbers instead of Lua lines. This changes globals, so it's not recommended in production, but it can be useful for debugging.
  • luaBundle: Defines the name of the output Lua file - all TypeScript sources are bundled into this file. If unset, each file will be output separately with the same name as the TS source. This defaults to main.lua, matching main.ts.
  • luaBundleEntry: If luaBundle is set, this marks the TypeScript file that should be executed. This defaults to main.ts.

License

The typings in types/ and event.ts are licensed under the MIT license. Projects are free to use these files as provisioned under the license (i.e. do whatever you want, but include the license notice somewhere in your project). Anything else is public domain.

You might also like...

Work in progress: A presentation server for Lisp programs, implemented in Electron

electron-presentation-server mikel evins [email protected] A work in progress: an experimental presentation server for Lisp programs, implemented with E

Feb 26, 2022

Jaxit is an easy-to-use library that makes an interactive terminal for your programs.

Jaxit Jaxit is an easy-to-use library that makes an interactive terminal for your programs. Jaxit was made by Codeverse, so check on Codeverse's Profi

Dec 11, 2022

Quickly develop, deploy and test Solana programs from the browser.

Solana Playground SolPg allows you to quickly develop, deploy and test Solana programs(smart contracts) from the browser. Note SolPg is still in beta

Dec 29, 2022

Command-line toolkit for parsing, compiling, transpiling, optimizing, linking, dataizing, and running EOLANG programs

First, you install npm and Java SE. Then, you install eolang package: $ npm install eolang Then, you write a simple EO program in hello.eo file in th

Nov 17, 2022

A decentralised portal that aims to help Government Educational organisations to track student and colleges data to provide them with fellowships and programs.

A decentralised portal that aims to help Government Educational organisations to track student and colleges data to provide them with fellowships and programs.

DeSIDB A decentralised database built on Ethereum & Solidity. Introduction - India is a country with a population of 6.8 crore students graduating eac

Jul 10, 2022

Contribute some nodejs programs here ;)

Contribute some nodejs programs here ;)

Nodejs Programs Showcase Table Of Contents Prerequisites Contributing Prerequisites In God we trust. All others must bring data. Need to be courageous

Oct 9, 2022

The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming language for implementing different functions.

Little Man Computer The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming

Nov 17, 2022

Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

CookBook - Hacktoberfest Find the book you want to read next! PRESENTED BY What is CookBook? A cookbook in the programming context is collection of ti

Nov 17, 2022

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript

eta (η) Documentation - Chat - RunKit Demo - Playground Summary Eta is a lightweight and blazing fast embedded JS templating engine that works inside

Dec 29, 2022

Variation-template - Variation is a PSD template that is covered into a web template using HTML5, CSS3, Bootstrapv4.6, JavaScript.

Variation Template Design Variation is a PSD website template. In this project this template is designed with HTML. Deployment This site is deployed a

Jan 1, 2022

This project is a boilerplate for Next and TypeScript projects. This template was built with Vite, TypeScript and Stitches.

This project is a boilerplate for Next and TypeScript projects. This template was built with Vite, TypeScript and Stitches.

Awesome Template Stitches — NextJS, TypeScript, Stitches and Design Tokens Summary About this template Avaliale scripts Other scripts available Main t

Dec 29, 2022

A Lua plugin, written in TypeScript, to write TypeScript (Lua optional).

typescript.nvim A minimal typescript-language-server integration plugin to set up the language server via nvim-lspconfig and add commands for convenie

Dec 29, 2022

Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

Jan 27, 2022

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Dec 20, 2022

Node Express Template (NET.ts) - a small template project which help you to speed up the process of building RESTful API

Node Express Template (NET.ts) - a small template project which help you to speed up the process of building RESTful API

Jan 4, 2023

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Sep 13, 2022

A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I implemented 3 functionalities on the this project namely: Add task edit task delete task using Js

My To-Do List A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I imp

Nov 11, 2022

Discord bot template written with javascript, include slash.

Getting Started This Discord Template with Slash is an advanced, easy to setup, free, and unbranded Discord bot. Official Discord Server If you need h

Aug 22, 2021

A fully-fledged Hardhat project template based on TypeScript.

Fully-Fledged Hardhat Project Template Based on TypeScript Installation It is recommended to install Yarn through the npm package manager, which comes

Dec 21, 2022
Comments
  • Update craftos.d.ts. Fixes #5

    Update craftos.d.ts. Fixes #5

    In order to use multiple annotations with TypeScriptToLua you must use JSDoc annotation style, which dictates that multiple annotations be stored in one multiline comment. #5

    opened by LexiHDev 0
  • Incorrect Annotations

    Incorrect Annotations

    /** @customConstructor window.create */
    /** @noSelf */
    declare class Window implements ITerminal {
        constructor(parent: ITerminal, x: number, y: number, width: number, height: number, visible?: boolean);
    }
    

    Is improper usage of the TypeScript to Lua annotations. TSTL uses JSDoc style annotation, so the proper way to do this would be to use

    /** 
      @customConstructor window.create
      @noSelf */
    declare class Window implements ITerminal {
        constructor(parent: ITerminal, x: number, y: number, width: number, height: number, visible?: boolean);
    }```
    
    Otherwise the customConstructor, "window.create" will not be called.
    opened by LexiHDev 0
  • Window Instance Transpiles with : instead of .

    Window Instance Transpiles with : instead of .

    I wrote this code.

    import * as event from "./event";
    
    const window = new Window(term.current(), 10, 10, 10, 10, true);
    term.clear()
    window.write("Hello world")
    

    After Compiling this, I ran it in ccemux, and it printed out "table e7..." on the screen. In the generated lua file, I saw the line window:write("Hello world") when I expected window.write("Hello world").

    I was able to fix this by opening the craftos.d.ts file and swapping the comment lines above the window class to look like this

    /** @customConstructor window.create */
    /** @noSelf **/
    declare class Window implements ITerminal {
    

    I don't know if this is a versioning thing or an os thing or something else, but I wanted to point it out.

    opened by foopis23 0
Releases(1.100.3)
  • 1.100.3(Mar 16, 2022)

    What's Changed

    • Turtle support and Command Support by @slashracer5 in https://github.com/MCJack123/cc-tstl-template/pull/3

    New Contributors

    • @slashracer5 made their first contribution in https://github.com/MCJack123/cc-tstl-template/pull/3

    Full Changelog: https://github.com/MCJack123/cc-tstl-template/commits/1.100.3

    Source code(tar.gz)
    Source code(zip)
Owner
JackMacWindows
I'm good enough at programming.
JackMacWindows
Template to get started with week0 tasks for MonthOfMERN

Template to get started with week0 tasks for MonthOfMERN

KJSCE CodeCell 3 Dec 4, 2022
TypeScript Data Structures that you need!

TSDS TypeScript Data Structures that you need! Doc Website Introduction A data structure is a way to store and organize data in order to facilitate ac

Ehsan Samavati 25 Dec 8, 2022
Opinionated, type-safe, zero-dependency max/min priority queue for JavaScript and TypeScript projects.

qewe qewe is an opinionated, type-safe, zero-dependency max/min priority queue for JavaScript and TypeScript projects. Installation Add qewe to your p

Jamie McElwain 2 Jan 10, 2022
Nanoservices in no time with seamless TypeScript support.

Nanolith Nanoservices in no time with seamless TypeScript support. Table of Contents About Defining a set of tasks Creating multiple sets of definitio

Matt Stephens 11 Dec 28, 2022
This project demonstrates how you can use the multi-model capabilities of Redis to create a real-time stock watchlist application.

Introduction This project demonstrates how you can use Redis Stack to create a real-time stock watchlist application. It uses several different featur

Redis Developer 43 Jan 2, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺

squirrelly Documentation - Chat - RunKit Demo - Playground Summary Squirrelly is a modern, configurable, and blazing fast template engine implemented

Squirrelly 451 Jan 2, 2023
[OBSOLETE] runs Node.js programs through Chromium DevTools

devtool ⚠️ Update: This tool is mostly obsolete as much of the philosophy has been brought into Node/DevTool core, see here for details. If you wish t

Jam3 3.8k Dec 20, 2022