Hello! These types are intended to be used with Typescript to Lua. With that compiler you can transpile .ts
files into .lua
files. This package is the safety net for the Tabletop Simulator functions and objects. Let your editor have some nice autocompletion!.
src
directory:
npm i tts-types typescript typescript-to-lua
mkdir src
{
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"target": "ESNext",
"lib": ["ESNext"],
"moduleResolution": "nodenext",
"module": "NodeNext",
"declaration": false,
"declarationMap": false,
"strict": true,
"types": ["tts-types"],
},
"tstl": {
"luaTarget": "5.2",
"noImplicitSelf": true,
"tstlVerbose": true,
"luaBundle": "bundle.lua",
"luaBundleEntry": "src/index.ts",
},
}
note: we use "luaTarget": "5.2"
to be compatible with the LUA version Tabletop Simulator uses.
Create src/index.ts
// The OnLoad function. This is called after everything in the game save finishes loading.
// Most of your script code goes here.
function onLoad( saveData: any ) {
// Lock color-UI cube
let cube = getObjectFromGUID( "c1a0d1" )
cube.interactable = false
cube.setLock( true )
}
Your project is ready! run npx tstl
to compile it into Lua
npx tstl
You will have some output like this:
Loaded 0 plugins
Parsing project settings
Transforming C:/Source/tts-test/src/index.ts
Printing C:/Source/tts-test/src/index.ts
Constructing emit plan
Resolving dependencies for C:/Source/tts-test/src/index.ts
Emitting output
Emitting C:/Source/tts-test/build/bundle.lua
Emit finished!
Your .lua file now exists at build/bundle.lua:
build/bundle.lua
autogenerated fileI use this to copy it in automatically (package.json):
"scripts": {
"compile": "tstl && npm run deploy",
"deploy": "copy \"build\\bundle.lua\" \"%LOCALAPPDATA%\\Temp\\TabletopSimulator\\Tabletop Simulator Lua\\Global.-1.lua\""
}
So I can simply use npm run compile
npm install
npm run build
to build the projectnpm run test
to run tests