Commit Graph

95 Commits

Author SHA1 Message Date
Jonathan Coates a735f23e1f
Fix a couple of bugs with wget
- Provide a friendly message when writing to a file fails.
 - Correctly write empty files

Fixes #832, closes #833
2021-06-19 11:59:15 +01:00
Jonathan Coates d71bf225cc
Add very simple markdown support to the help viewer (#819)
- Allow help files to use the ".md" suffix, and move changelog/whatsnew
   to use them.

 - When files end with ".md", the "help" program attempts to highlight
   them. This involves:
   - Colour code blocks with a lightGrey background.
   - Replace lists to use bullet points instead of "-"/"*".
   - Colours headings yellow.
   The implementation of this is a bit janky because a) I wrote this and
   b) we need to run this step before text wrapping, but preserve
   colours and section positions over wrapping (thanks to Jack for
   getting this working).

 - Add section navigation to the help viewer, with left/right to move to
   the next/previous section.

Closes #569
2021-06-12 19:48:41 +01:00
Wojbie b323db30ee
Add cc.shell.completion `programWithArgs` completion. (#815)
And expand monitor, shell, fg and bg to use it
2021-06-07 22:02:45 +01:00
JackMacWindows 53efd6b303
Fixed error handling in scale subcommand (#816) 2021-06-07 20:47:15 +01:00
Matthew Wilbern f8074636bc
Allow craft program to craft unlimited items (#807) 2021-06-06 06:52:01 +01:00
magiczocker10 38335ca187
Add some options for textutils.serialize (#664) 2021-05-29 17:46:58 +01:00
JackMacWindows e0e194099c
Add a scale subcommand to monitor.lua (#623) 2021-05-29 16:55:55 +01:00
Jonathan Coates f96d923b2a
Allow cleaning dyed turtles in a cauldron
Fixes #771. This does not allow clearing pocket computers or disks right
now - neither normally responds very well to water!
2021-05-29 15:18:53 +01:00
Lupus590 28165bfcd6
Add cc.expect.range (#790) 2021-05-17 17:49:48 +01:00
Jonathan Coates bc8e090873 Simplify our overrides of load/loadstring
- Remove auto-prefixing of load/loadstring
 - Use Cobalt's normal load implementation, with a simple hook to
   set _ENV on the environment.
2021-05-04 18:30:28 +01:00
Jonathan Coates cf0f67265f Correctly handle sparse arrays in cc.pretty
This also swaps the order we display mixed array/maps in, so that the
array part comes first. I think this is more sensible.

Closes #777
2021-05-04 18:05:56 +01:00
Jonathan Coates 74dae4ec17 That's it, I'm adding pre-commit hooks 2021-04-28 08:19:09 +01:00
Jonathan Coates 3cb25b3525 Various VM tests
These are largely copied across from Cobalt's test suite, with some
minor tweaks. It actually exposed one bug in Cobalt, which is pretty
nice.

One interesting thing from the coroutine tests, is that Lua 5.4 (and
one assumes 5.2/5.3) doesn't allow yielding from within the error
handler of xpcall - I rather thought it might.

This doesn't add any of the PUC Lua tests yet - I got a little
distracted.

Also:
 - Allow skipping "keyword" tests, in the style of busted. This is
   implemented on the Java side for now.
 - Fix a bug with os.date("%I", _) not being 2 characters wide.
2021-04-27 22:25:46 +01:00
lily 9708dd6786
Fixed sortCoords for draw functions (#749) 2021-04-02 15:30:28 +01:00
Jonathan Coates 6d367e08a3 ./gradlew checkstyleMain
Every time I forget to run this before pushing, I get very sad.
2021-01-19 21:15:18 +00:00
Jonathan Coates eaa7359c8c Add a whole bunch of tests
Coverage graph goes woosh. Hopefully.

More importantly, all of these are historic regressions, so very much
worth tracking.
2021-01-19 20:02:45 +00:00
FensieRenaud 763bab80fa Serialise sparse arrays into JSON (#685) 2021-01-18 20:48:33 +00:00
Jonathan Coates f78e24f9a0 Use UnsafeHacks to construct the test function info
This has been stripped (only in CI on 1.15, always in 1.16) so blows up
when we try to call it.
2021-01-09 20:12:13 +00:00
Jonathan Coates 331031be45 Run integration tests in-game
Name a more iconic duo than @SquidDev and over-engineered test
frameworks.

This uses Minecraft's test core[1] plus a home-grown framework to run
tests against computers in-world.

The general idea is:
 - Build a structure in game.
 - Save the structure to a file. This will be spawned in every time the
   test is run.
 - Write some code which asserts the structure behaves in a particular
   way. This is done in Kotlin (shock, horror), as coroutines give us a
   nice way to run asynchronous code while still running on the main
   thread.

As with all my testing efforts, I still haven't actually written any
tests!  It'd be good to go through some of the historic ones and write
some tests though. Turtle block placing and computer redstone
interactions are probably a good place to start.

[1]: https://www.youtube.com/watch?v=vXaWOJTCYNg
2021-01-09 19:50:27 +00:00
Lupus590 41226371f3
Add isReadOnly to fs.attributes (#639) 2021-01-07 16:36:25 +00:00
Lupus590 16d74dd2e8 Add functions to wrap text 2020-12-23 16:21:04 +00:00
SquidDev d83a68f3ff Allow $private HTTP rule to block any private IP
This is a little magic compared with our previous approach of "list
every private IP range", but given then the sheer number we were
missing[1][2] this feels more reasonable.

Also refactor out some of the logic into separate classes, hopefully to
make things a little cleaner.

Fixes #594.

[1]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
[2]: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
2020-12-05 11:32:00 +00:00
JackMacWindows 24d3777722
Added improved help viewer (#595)
- Pagination, with (page) up/down, q(uit) and scrolling support.
 - Render markdown style bullets ('-'/'*') using a '•' instead.
2020-12-02 19:22:12 +00:00
SquidDev d4199064ae Make fs.combine accept multiple arguments
Means we can now do fs.combine("a", "b", "c"). Of course, one may just
write "a/b/c" in this case, but it's definitely useful elsewhere.

This is /technically/ a breaking change as fs.combine(a, b:gsub(...))
will no longer function (as gsub returns multiple arguments). However,
I've done a quick search through GH and my Pastebin archives and can't
find any programs which would break. Fingers crossed.
2020-11-28 11:41:03 +00:00
SquidDev 04f9644ae7 Allow strings or numbers in textutils.*tabulate
A little dubious, but apparently CC used to support it. This means we're
consistent with methods like io.write or string.len which accept strings
or numbers.

Fixes #591
2020-11-27 21:29:11 +00:00
Lupus590 d13bd2cce8
use arg[0] in all usage printouts (#571) 2020-11-04 14:03:08 +00:00
Drew Lemmy 741adfa7bb
Use blit to draw boxes, add colors.toBlit (#570) 2020-11-01 19:28:18 +00:00
SquidDev c58441b29c Various SNBT parsing improvements
Correctly handle:
 - Typed arrays ([I; 1, 2, 3])
 - All suffixed numbers (1.2d)
 - Single-quoted strings

Fixes #559
2020-11-01 11:36:48 +00:00
SquidDev c334423d42 Add function to get window visibility
Closes #562

Co-authored-by: devomaa <lmao@distruzione.org>
2020-10-31 09:54:38 +00:00
SquidDev 59de21eae2 Handle tabs when parsing JSON
Fixes #539
2020-09-11 18:02:23 +01:00
JackMacWindows d5368d0719
Add date-specific MOTDs (like Minecraft) (#533) 2020-09-04 17:35:46 +01:00
R93950X d5de39ebd4
Fix time formatting (#527)
Fixes #525.

Co-authored-by: R93950X <R93950X@users.noreply.github.com>
2020-08-22 15:17:12 +01:00
hydraz 0e2ce3c634
Make the key for mtime "modified" in fs.attributes (#512) 2020-07-31 18:39:09 +01:00
neumond 053cb1b53c Fix JSON serialization of strings
Control characters become escaped as JSON requires
Non-ASCII characters get escaped as well for better interoperability
We assume here that lua strings represent only first 256 code points of unicode
2020-07-25 19:40:06 +03:00
SquidDev 8f069a9b72 Remove absolute file path from FS errors
When dealing with invalid paths (for instance, ones which are too long
or malformed), Java may throw a FileSystemException. This contains the
absolute path (i.e. C:/Users/Moi/.../.minecraft/...), which is printed
to the user within CC - obviously not ideal!

We simply catch this exception within the MountWrapper and map it back
to the local path. The disadvantage of doing it here is that we can't
map the path in the exception back to the computer - we'd need to catch
it in FileMount for that - so we just assume it referrs to the original
path instead.

Doing it in FileMount ends up being a little uglier, as we already do
all the exception wrangling in FileWrapper, so this'll do for now.

Fixes #495
2020-07-18 10:13:43 +01:00
JakobDev b54519d0e6
Add functions for parsing and drawing nft (#458) 2020-06-25 09:08:35 +01:00
SquidDev 2b077554f7 Merge branch 'mc-1.14.x' into mc-1.15.x
# Conflicts:
#	gradle.properties
#	src/main/java/dan200/computercraft/client/render/MonitorTextureBufferShader.java
#	src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java
#	src/main/java/dan200/computercraft/core/apis/handles/HandleGeneric.java
#	src/main/java/dan200/computercraft/shared/Config.java
#	src/main/java/dan200/computercraft/shared/network/NetworkHandler.java
#	src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java
#	src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java
#	src/main/resources/data/computercraft/lua/rom/help/changelog.txt
#	src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt
2020-06-16 09:24:14 +01:00
SquidDev d929c02d2a Fix settings loading failing for defined settings
Yes, this was the only piece of code which wasn't tested :/. Fixes #457.
2020-05-24 12:16:51 +01:00
Jonathan Coates d5f82fa458
Replace getMethodNames/callMethod with annotations (#447)
When creating a peripheral or custom Lua object, one must implement two
methods:

 - getMethodNames(): String[] - Returns the name of the methods
 - callMethod(int, ...): Object[] - Invokes the method using an index in
   the above array.

This has a couple of problems:
 - It's somewhat unwieldy to use - you need to keep track of array
   indices, which leads to ugly code.
 - Functions which yield (for instance, those which run on the main
   thread) are blocking. This means we need to spawn new threads for
   each CC-side yield.

We replace this system with a few changes:

 - @LuaFunction annotation: One may annotate a public instance method
   with this annotation. This then exposes a peripheral/lua object
   method.

   Furthermore, this method can accept and return a variety of types,
   which often makes functions cleaner (e.g. can return an int rather
   than an Object[], and specify and int argument rather than
   Object[]).

 - MethodResult: Instead of returning an Object[] and having blocking
   yields, functions return a MethodResult. This either contains an
   immediate return, or an instruction to yield with some continuation
   to resume with.

   MethodResult is then interpreted by the Lua runtime (i.e. Cobalt),
   rather than our weird bodgey hacks before. This means we no longer
   spawn new threads when yielding within CC.

 - Methods accept IArguments instead of a raw Object array. This has a
   few benefits:
   - Consistent argument handling - people no longer need to use
     ArgumentHelper (as it doesn't exist!), or even be aware of its
     existence - you're rather forced into using it.
   - More efficient code in some cases. We provide a Cobalt-specific
     implementation of IArguments, which avoids the boxing/unboxing when
     handling numbers and binary strings.
2020-05-15 13:21:16 +01:00
SquidDev 161a5b4707 Document and test the redstone library
The tests may be a little agressive, but I wanted some sanity checks for
the 1.15 API rewrite.
2020-05-15 10:03:47 +01:00
SquidDev 96e7b60285 Display function arguments and positions in the REPL
- cc.pretty.pretty now accepts two additional options:
   - function_args: Show function arguments
   - function_source: Show where functions are defined.
 - Expose the two options as lua.* settings (defaulting function_args to
   true, and function_source to false).
   These are then used in the Lua REPL.

Closes #361
2020-05-14 19:11:57 +01:00
SquidDev 086fccd997 Move the package library into a separate module
Hopefully this makes it a little easier for people to use in custom
shells (and anything else where it might be useful).
2020-05-14 17:27:50 +01:00
Lupus590 05d7be0362
Improvements to the various file system programs (rm, mv, rename) (#440)
This enforces several sanity checks before actually attempting
the move, allowing us to produce friendlier error messages.
2020-05-12 11:32:48 +01:00
SquidDev 9a71dc1a26 Copy across a bunch of 5.1/5.3 io tests
I've been meaning to do this for ages. Woops.
2020-05-11 18:05:40 +01:00
SquidDev 156023b154 Create more work for myself
This ensures no lines start with an empty line, and all files finish
with exactly one "\n".
2020-05-11 16:08:25 +01:00
SquidDev 6b3773a862 Run tests with coverage
- Use jacoco for Java-side coverage. Our Java coverage is /terrible
   (~10%), as we only really test the core libraries. Still a good thing
   to track for regressions though.

 - mcfly now tracks Lua side coverage. This works in several stages:
   - Replace loadfile to include the whole path
   - Add a debug hook which just tracks filename->(lines->count). This
     is then submitted to the Java test runner.
   - On test completion, we emit a luacov.report.out file.

   As the debug hook is inserted by mcfly, this does not include any
   computer startup (such as loading apis, or the root of bios.lua),
   despite they're executed.

   This would be possible to do (for instance, inject a custom header
   into bios.lua). However, we're not actually testing any of the
   behaviour of startup (aside from "does it not crash"), so I'm not
   sure whether to include it or not. Something I'll most likely
   re-evaluate.
2020-05-11 15:47:30 +01:00
Drew Lemmy a565a571f9
Return the peripheral name when wrapping (#436) 2020-05-03 06:53:42 +01:00
SquidDev fb64b6017b Add shell.execute
This functions the same as shell.run, but does not tokenise the
arguments. This allows us to pass command line arguments through to
another program without having to re-quote them.

Closes #417
2020-05-02 11:05:09 +01:00
Jonathan Coates e1663f3df0
Fix malformed doc comments 2020-05-01 08:50:44 +01:00
Jonathan Coates 1fc0214857
Some redesigning of the settings API (#408)
- The store is now split into two sections:
   - A list of possible options, with some metadata about them.
   - A list of values which have been changed.
 - settings.define can be used to register a new option. We have
   migrated all existing options over to use it. This can be used to
   define a default value, description, and a type the setting must have
   (such as `string` or `boolean).

 - settings.{set,unset,clear,load,store} operate using this value list.
   This means that only values which have been changed are stored to
   disk.
   Furthermore, clearing/unsetting will reset to the /default/ value,
   rather than removing entirely.

 - The set program will now display descriptions.

 - settings.{load,save} now default to `.settings` if no path is given.
2020-04-21 11:37:56 +01:00