diff --git a/.github/workflows/test-skripts.yml b/.github/workflows/test-skripts.yml index 700330c..61be5e3 100644 --- a/.github/workflows/test-skripts.yml +++ b/.github/workflows/test-skripts.yml @@ -43,7 +43,7 @@ jobs: run: | mkdir -p build/libs curl -L -o build/libs/skript-reflect.jar \ - https://github.com/SkriptLang/skript-reflect/releases/download/v2.6.1/skript-reflect-2.6.1.jar + https://github.com/SkriptLang/skript-reflect/releases/download/v2.6.3/skript-reflect-2.6.3.jar - name: Download Routines from JitPack run: | @@ -54,26 +54,41 @@ jobs: curl -L --fail -o build/libs/skript-reflect/routines-paper.jar \ https://jitpack.io/com/github/devdinc/routines/routines-paper/v2.2.1/routines-paper-v2.2.1.jar - # Disable pdc for now, i want to remove skbee req - # Disable config reload + - name: Prepare scripts run: | mkdir -p tests/scripts rsync -av scripts/ tests/scripts/ - mv tests/scripts/libs/singlelinesection.sk tests/scripts/libs/0_singlelinesection.sk - rm -f tests/scripts/utils/testframework.sk rm -f tests/scripts/utils/configreloadv2.sk + + - name: Force-load Skript native test suite + run: | + cat > tests/zzzz_force_native_tests.sk <<'EOF' + import: + ch.njol.skript.test.runner.SkriptTestEvent + test "run devdinc tests": + event is instance of SkriptTestEvent + send "Running devdinc tests" to console + + set {_list::string} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313" + set {_list::boolean} to false + + call custom event "skriptTest" with {_list::*} + + set {_tests::*} to all tests + autorun {_tests::*} + EOF - name: Run tests uses: devdinc/skript-test-action@v1.3 with: - skript_repo_url: https://github.com/devdinc/Skript.git + skript_repo_url: https://github.com/SkriptLang/Skript.git # directory where your test scripts are located (relative to repo root) test_script_directory: tests # Skript version or ref (tag, branch, or commit) - skript_repo_ref: ef28bd5 # 2.13.2 + skript_repo_ref: dev/feature # directory containing addon/plugin jars (relative to repo root) extra_plugins_directory: build/libs diff --git a/.restructure b/.restructure index 64b3cec..e518a3b 100644 --- a/.restructure +++ b/.restructure @@ -1,7 +1,7 @@ using scripts prefix: - 0 libs/singlelinesection.sk + 0 libs/parser/singlelinesection.sk 1 libs/functionsv2.sk 2 libs/routines.sk 3 . diff --git a/README.md b/README.md index 38d5b1d..1a025f2 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,3 @@ If you encounter errors such as `Can't understand this expression`, the issue is Skript loads files alphabetically, with folders being prioritized. To control load order, prefix the Skript file with a folder or a character such as `0_` or `!` (e.g., `!testframework.sk`) - -## TODO - -Currents plans include: -- multiline lambda expression -- making the test framework support extending over the skriptlang native test suit -- Auto casting for primitives, pdc.sk(new Byte,Integer etc) diff --git a/docs/functions.md b/docs/functions.md index 073b75f..d2991e0 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -31,16 +31,17 @@ All generated lambdas are real Java proxy instances. --- -## Core Lambda Syntax +## Core Lambda Syntax (Single-Line) ### 1. Returning Lambda ```skript lambda []: -``` +```` * Returns a value * Automatically mapped to a Java functional interface +* Return vs effect behavior is auto-detected --- @@ -66,6 +67,67 @@ lambda []:+ --- +## Multiline Lambdas (Section-Based) + +Lambdas may also be written as **multiline sections**. +These allow more complex logic while still compiling into Java functional interfaces. + +Multiline lambdas are created using **typed aliases** (`new runnable:`, `new function {_x}:`, etc.). + +--- + +### Multiline Non-Returning Lambda + +Maps to: + +* `Runnable` +* `Consumer` +* `BiConsumer` + +depending on arity. + +```skript +set {_task} to new runnable: + broadcast "working" + broadcast "still working" +``` + +Rules: + +* Produces **no return value** +* All lines must be **effects** +* `return` is not allowed + +--- + +### Multiline Returning Lambda + +Multiline returning lambdas **must use the `return` effect**. +The lambda does **not** infer a return value from the last line. + +```skript +set {_double} to new function {_x}: + broadcast "doubling %{_x}%" + return {_x} * 2 +``` + +Rules: + +* `return ` is **mandatory** +* The final line does **not** need to be an expression +* Effects may appear anywhere before `return` +* Multiple control-flow paths may use `return` + +Maps to: + +* `Supplier` +* `Function` +* `BiFunction` + +based on arity. + +--- + ## Java Interface Mapping (Arity-Based) The target Java interface is selected based on **parameter count** and **return behavior**. @@ -93,7 +155,9 @@ The target Java interface is selected based on **parameter count** and **return > Lambdas with more than **2 parameters are not supported**. -### Workaround for Higher Arity +--- + +## Workaround for Higher Arity Pass a single composite object instead: @@ -196,7 +260,8 @@ biaccepter {_a}, {_b}: ```skript set {_f} to function {_x}: {_x} * 2 -set {_r} to runnable: broadcast "hello" +set {_r} to runnable: + broadcast "hello" ``` --- @@ -239,38 +304,38 @@ set {_adder} to lambda {_m}:- {_m}.values().stream().forEach({_inlineforeach}) ## Limitations -* Lambdas are **strictly single-line** -* Returning lambdas (`:` / `:+`) **cannot contain effects** -* Non-returning lambdas (`:-`) **cannot contain expressions** -* Non-returning lambdas **cannot return values** +* Lambdas may be **single-line or multiline** +* Single-line lambdas infer return vs effect behavior +* Multiline returning lambdas **require `return`** +* Multiline non-returning lambdas **must not return** +* Lambdas are limited to **0–2 parameters** * Variable lists as parameters are **not supported** * Arrays are unreliable inside lambdas: * Indexing (`[n]`) does not work * Use `spread(...)` before passing arrays -* Imported classes or complex expressions **may fail inline** - - * Mitigations: +* Imported classes or complex expressions may fail inline - * Explicitly use `:+` or `:-` - * Wrap logic in a normal function and call it + * Prefer multiline lambdas + * Or wrap logic in a normal Skript function --- ## Notes -* Return vs effect behavior is **auto-detected** unless overridden with `:-` or `:+` +* Single-line lambdas auto-detect return vs effect +* Multiline lambdas require explicit intent * Lambdas are real Java proxy objects and fully compatible with: * Java streams * Java APIs * skript-reflect usage +* Experimentally, local values are passed into lambda sections. Use with care. --- -* Experimentally local values are passed into the section. You can use local values, but be careful. - ## Planned * Additional utility expressions (e.g., `for each` helpers) * These will be introduced in **separate files** + diff --git a/docs/pdc.md b/docs/pdc.md index 2adee52..689d457 100644 --- a/docs/pdc.md +++ b/docs/pdc.md @@ -1,8 +1,5 @@ - # Persistent Data Container (PDC) Utility Expressions for Skript -> **WARNING:** Read migration notes carefully before upgrading. - --- ## Overview @@ -11,94 +8,98 @@ This document describes a set of Skript expressions and helpers for interacting It supports: -- Native `PersistentDataType` (PDT) values +- Native `PersistentDataType` (PDT) values - Arbitrary object storage via Java serialization into `BYTE_ARRAY` --- -## Migration Notice (Base64 Removed) +## Requirements -Previous versions serialized arbitrary objects using Base64 encoding and stored them as `STRING` values. +- Paper server +- Skript +- skript-reflect -**This implementation no longer uses Base64.** +--- -Arbitrary objects are now: +## Key Features -- Serialized directly using `BukkitObjectOutputStream` -- Stored natively as `PersistentDataType.BYTE_ARRAY` +### 1. Unified `key … in pdc` Expression -This is a **storage-format change only**. -Arbitrary object support remains fully supported. +- Read, write, and delete PDC entries using a single expression +- Automatically resolves: + - `PersistentDataHolder` → `PersistentDataContainer` -### Required User Action +--- -- Existing Base64-encoded PDC values are **not compatible** -- Stored data must be migrated or deleted +### 2. Native and Arbitrary Object Storage -Scripts do **not** require syntax changes, but values written by older versions will not deserialize correctly. +- When a `PersistentDataType` is provided: + → Values are stored natively using that PDT +- When omitted: + → Values are serialized and stored as `PersistentDataType.BYTE_ARRAY` --- -## Requirements +### 3. Built-in NamespacedKey Handling -- Paper server -- Skript -- skript-reflect +There is **no standalone NamespacedKey expression**. ---- +Instead, namespaced keys are handled directly by the main expression using string input. -## Key Features +Key strings must be in the form: -### 1. Unified `key in pdc` Expression +``` -- Read, write, and delete PDC entries using a single expression -- Automatically resolves: - - `PersistentDataHolder` → `PersistentDataContainer` +namespace:key -### 2. Native and Arbitrary Object Storage +```` -- When a `PersistentDataType` is provided: - → Values are stored natively -- When omitted: - → Values are serialized and stored as `BYTE_ARRAY` +Example: -### 3. NamespacedKey Convenience Expression +```skript +"minecraft:foo" +"myplugin:data" +```` -- Allows creation of `NamespacedKey` from strings such as: - - `plugin:key` +--- ### 4. Safety and Validation -- Runtime validation ensures correct types for: - - Key - - Container - - PersistentDataType -- Invalid expressions fail silently to avoid hard Skript errors +* Runtime validation ensures correct types for: + + * Key string + * Container / holder + * PersistentDataType (if provided) +* Invalid expressions fail silently to avoid hard Skript errors --- ## Serialization Notes -- Arbitrary objects are serialized using `BukkitObjectOutputStream` -- Data is stored directly as `byte[]` via `PersistentDataType.BYTE_ARRAY` -- Objects **must** implement `java.io.Serializable` - -### Compared to Base64 - -- Lower overhead -- No string encoding or decoding -- Direct compatibility with Bukkit PDC APIs +* Arbitrary objects are serialized using `BukkitObjectOutputStream` +* Data is stored directly as `byte[]` via `PersistentDataType.BYTE_ARRAY` +* Objects **must** implement `java.io.Serializable` --- ## Syntax Summary +### Core Expression + +```skript +expression [devdinc] [namespaced]( |-)key %string% [with]in %pdcholder/pdc% [for %-pdt%] +``` + +--- + ### Reading ```skript set {_value} to key "plugin:test" within player's pdc set {_value} to key "plugin:test" in player's pdc for pdt string -```` +``` + +--- ### Writing @@ -107,6 +108,8 @@ set key "plugin:test" within player's pdc to {_object} set key "plugin:test" in player's pdc for pdt integer to 5 ``` +--- + ### Deleting ```skript @@ -115,10 +118,11 @@ delete key "plugin:test" within player's pdc --- -## Notes +## Behavior Notes * If no `PersistentDataType` is specified, `BYTE_ARRAY` storage is used -* Deleting a key or setting its value to `null` removes the entry +* Setting a key to `null` removes the entry +* Deleting a key removes it regardless of storage type --- @@ -126,4 +130,7 @@ delete key "plugin:test" within player's pdc * Deserialization failures will propagate runtime errors * Class definition changes may break previously serialized data -* Old Base64-encoded values must be migrated manually +* Stored objects must remain compatible with Java serialization + +--- + diff --git a/docs/scopedvariables.md b/docs/scopedvariables.md new file mode 100644 index 0000000..d8022cc --- /dev/null +++ b/docs/scopedvariables.md @@ -0,0 +1,249 @@ +# Scoped Variables Utility for Skript + +This module introduces **scoped variables**, allowing variables to be namespaced automatically by +script, folder (package), or a custom scope string. + +It provides: + +- A configurable **default scope per script** +- A `scoped variable` expression that transparently rewrites variable paths +- Full support for **get / set / add / remove / delete / reset** +- Correct handling of **local**, **ephemeral**, and **list** variables + +All scoping is implemented by rewriting variable names internally. + +--- + +## Concepts + +### What Is a Scoped Variable? + +A scoped variable is a normal Skript variable whose **storage key is prefixed with a scope**. + +Instead of: + +```skript +set {count} to 1 +```` + +you get: + +```text +scoped::::count +``` + +Scopes prevent collisions between scripts, folders, or logical modules while still using Skript’s variable system. + +--- + +## Default Scope per Script + +Each script can define a **default scope** that is used whenever no explicit scope is provided. + +### Effect Syntax + +```skript +set default scope for scoped variables in current script to + current folder + current package + current script + folder + package +