
We now suggest alternative table keys when code errors with "attempt to index/call 'foo' (a nil value)". For example: "redstone.getinput()", will now suggest "Did you mean: getInput". This is a bit tricky to get right! In the above example, our code reads like: 1 GETTABUP 0 0 0 ; r0 := _ENV["redstone"] 2 GETFIELD 0 0 1 ; r0 := r0["getinput"] 3 CALL 0 1 1 ; r0() Note, that when we get to the problematic line, we don't have access to the original table that we attempted to index. In order to do this, we borrow ideas from Lua's getobjname — we effectively write an evaluator that walks back over the code and tries to reconstruct the expression that resulted in nil. For example, in the above case: - We know an instruction happened at pc=3, so we try to find the expression that computed r0. - We know this was set at pc=2, so we step back one. This is a GETFIELD instruction, so we check the key (it's a constant, so worth reporting), and then try to evaluate the table. - This version of r0 was set at pc=1, so we step back again. It's a GETTABUP instruction, so we can just evaluate that directly. We then use this information (indexing _ENV.redstone with "getinput") to find alternative keys (e.g. getInput, getOutput, etc...) and then pick some likely suggestions with Damerau-Levenshtein/OSD. I'm not entirely thrilled by the implementation here. The core interpretation logic is implemented in Java. Which is *fine*, but a) feels a little cheaty and b) means we're limited to what Lua bytecode can provide (for instance, we can't inspect outer functions, or list all available names in scope). We obviously can expand the bytecode if needed, but something we'd want to be careful with. The alternative approach would be to handle all the parsing in Lua. Unfortunately, this is quite hard to get right — I think we'd need some lazy parsing strategy to avoid constructing the whole AST, while still retaining all the scope information we need. I don't know. We really could make this as complex as we like, and I don't know what the right balance is. It'd be cool to detect patterns like the following, but is it *useful*? local monitor = peripheral.wrap("left") monitor.write("Hello") -- ^ monitor is nil. Is there a peripheral to the left of the -- computer? For now, the current approach feels the easiest, and should allow us to prototype things and see what does/doesn't work.

CC: Tweaked is a mod for Minecraft which adds programmable computers, turtles and more to the game. A fork of the much-beloved ComputerCraft, it continues its legacy with improved performance and stability, along with a wealth of new features.
CC: Tweaked can be installed from Modrinth. It runs on both Minecraft Forge and Fabric.
Contributing
Any contribution is welcome, be that using the mod, reporting bugs or contributing code. If you want to get started developing the mod, check out the instructions here.
Community
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
ComputerCraft, do check out our GitHub discussions page! There's also a fairly populated,
albeit quiet IRC channel on EsperNet, if that's more your cup of tea. You can join #computercraft
through your
desktop client, or online using KiwiIRC.
We also host fairly comprehensive documentation at tweaked.cc.
Using
CC: Tweaked is hosted on my maven repo, and so is relatively simple to depend on. You may wish to add a soft (or hard)
dependency in your mods.toml
file, with the appropriate version bounds, to ensure that API functionality you depend
on is present.
repositories {
maven {
url "https://maven.squiddev.cc"
content {
includeGroup("cc.tweaked")
}
}
}
dependencies {
// Vanilla (i.e. for multi-loader systems)
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-common-api:$cctVersion")
// Forge Gradle
compileOnly("cc.tweaked:cc-tweaked-$mcVersion-core-api:$cctVersion")
compileOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$cctVersion"))
runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge:$cctVersion"))
// Fabric Loom
modCompileOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric-api:$cctVersion")
modRuntimeOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric:$cctVersion")
}
You should also be careful to only use classes within the dan200.computercraft.api
package. Non-API classes are
subject to change at any point. If you depend on functionality outside the API (or need to mixin to CC:T), please file
an issue to let me know!
We bundle the API sources with the jar, so documentation should be easily viewable within your editor. Alternatively, the generated documentation can be browsed online.