1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-06 03:53:21 +00:00
Commit Graph

95 Commits

Author SHA1 Message Date
Jonathan Coates
e153839a98
Detect playing HTML files in speaker
Goes someway towards preventing people playing YouTube or non-raw GitHub
files.
2023-05-26 10:19:42 +01:00
Jonathan Coates
842eb67e17
Normalise line endings in the SanitisedError test
We could use the system line ending when printing the message, but this
is fine too.
2023-05-25 09:49:40 +01:00
Jonathan Coates
ebed357f05
Truncate longer error messages
We could do this in a more concise manner by wrapping Throwable rather
than reimplementing printStackTrace. However, doing this way allows us
to handle nested exceptions too.
2023-05-25 09:10:03 +01:00
Jonathan Coates
9d16fda266
Fix image links in Modrinth description
Modrinth proxies images hosted on non-trusted domains through wsrv.nl,
for understandable reasons. However, wsrv.nl blocks tweaked.cc - I'm not
sure why. Instead we reference the image on GH directly, which works!

Also:
 - Fix the modrinthSyncBody task pointing to a missing file.
 - Update the licenses of a few files, post getting permission from
   people. <3 all.
2023-05-24 22:35:45 +01:00
Jonathan Coates
2ae14b4c08
Add support for HTTP timeouts (#1453)
- Add a `timeout` parameter to http request and websocket methods.
    - For requests, this sets the connection and read timeout.
    - For websockets, this sets the connection and handshake timeout.
 - Remove the timeout config option, as this is now specified by user
   code.
 - Use netty for handling websocket handshakes, meaning we no longer
   need to deal with pongs.
2023-05-23 22:32:16 +00:00
Jonathan Coates
55ed0dc3ef
Use UTC formats for the 12am os.date tests
We could alternatively use os.time { ... } here, but this feels more
"correct"?

Fixes #1447
2023-05-21 11:08:01 +01:00
Jonathan Coates
3112f455ae
Support arguments being coerced from strings
In this case, we use Lua's tostring(x) semantics (well, modulo
metamethods), instead of Java's Object.toString(x) call. This ensures
that values are formatted (mostly) consistently between Lua and Java
methods.

 - Add IArguments.getStringCoerced, which uses Lua's tostring semantics.

 - Add a Coerced<T> wrapper type, which says to use the .getXCoerced
   methods. I'm not thrilled about this interface - there's definitely
   an argument for using annotations - but this is probably more
   consistent for now.

 - Convert existing methods to use this call.

Closes #1445
2023-05-20 18:54:22 +01:00
Jonathan Coates
e0216f8792
Some core cleanup
- Move some ArgumentHelpers methods to the core project.
 - Remove static imports in CobaltLuaMachine, avoiding confusing calls
   to valueOf.
2023-05-18 19:20:27 +01:00
Jonathan Coates
b91bca8830
Merge pull request #1446 from Erb3/erb3-path-3
Add `colors.fromBlit`.
2023-05-17 22:47:28 +01:00
Jonathan Coates
90177c9f8b
Convert to block comments
And remove empty line between block and definition
2023-05-17 22:21:38 +01:00
Erlend
952674a161 Improve argument validation in colors.fromBlit 2023-05-17 20:20:53 +02:00
Erlend
25ab7d0dcb Improve test for colors.fromBlit to show inverse 2023-05-17 20:16:47 +02:00
Erlend
98ee37719d Improve documentation for colors.fromBlit and colors.toBlit 2023-05-17 20:09:59 +02:00
Erlend
090d17c528 Add tests for colors.fromBlit 2023-05-17 14:43:08 +02:00
Erlend
722b870f98 fix #1367: Add colors.fromBlit 2023-05-17 14:02:21 +02:00
Jonathan Coates
0e48ac1dfe
Speed up JSON string parsing
We now use Lua patterns to find runs of characters. This makes string
parsing 3-4x faster. Ish - I've not run any exact benchmarks.

Closes #1408
2023-05-04 19:47:52 +01:00
Lupus590
5eb4a9033b
Fix typo in docs
foreground and background *characters* -> foreground and background *colours*
2023-05-04 13:58:56 +01:00
Jonathan Coates
ccd7f6326a
Allow GPS hosts to be closer together
I'm not quite sure why I typed a 5 here. There we go.
2023-04-05 21:59:20 +01:00
Jonathan Coates
1f3815039f
Bump CC:T to 1.104.0 2023-04-05 20:50:01 +01:00
Jonathan Coates
eef67a04a4
Handle duplicate pings received by gps.locate
Co-authored-by: Wojbie <Wojbie@gmail.com>
2023-04-05 20:18:38 +01:00
Jonathan Coates
8fe509ecb1
Properly scope IArguments to the current function call
This is a horrible commit: It's a breaking change in a pretty subtle
way, which means it won't be visible while updating. Fortunately I think
the only mod on 1.19.4 is Plethora, but other mods (Mek, Advanced
Peripherals) may be impacted when they update. Sorry!

For some motivation behind the original issue:

The default IArguments implementation (VarargArguments) lazily converts
Lua arguments to Java ones. This is mostly important when passing tables
to Java functions, as we can avoid the conversion entirely if the
function uses IArguments.getTableUnsafe.

However, this lazy conversion breaks down if IArguments is accessed on a
separate thread, as Lua values are not thread-safe. Thus we need to
perform this conversion before the cross-thread sharing occurs.

Now, ideally this would be an implementation detail and entirely
invisible to the user. One approach here would be to only perform this
lazy conversion for methods annotated with @LuaFunction(unsafe=true),
and have it be eager otherwise.

However, the peripheral API gets in the way here, as it means we can no
longer inspect the "actual" method being invoked. And so, alas, this
must leak into the public API.

TLDR: If you're getting weird errors about scope, add an
IArguments.escapes() call before sharing the arguments between threads.

Closes #1384
2023-04-01 11:09:03 +01:00
Jonathan Coates
cbb3e88d76
Relicense a couple more files
Again, not wild about .license files, but it's kinda the only option :/.

See #1339 for further details. <3 everyone!
2023-03-31 18:22:57 +01:00
Jonathan Coates
a9547d1d6f
Further licensing work
- Fix several inaccuracies with several files not marking Dan's
   authorship. Most of these are new files, where the code was moved from
   somewhere else:
   - In the public API:  IDynamicLuaObject, ILuaAPI, TaskCallbakc,
     IDynamicPeripheral, UpgradeBase
   - In the ROM: fs, http, require

 - Do not mark Dan as an author for entirely new code. This affects
   DetailHelpers, DropConsumer, FluidData, InventoryMethods, ItemDetails,
   MonitorRenderState, NoTermComputerScreen, Palette, PlatformHelperImpl,
   UploadFileMessage, the Terminal tests, and any speaker-related files.

 - Relicence many files under the MPL where we have permission to do
   so. See #1339 for further details.

Thank you to everyone who has contributed so far! Cannot overstate how
appreciated it is <3.
2023-03-29 23:00:18 +01:00
Jonathan Coates
dbd47be432
Detect common audio containers in "speaker"
Trying to play a non-DFPWM (or WAV) file will generate terrible noise,
which in turns generates confused users. Instead, fail to play the audio
file and redirect them to the docs.
2023-03-29 09:51:09 +01:00
Jonathan Coates
f93a33aa5e
Bundle jzlib with our published jar
Netty requires this for handling compressed websockets with non-default
compression arguments.

Closes #1394
2023-03-29 09:32:06 +01:00
Jonathan Coates
e655c6d302
Prevent use of shell as a hashbang program
This doesn't do what you want (it'll infinite loop), so while special
casing it /is/ ugly, it's better than a confusing error.

Closes #1386.
2023-03-28 20:57:26 +01:00
Jonathan Coates
435aea18dc
Some cleanup to argument checking
- Consult __name in native code too. Closes #1355. This has the added
   advantage that unconvertable values (i.e. functions) will now
   correctly be reported as their original type, not just nil.

 - Fix the error message in cc.expect, so it matches the rest of Lua.
   This has been bugging me for years, and I keep forgetting to change
   it.
2023-03-28 19:17:15 +01:00
Jonathan Coates
8a203e7454
Re-license several more files under MPL-2.0
- Several files where @MCJack123 is the exclusive contributor. He has
   signed over all contributions to "any OSI-approved license". Thank
   you!

 - Various the file handle classes: Looking at these again, I don't
   think they contain any of the original code.
2023-03-28 10:28:59 +01:00
Jonathan Coates
ca279d410a
Support __name inside cc.expect
See #1355
2023-03-28 08:55:29 +01:00
Jonathan Coates
5bb2e8e8cd
Update Cobalt to 0.7
- Timeouts are now driven by an interrupt system, rather than polling.
   While we do not impose memory limits, this should close #1333.

 - Update the table library to largely match Lua 5.4:
    - Add table.move
    - Table methods (with the exception of foreach/foreachi) now use
      metamethods (closes #1088).
   There's still some remaining quirks (for instance, table.insert
   accepts values out-of-bounds), but I think that's fine.

 - Cobalt's threaded-coroutine system is gone (load now supports
   yielding), so we no longer track coroutine metrics.

 - Type errors now use __name. See #1355, though this does not apply to
   CC methods (either on the Java or CraftOS side), so is not enough to
   resolve it.

See https://github.com/SquidDev/Cobalt/compare/v0.6.0...v0.7.0 for the
full delta.
2023-03-26 19:42:55 +01:00
JackMacWindows
06af3c7240
Add more explanation on how os.epoch("ingame") works 2023-03-16 01:28:12 -04:00
Jonathan Coates
986c65f56e
Construct ILuaMachines in one go
This means creating an ILuaMachine is largely atomic - it either is
created or it fails.
2023-03-15 22:39:51 +00:00
Jonathan Coates
b9e2d0a936
Ignore metatables in textutils.serialize
Closes #1368
2023-03-15 21:53:47 +00:00
Jonathan Coates
895bc7721a
License CC:T according to the REUSE specification (#1351)
This adds SPDX license headers to all source code files, following the
REUSE[1] specification. This does not include any asset files (such as
generated JSON files, or textures). While REUSE does support doing so
with ".license" files, for now we define these licences using the
.reuse/dep5 file.

[1]: https://reuse.software/
2023-03-15 21:52:13 +00:00
Jonathan Coates
c9bb534799
Don't create a TrustManagerFactory
See the discussion in #1352 - Netty uses the system one by default,
so no sense creating our own.

Also make sure we through the HTTP error every time, not just on the
first failure. Otherwise we get cryptic connection dropped errors.
2023-03-04 11:21:06 +00:00
Jonathan Coates
1c120982a7
Distinguish between all parsers passing and failing
Given an input like f(x), which is both a valid statement and
expression, both parsers would accept the whole input. However, this was
treated the same as both parsers rejecting the input, resulting in a
crash when trying to print the error.

We now return immediately when any parser accepts the input.

Fixes #1354
2023-03-04 10:30:12 +00:00
JackMacWindows
67c462f8b0
Fix introduction dates of os.cancel[Alarm|Timer] 2023-02-27 21:57:45 -05:00
Jonathan Coates
4e909bc59e
Improve several comma related parse errors
- Suggest adding a comma on { 2 3 }
 - Suggest removing a comma on f(1, )

Closes #1341.
2023-02-17 21:07:48 +00:00
Jonathan Coates
41c83988a1
Be more rigorous in checking for invalid values in settings.load
If someone had a recursive table (created with an IIFE), then we'd throw
an error inside reserialize. We now catch this error and silently drop
the value.

I'm not thrilled by this behaviour - there's an argument we should
return false instead - but it's consistent with what we currently do.

Closes #1337.
2023-02-17 09:08:29 +00:00
Jonathan Coates
33b6f38339
Hide the internal redirect methods in multishell
Previously it was possible to access all methods of the multishell
redirect by calling term.current(). This is definitely not intended, as
it leaks all sorts of internals to the user.

Also bump illuaminate - the new version is about twice as fast on my
machine.
2023-02-12 21:26:01 +00:00
Jonathan Coates
e1ff1a8c6a
Sync changelog and whatsnew
Every time I commit code on the train I end up regretting it and telling
myself I won't do it again. I should know better by now, and yet here we
are.
2023-02-10 21:32:54 +00:00
Jonathan Coates
ab7af063c3 Remove wrapping from a couple of changelog items 2023-02-10 07:56:12 +00:00
Jonathan Coates
6a116aadb8
Bump CC:T to 1.103.1
Woops!

 - Fix the REPL not printing values, as exception.try didn't return
   values. It did originally, and then I tried to simplify it >_>

 - Change repl_exprs to run an expression and program parser in
   parallel, rather than handling the parallelism on the grammar side -
   that has a few shift/reduce conflicts which result in bad parse
   errors.
2023-02-09 21:45:20 +00:00
Jonathan Coates
9e6e0c8b88
Bump CC:T to 1.103.0 2023-02-09 21:02:09 +00:00
Jonathan Coates
5502412181
Improve display of runtime errors (#1320)
- Bump Cobalt to 0.6.0. We now track both line and column numbers of
   each bytecode instruction, allowing us to map an error to a concrete
   position.

 - `loadfile` (and similar functions) now use the full path, rather than
   the file name. Cobalt truncates this to 30 characters (rather than
   the previous 60) so this should be less noisy.

 - The shell, edit and Lua REPL now display the corresponding source
   code alongside an error.

   Note this is incredibly limited right now - it won't cope with errors
   which cross coroutine boundaries. Supporting this is on the roadmap,
   but requires some careful API design.
2023-02-09 20:53:50 +00:00
Jonathan Coates
7e54a40fa9
Add a couple of missing version annotations 2023-02-09 20:09:57 +00:00
Jonathan Coates
3075d3cea8
Fxi teh spolling of handshakder 2023-02-07 20:59:45 +00:00
Jonathan Coates
cdab8f429e
Clarify Minecraft' shift+right click behaviour
Closes #1323
2023-02-07 08:45:17 +00:00
Jonathan Coates
22cadd6730
Various improvements to our Lua parser
- Encode the DFA as a virtual machine (identical to lrgrep) rather than
   compiling it to a series of Lua functions. While this is a little
   slower and uglier, it's much more space efficient, shaving off 16Kb.

 - Minimise the DFA properly. This only shaves off a few states, but
   every little helps.

 - Run the error handling code from a non-reduced parser stack. This was
   incredibly nasty to get right (and positions are still not correctly
   handled), but it fixes several broken error messages.
2023-02-04 12:46:51 +00:00
Jonathan Coates
366052ec48
Merge pull request #1316 from LelouBil/patch-1
Fix word error in rednet documentation
2023-02-03 19:39:13 +00:00