Add Lua integration and run keyword

This commit is contained in:
Moritz Hölting 2024-04-06 19:08:53 +02:00
parent f43693ec19
commit e908e4d564
2 changed files with 51 additions and 7 deletions

View File

@ -8,7 +8,7 @@ sidebar:
---
## Comments
Single line comments start with `//` and continue until the end of the line.
Single-line comments start with `//` and continue until the end of the line.
Multiline comments start with `/*` and end with `*/`.
```shulkerscript
@ -32,6 +32,10 @@ They start with a `/` and are followed by the command.
This will result in `say Hello, world!` being included in the `.mcfunction` file.
:::note
Literal commands are just syntactic sugar for the [`run`](#run) keyword.
:::
## Functions
Functions are blocks of code that can be executed.
They start with `fn` followed by the name of the function, parenthesis and a block of code.
@ -51,8 +55,7 @@ ShulkerScript always requires a `main` function to be present in the code.
### Annotations
Annotations are special attributes that can be attached to functions.
They start with `#` followed by the name of the annotation in square brackets. Some annotations can have arguments assigned to them with the `=` operator.
Currently the following annotations are supported:
Currently, the following annotations are supported:
- `#[tick]`: The function will be executed every tick.
- `#[load]`: The function will be executed when the data pack is loaded.
- `#[deobfuscate]`: The function will keep the original name in the output (path of the `.shu`-file followed by the function name).
@ -84,7 +87,7 @@ if ("block ~ ~-1 ~ minecraft:stone") {
```
## Groupings
Groupings are used to group multiple commands together into one `mcfunction` file without declaring a new function.
Groupings are used to group multiple commands into one `mcfunction` file without declaring a new function.
This can be used for commands that need to be executed atomically.
```shulkerscript
group {
@ -92,3 +95,22 @@ group {
/say World
}
```
## Run
The `run` keyword is used to evaluate the following expression and include the resulting command in the output.
```shulkerscript
run "say Hello, world!"
```
:::tip
In most cases, you can use [literal commands](#literal-commands) instead of the `run` keyword.
:::
## Lua Code
The `lua` keyword is used to embed Lua code in your ShulkerScript code. It can be combined with the `run` keyword to include the result of the Lua code in the output.
```shulkerscript
run lua() {
// Lua code goes here
return "Hello, Lua!";
}
```

View File

@ -0,0 +1,22 @@
---
title: Lua Integration
description: Reference for writing Lua code in ShulkerScript
sidebar:
badge:
text: WIP
variant: caution
---
ShulkerScript supports writing Lua code directly in your scripts. This allows you to use Lua's powerful features and libraries to extend the functionality of your scripts.
The Lua code is embedded in the ShulkerScript code using the `lua` keyword. In the future, you will be able to pass arguments to the Lua code, but for now, you can only write Lua code without arguments.
Your Lua code should return a string value when used in combination with the run keyword. This string returned will be included in the output.
## Syntax
```shulkerscript
run lua() {
// Lua code goes here
return "Hello, Lua!";
}
```