Docs(shortcuts): add expr and starlark (#2759)
Signed-off-by: Birkhoff Lee <git@birkhoff.me>
This commit is contained in:
parent
c244229ffb
commit
46bb6c38ff
@ -71,6 +71,13 @@ export default defineConfig({
|
|||||||
|
|
||||||
base: '/clash/',
|
base: '/clash/',
|
||||||
|
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
'link',
|
||||||
|
{ rel: 'icon', type: "image/x-icon", href: '/clash/logo.png' }
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
outline: 'deep',
|
outline: 'deep',
|
||||||
|
|
||||||
|
@ -7,12 +7,10 @@ sidebarOrder: 6
|
|||||||
|
|
||||||
Clash Premium implements the Scripting feature powered by Python3, enableing users to programmatically select policies for the packets with dynamic flexibility.
|
Clash Premium implements the Scripting feature powered by Python3, enableing users to programmatically select policies for the packets with dynamic flexibility.
|
||||||
|
|
||||||
You can either controll the entire rule-matching engine with a single Python script, or define a number of shortcuts and use them in companion with the regular rules. This page refers to the latter feature, for the former, see [Script](./script.md).
|
You can either controll the entire rule-matching engine with a single Python script, or define a number of shortcuts and use them in companion with the regular rules. This page refers to the latter feature. For the former, see [Script](./script.md).
|
||||||
|
|
||||||
This feature enables the use of script in `rules` mode. By default, DNS resolution takes place for SCRIPT rules. `no-resolve` can be appended to the rule to prevent the resolution. (i.e.: `SCRIPT,quic,DIRECT,no-resolve`)
|
This feature enables the use of script in `rules` mode. By default, DNS resolution takes place for SCRIPT rules. `no-resolve` can be appended to the rule to prevent the resolution. (i.e.: `SCRIPT,quic,DIRECT,no-resolve`)
|
||||||
|
|
||||||
**NOTE: ****`src_port`**** and ****`dst_port`**** are number**
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
mode: Rule
|
mode: Rule
|
||||||
|
|
||||||
@ -27,11 +25,33 @@ rules:
|
|||||||
- SCRIPT,quic,REJECT
|
- SCRIPT,quic,REJECT
|
||||||
```
|
```
|
||||||
|
|
||||||
## Function Definitions
|
## Evaluation Engines
|
||||||
|
|
||||||
|
[Expr](https://expr.medv.io/) is used as the default engine for Script Shortcuts, offering 10x to 20x performance boost compared to Starlark.
|
||||||
|
|
||||||
|
[Starlark](https://github.com/google/starlark-go) is a Python-like langauge for configuration purposes, you can also use it for Script Shortcuts.
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
- network: string
|
||||||
|
- type: string
|
||||||
|
- src_ip: string
|
||||||
|
- dst_ip: string
|
||||||
|
- src_port: uint16
|
||||||
|
- dst_port: uint16
|
||||||
|
- host: string
|
||||||
|
- process_path: string
|
||||||
|
|
||||||
|
::: warning
|
||||||
|
Starlark is missing `process_path` variable for now.
|
||||||
|
:::
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type resolve_ip = (host: string) => string // ip string
|
type resolve_ip = (host: string) => string // ip string
|
||||||
type in_cidr = (ip: string, cidr: string) => boolean // ip in cidr
|
type in_cidr = (ip: string, cidr: string) => boolean // ip in cidr
|
||||||
|
type in_ipset = (name: string, ip: string) => boolean // ip in ipset
|
||||||
type geoip = (ip: string) => string // country code
|
type geoip = (ip: string) => string // country code
|
||||||
type match_provider = (name: string) => boolean // in rule provider
|
type match_provider = (name: string) => boolean // in rule provider
|
||||||
type resolve_process_name = () => string // find process name (curl .e.g)
|
type resolve_process_name = () => string // find process name (curl .e.g)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user