You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Compatibility.md
+36-8Lines changed: 36 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,10 @@
2
2
sidebar_position: 10
3
3
---
4
4
5
-
## How compatible with Lua is Pluto?
6
-
Pluto is compatible with most Lua source code. However, it's imperfect. Due to that, Pluto has several compatibility options.
7
-
### Where are the incompatibilities?
5
+
Pluto aims to be source- and bytecode-compatible with existing Lua code such that it can simply be used as a drop-in replacement for Lua, and Lua modules can simply be used in Pluto codebases. In the vast majority of cases, we do succeed, but there are a few things to be aware of.
6
+
7
+
## New Keywords
8
+
8
9
Pluto adds the following reserved tokens:
9
10
-`switch`
10
11
-`continue`
@@ -18,14 +19,13 @@ Pluto adds the following reserved tokens:
18
19
19
20
Which means you can't use them as identifiers. They can still be used with short-hand table indexes and goto labels because Pluto [allows reserved keywords to be used in those contexts](QoL%20Improvements/Reserved%20Identifiers).
20
21
21
-
### How to fix it?
22
-
All of these incompatible keywords can be disabled:
22
+
### Mitigations
23
+
23
24
-**For Integrators:** Check your `luaconf.h` file to find the relevant macros under the "Compatibility" heading.
24
25
-**For Scripters:** Use `pluto_use` in the source files. `-- @pluto_use * = false` to simply disable all incompatible keywords.
25
26
-**For Users:** Pass the `-c` flag to `pluto` or `plutoc`.
26
27
27
-
## For Scripters
28
-
Scripters are given final say in how Compatibility Mode works within their scripts.
28
+
The following sections will go more in-depth on source-level mitigations (for scripters).
29
29
30
30
### Compile-time Configuration (pluto_use)
31
31
You can change the meaning of Pluto's reserved tokens at any point in your scripts using the `--@pluto_use` comment or `pluto_use` statement.
@@ -72,4 +72,32 @@ These are what they look like:
72
72
-`pluto_parent`
73
73
-`pluto_export`
74
74
-`pluto_try`
75
-
-`pluto_catch`
75
+
-`pluto_catch`
76
+
77
+
## Default Table Metatable
78
+
79
+
This is [a feature in Pluto](Runtime%20Environment/Global%20&%20Base#default-metatables) that, by itself, is a benign QoL improvement for developers. However, in combination with our added standard library functions like [table.min](Runtime%20Environment/Table#tablemin), it can be an unexpected semantic change:
80
+
81
+
```pluto showLineNumbers
82
+
local function roll(opts)
83
+
return math.random(opts.min or 1, opts.max or 100)
84
+
end
85
+
print(roll{ max = 10 })
86
+
```
87
+
```
88
+
pluto: test.pluto:2: bad argument #1 to 'random' (number expected, got function)
89
+
stack traceback:
90
+
[C]: in function 'math.rand'
91
+
test.pluto:2: in local 'roll'
92
+
test.pluto:4: in main chunk
93
+
```
94
+
95
+
Integrators can disable this feature by defining the `PLUTO_NO_DEFAULT_TABLE_METATABLE` macro in their luaconf.h or build config, to aid in a smooth transition, should scripts in their ecosystem require it.
96
+
97
+
Scripters are advised to use `rawget` and/or `type` to better codify their expectations. For example, the example above seems to care only about providing fallback values and not at all about type-checking, so `rawget` would be an excellent fit for it:
98
+
```pluto
99
+
local function roll(opts)
100
+
return math.random(rawget(opts, "min") or 1, rawget(opts, "max") or 100)
0 commit comments