mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-02 10:37:54 +00:00
Some minor documentation fixes
- Add a TOC to the Local IPs page. - Increase the echo delay in our speaker audio page to 1.5s. This sounds much better and is less clashy than 1s. Also add a sleep(0) (eww, I know) to fix timeouts on some browsers/computers. - Move Lua feature compat to a new "reference" section. Still haven't figured out how to structure these docs - open to any ideas really. - Mention FFmpeg as an option for converting to DFPWM (closes #1075). - Allow data-mount to override built-in files. See my comment in #1069.
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
---
|
||||
module: [kind=guide] feature_compat
|
||||
---
|
||||
|
||||
# Lua 5.2/5.3 features in CC: Tweaked
|
||||
CC: Tweaked is based off of the Cobalt Lua runtime, which uses Lua 5.1. However, Cobalt and CC:T implement additional features from Lua 5.2 and 5.3 (as well as some deprecated 5.0 features) that are not available in base 5.1. This page lists all of the compatibility for these newer versions.
|
||||
|
||||
## Lua 5.2
|
||||
| Feature | Supported? | Notes |
|
||||
|---------------------------------------------------------------|------------|-------------------------------------------------------------------|
|
||||
| `goto`/labels | ❌ | |
|
||||
| `_ENV` | 🔶 | The `_ENV` global points to `getfenv()`, but it cannot be set. |
|
||||
| `\z` escape | ✔ | |
|
||||
| `\xNN` escape | ✔ | |
|
||||
| Hex literal fractional/exponent parts | ✔ | |
|
||||
| Empty statements | ❌ | |
|
||||
| `__len` metamethod | ✔ | |
|
||||
| `__ipairs` metamethod | ❌ | |
|
||||
| `__pairs` metamethod | ✔ | |
|
||||
| `bit32` library | ✔ | |
|
||||
| `collectgarbage` isrunning, generational, incremental options | ❌ | `collectgarbage` does not exist in CC:T. |
|
||||
| New `load` syntax | ✔ | |
|
||||
| `loadfile` mode parameter | ✔ | Supports both 5.1 and 5.2+ syntax. |
|
||||
| Removed `loadstring` | 🔶 | Only if `disable_lua51_features` is enabled in the configuration. |
|
||||
| Removed `getfenv`, `setfenv` | 🔶 | Only if `disable_lua51_features` is enabled in the configuration. |
|
||||
| `rawlen` function | ✔ | |
|
||||
| Negative index to `select` | ✔ | |
|
||||
| Removed `unpack` | 🔶 | Only if `disable_lua51_features` is enabled in the configuration. |
|
||||
| Arguments to `xpcall` | ❌ | |
|
||||
| Second return value from `coroutine.running` | ❌ | |
|
||||
| Removed `module` | ✔ | |
|
||||
| `package.loaders` -> `package.searchers` | ❌ | |
|
||||
| Second argument to loader functions | ✔ | |
|
||||
| `package.config` | ✔ | |
|
||||
| `package.searchpath` | ✔ | |
|
||||
| Removed `package.seeall` | ✔ | |
|
||||
| `string.dump` on functions with upvalues (blanks them out) | ✔ | |
|
||||
| `string.rep` separator | ❌ | |
|
||||
| `%g` match group | ❌ | |
|
||||
| Removal of `%z` match group | ❌ | |
|
||||
| Removed `table.maxn` | 🔶 | Only if `disable_lua51_features` is enabled in the configuration. |
|
||||
| `table.pack`/`table.unpack` | ✔ | |
|
||||
| `math.log` base argument | ✔ | |
|
||||
| Removed `math.log10` | 🔶 | Only if `disable_lua51_features` is enabled in the configuration. |
|
||||
| `*L` mode to `file:read` | ✔ | |
|
||||
| `os.execute` exit type + return value | ❌ | `os.execute` does not exist in CC:T. |
|
||||
| `os.exit` close argument | ❌ | `os.exit` does not exist in CC:T. |
|
||||
| `istailcall` field in `debug.getinfo` | ❌ | |
|
||||
| `nparams` field in `debug.getinfo` | ✔ | |
|
||||
| `isvararg` field in `debug.getinfo` | ✔ | |
|
||||
| `debug.getlocal` negative indices for varargs | ❌ | |
|
||||
| `debug.getuservalue`/`debug.setuservalue` | ❌ | Userdata are rarely used in CC:T, so this is not necessary. |
|
||||
| `debug.upvalueid` | ✔ | |
|
||||
| `debug.upvaluejoin` | ✔ | |
|
||||
| Tail call hooks | ❌ | |
|
||||
| `=` prefix for chunks | ✔ | |
|
||||
| Yield across C boundary | ✔ | |
|
||||
| Removal of ambiguity error | ❌ | |
|
||||
| Identifiers may no longer use locale-dependent letters | ✔ | |
|
||||
| Ephemeron tables | ❌ | |
|
||||
| Identical functions may be reused | ❌ | |
|
||||
| Generational garbage collector | ❌ | Cobalt uses the built-in Java garbage collector. |
|
||||
|
||||
## Lua 5.3
|
||||
| Feature | Supported? | Notes |
|
||||
|---------------------------------------------------------------------------------------|------------|---------------------------|
|
||||
| Integer subtype | ❌ | |
|
||||
| Bitwise operators/floor division | ❌ | |
|
||||
| `\u{XXX}` escape sequence | ✔ | |
|
||||
| `utf8` library | ✔ | |
|
||||
| removed `__ipairs` metamethod | ✔ | |
|
||||
| `coroutine.isyieldable` | ❌ | |
|
||||
| `string.dump` strip argument | ✔ | |
|
||||
| `string.pack`/`string.unpack`/`string.packsize` | ✔ | |
|
||||
| `table.move` | ❌ | |
|
||||
| `math.atan2` -> `math.atan` | ❌ | |
|
||||
| Removed `math.frexp`, `math.ldexp`, `math.pow`, `math.cosh`, `math.sinh`, `math.tanh` | ❌ | |
|
||||
| `math.maxinteger`/`math.mininteger` | ❌ | |
|
||||
| `math.tointeger` | ❌ | |
|
||||
| `math.type` | ❌ | |
|
||||
| `math.ult` | ❌ | |
|
||||
| Removed `bit32` library | ❌ | |
|
||||
| Remove `*` from `file:read` modes | ✔ | |
|
||||
| Metamethods respected in `table.*`, `ipairs` | 🔶 | Only `__lt` is respected. |
|
||||
|
||||
## Lua 5.0
|
||||
| Feature | Supported? | Notes |
|
||||
|----------------------------------|------------|--------------------------------------------------|
|
||||
| `arg` table | 🔶 | Only set in the shell - not used in functions. |
|
||||
| `string.gfind` | ✔ | Equal to `string.gmatch`. |
|
||||
| `table.getn` | ✔ | Equal to `#tbl`. |
|
||||
| `table.setn` | ❌ | |
|
||||
| `math.mod` | ✔ | Equal to `math.fmod`. |
|
||||
| `table.foreach`/`table.foreachi` | ✔ | |
|
||||
| `gcinfo` | ❌ | Cobalt uses the built-in Java garbage collector. |
|
@@ -2,11 +2,15 @@
|
||||
module: [kind=guide] local_ips
|
||||
---
|
||||
|
||||
# Allowing access to local IPS
|
||||
# Allowing access to local IPs
|
||||
By default, ComputerCraft blocks access to local IP addresses for security. This means you can't normally access any
|
||||
HTTP server running on your computer. However, this may be useful for testing programs without having a remote
|
||||
server. You can unblock these IPs in the ComputerCraft config.
|
||||
|
||||
- [Minecraft 1.13 and later, CC:T 1.87.0 and later](#cc-1.87.0)
|
||||
- [Minecraft 1.13 and later, CC:T 1.86.2 and earlier](#cc-1.86.2)
|
||||
- [Minecraft 1.12.2 and earlier](#mc-1.12)
|
||||
|
||||
## Minecraft 1.13 and later, CC:T 1.87.0 and later {#cc-1.87.0}
|
||||
The configuration file can be located at `serverconfig/computercraft-server.toml` inside the world folder on either
|
||||
single-player or multiplayer. Look for lines that look like this:
|
||||
|
@@ -125,7 +125,7 @@ different.
|
||||
First, we require the dfpwm module and call @{cc.audio.dfpwm.make_decoder} to construct a new decoder. This decoder
|
||||
accepts blocks of DFPWM data and converts it to a list of 8-bit amplitudes, which we can then play with our speaker.
|
||||
|
||||
As mentioned to above, @{speaker.playAudio} accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
|
||||
As mentioned above, @{speaker.playAudio} accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
|
||||
sample, which means we want to process our audio in chunks of 16×1024 bytes (16KiB). In order to do this, we use
|
||||
@{io.lines}, which provides a nice way to loop over chunks of a file. You can of course just use @{fs.open} and
|
||||
@{fs.BinaryReadHandle.read} if you prefer.
|
||||
@@ -136,22 +136,22 @@ You can mix together samples from different streams by adding their amplitudes,
|
||||
samples, etc...
|
||||
|
||||
Let's put together a small demonstration here. We're going to add a small delay effect to the song above, so that you
|
||||
hear a faint echo about a second later.
|
||||
hear a faint echo a second and a half later.
|
||||
|
||||
In order to do this, we'll follow a format similar to the previous example, decoding the audio and then playing it.
|
||||
However, we'll also add some new logic between those two steps, which loops over every sample in our chunk of audio, and
|
||||
adds the sample from one second ago to it.
|
||||
adds the sample from 1.5 seconds ago to it.
|
||||
|
||||
For this, we'll need to keep track of the last 48k samples - exactly one seconds worth of audio. We can do this using a
|
||||
For this, we'll need to keep track of the last 72k samples - exactly 1.5 seconds worth of audio. We can do this using a
|
||||
[Ring Buffer], which helps makes things a little more efficient.
|
||||
|
||||
```lua {data-peripheral=speaker}
|
||||
local dfpwm = require("cc.audio.dfpwm")
|
||||
local speaker = peripheral.find("speaker")
|
||||
|
||||
-- Speakers play at 48kHz, so one second is 48k samples. We first fill our buffer
|
||||
-- Speakers play at 48kHz, so 1.5 seconds is 72k samples. We first fill our buffer
|
||||
-- with 0s, as there's nothing to echo at the start of the track!
|
||||
local samples_i, samples_n = 1, 48000
|
||||
local samples_i, samples_n = 1, 48000 * 1.5
|
||||
local samples = {}
|
||||
for i = 1, samples_n do samples[i] = 0 end
|
||||
|
||||
@@ -162,7 +162,7 @@ for chunk in io.lines("data/example.dfpwm", 16 * 1024) do
|
||||
for i = 1, #buffer do
|
||||
local original_value = buffer[i]
|
||||
|
||||
-- Replace this sample with its current amplitude plus the amplitude from one second ago.
|
||||
-- Replace this sample with its current amplitude plus the amplitude from 1.5 seconds ago.
|
||||
-- We scale both to ensure the resulting value is still between -128 and 127.
|
||||
buffer[i] = original_value * 0.6 + samples[samples_i] * 0.4
|
||||
|
||||
@@ -175,6 +175,11 @@ for chunk in io.lines("data/example.dfpwm", 16 * 1024) do
|
||||
while not speaker.playAudio(buffer) do
|
||||
os.pullEvent("speaker_audio_empty")
|
||||
end
|
||||
|
||||
-- The audio processing above can be quite slow and preparing the first batch of audio
|
||||
-- may timeout the computer. We sleep to avoid this.
|
||||
-- There's definitely better ways of handling this - this is just an example!
|
||||
sleep(0.05)
|
||||
end
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user