Skip to content

Commit 0d7f2a7

Browse files
committed
feat: new class builder docs
1 parent 1eca560 commit 0d7f2a7

File tree

10 files changed

+843
-285
lines changed

10 files changed

+843
-285
lines changed

docs/.vitepress/config.mts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export default defineConfig({
4747
{ text: 'Mixin Library', link: '/reference/mixin-lib' },
4848
{ text: 'Class Building', link: '/reference/class-building' },
4949
]
50+
},
51+
{
52+
text: 'Asides',
53+
items: [
54+
{ text: 'Type Mapping Reference', link: '/reference/asides/type-table' }
55+
]
5056
}
5157
],
5258

@@ -71,8 +77,10 @@ export default defineConfig({
7177
}).use(footnote)
7278
},
7379
lineNumbers: true,
80+
stripMarkersFromSnippets: true,
7481
},
7582

83+
7684
vite: {
7785
plugins: [
7886
groupIconVitePlugin({
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ prev:
55
next: false
66
---
77

8-
# Type Mapping Reference
8+
# Aside - Type Mapping Reference
99

1010
| Lua Type | Java Type |
1111
| :--------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
12-
| `nil` | `null`, `void`, `Void` [^1] |
13-
| `number` | `byte`, `short`, `int`, `long`, `float`, `double`, `Byte`, `Short`, `Int`, `Long`, `Float`, `Double` [^2] |
12+
| `nil` | `null` |
13+
| `number` | `byte`, `short`, `int`, `long`, `float`, `double`, `Byte`, `Short`, `Int`, `Long`, `Float`, `Double` [^1] |
1414
| `boolean` | `boolean`, `Boolean` |
1515
| `string` | `String` |
16-
| `function` | *instance* [^3] |
17-
| `table` | [See Source code](https://github.com/moongardenmods/allium/blob/main/allium/src/main/java/dev/hugeblank/allium/loader/type/coercion/TypeCoercions.java#L315-L330)[^4] |
18-
| `userdata` | *instance*, `Class`, `EClass` [^5] |
16+
| `function` | *instance* [^2] |
17+
| `table` | [See Source code](https://github.com/moongardenmods/allium/blob/main/allium/src/main/java/dev/hugeblank/allium/loader/type/coercion/TypeCoercions.java#L315-L330)[^3] |
18+
| `userdata` | *instance*, `Class`, `EClass` [^4] |
1919

20-
[^1]: Can only be used as `void` or `Void` when describing a method to create or override during class building.
21-
[^2]: If a number greater than the max size of the Java type is provided, it overflows, wrapping around. (ex. if passing 256 where a byte is expected, the resulting byte will be 0)
22-
[^3]: When going from Lua to Java, converted to an instance of a functional interface (java interface with only one method), where applicable. see [Callback Methods](#callback-methods)
23-
[^4]: When going from Java to Lua, converted only if the java method's return value is annotated with `@CoerceToNative`. When going from Lua to Java, converted unconditionally.
24-
[^5]: Java classes and objects are wrapped as userdata. Additionally, where a `Class` or `EClass` are expected, a userdata passed directly from `require` can be used.
20+
[^1]: If a number greater than the max size of the Java type is provided, it overflows, wrapping around. (ex. if passing 256 where a byte is expected, the resulting byte will be 0)
21+
[^2]: When going from Lua to Java, converted to an instance of a functional interface (java interface with only one method), where applicable. see [Callback Methods](#callback-methods)
22+
[^3]: When going from Java to Lua, converted only if the java method's return value is annotated with `@CoerceToNative`. When going from Lua to Java, converted unconditionally.
23+
[^4]: Java classes and objects are wrapped as userdata. Additionally, where a `Class` or `EClass` are expected, a userdata passed directly from `require` can be used.

docs/reference/builders/clinit.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
prev:
3+
text: 'Class Building - classBuilder:clinit()'
4+
link: '/reference/class-building#classbuilder-clinit'
5+
next: false
6+
---
7+
8+
9+
# Class Initializer Builder
10+
11+
Class initializers are invoked on class load, and are meant to set static variables that do not have a pre-defined value.
12+
13+
## `clinitBuilder:index(index)`
14+
15+
Adds an index to this class initializer that is used instead of the default name `initializer` when running `classBuilder:define()`.
16+
17+
### Parameters
18+
19+
1. `index` - `string`: A unique index that will be used as the name of the handler function in the table provided to `classBuilder:define()`.
20+
21+
### Returns
22+
23+
- `userdata [instance]` This class initializer builder.
24+
25+
## `clinitBuilder:build()`
26+
27+
Finalize the class initializer, preparing it for definition in `classBuilder:define()`.
28+
29+
### Returns
30+
31+
- `userdata [instance]` The class builder for which this class initializer is being built for.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
prev:
3+
text: 'Class Building - classBuilder:constructor()'
4+
link: '/reference/class-building#classbuilder-constructor'
5+
next: false
6+
---
7+
8+
# Constructor Builder
9+
10+
## `constructorBuilder:index(index)`
11+
12+
Adds an index to this constructor that is used instead of the default name `constructor` when running `classBuilder:define()`.
13+
14+
### Parameters
15+
16+
1. `index` - `string`: A unique index that will be used as the name of the method in the table provided to `classBuilder:define()`.
17+
18+
### Returns
19+
20+
- `userdata [instance]` This constructor builder.
21+
22+
## `constructorBuilder:access(access)`
23+
24+
Defines this constructors access. If no access table is provided, the default `package-private` scope is used.
25+
26+
### Parameters
27+
28+
1. `access` - `table`: Access flags for the constructor. See [Access Modifier Table](#access-modifier-table)
29+
30+
### Returns
31+
32+
- `userdata [instance]` This constructor builder.
33+
34+
## `constructorBuilder:this(params)`
35+
36+
Indicates that this constructor should initialize using another constructor within this class.
37+
38+
### Parameters
39+
40+
1. `params` - `table<userdata [class]>`: The parameters of the `this` constructor.
41+
42+
### Returns
43+
44+
- `userdata [instance]` This constructor builder.
45+
46+
## `constructorBuilder:super(params)`
47+
48+
Indicates that this constructor should initialize using one of the parent's class constructors.
49+
50+
### Parameters
51+
52+
1. `params` - `table<userdata [class]>`: The parameters of the `super` constructor.
53+
54+
### Returns
55+
56+
- `userdata [instance]` This constructor builder.
57+
58+
## `constructorBuilder:parameters(params)`
59+
60+
Defines the parameters of this constructor. If omitted, defaults to the parameters of the `this` or `super` constructor, whichever is defined.
61+
If the parameters of the constructor being built, and `super` or `this` constructor match, parameters do not need to be defined.
62+
63+
### Parameters
64+
65+
1. `params` - `table<userdata [class]>`: The parameters of the constructor.
66+
67+
### Returns
68+
69+
- `userdata [instance]` This constructor builder.
70+
71+
## `constructorBuilder:remapper(func)`
72+
73+
Function that allows for the parameters of the constructor being built to be adapted to the `this` or `super` constructor, whichever is defined.
74+
If the parameters of the constructor being built, and `super` or `this` constructor match, a remapper function is not needed.
75+
76+
### Parameters
77+
78+
1. `remapper` - `function?`: An function that accepts the parameters of the constructor that will eventually be built. Returns what will be fed into the `super` or `this` constructor.
79+
80+
### Returns
81+
82+
- `userdata [instance]` This constructor builder.
83+
84+
## `constructorBuilder:definesFields()`
85+
86+
Indicates that this constructor will define instance fields. Constructors without this method invoked will not be able to define fields.
87+
If invoked, Instance fields created by `classBuilder:field()` that do not have a default value must be initialized in this constructor.
88+
89+
### Returns
90+
91+
- `userdata [instance]` This constructor builder.
92+
93+
## `constructorBuilder:build()`
94+
95+
### Returns
96+
97+
- `userdata [instance]` The class builder for which this constructor is being built for.
98+
99+
Finalize the constructor, preparing it for definition in `classBuilder:define()`.

docs/reference/builders/method.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
prev:
3+
text: 'Class Building - classBuilder:method()'
4+
link: '/reference/class-building#classbuilder-method'
5+
next: false
6+
---
7+
8+
# Method Builder
9+
10+
## `methodBuilder:index(index)`
11+
12+
Adds an index to this method that is used instead of the method name when running `classBuilder:define()`.
13+
14+
### Parameters
15+
16+
1. `index` - `string`: A unique index that will be used as the name of the handler function in the table provided to `classBuilder:define()`.
17+
18+
### Returns
19+
20+
- `userdata [instance]` This method builder.
21+
22+
## `methodBuilder:override(name, params)`
23+
24+
Overrides a method in the parent class.
25+
26+
If provided, `methodBuilder:name()`, `methodBuilder:params()`, and `methodBuilder:returnType()` must not be used,
27+
and `methodBuilder:access()` can only be used to maintain or increase the scope of the method, never decrease.
28+
29+
### Parameters
30+
31+
1. `name` - `string`: The name of the method to override.
32+
1. `params` - `table<userdata [class]>`: The parameters of the method to override.
33+
34+
### Returns
35+
36+
- `userdata [instance]` This method builder.
37+
38+
## `methodBuilder:access(access)`
39+
40+
Defines this methods access. If no access table is provided, the default `package-private` scope is used.
41+
42+
If the method to be created is abstract, a function defintion must not be submitted.
43+
44+
If the method is not static then `self` represents `this`.
45+
46+
If the method is static then `self` reprents a `userdata [class]` of the class being built, with access to all static fields.
47+
48+
### Parameters
49+
50+
1. `access` - `table`: Access flags for the method. See [Access Modifier Table](#access-modifier-table)
51+
52+
### Returns
53+
54+
- `userdata [instance]` This method builder.
55+
56+
## `methodBuilder:name(name)`
57+
58+
Define a name for the method to be created.
59+
60+
### Parameters
61+
62+
1. `name` - `string`: The method name.
63+
64+
### Returns
65+
66+
- `userdata [instance]` This method builder.
67+
68+
## `methodBuilder:parameters(params)`
69+
70+
Defines the parameters of this method.
71+
72+
### Parameters
73+
74+
1. `params` - `table<userdata [class]>`: The parameters of the method.
75+
76+
### Returns
77+
78+
- `userdata [instance]` This method builder.
79+
80+
## `methodBuilder:returnType(returnType)`
81+
82+
Defines the return type of this method.
83+
84+
### Parameters
85+
86+
1. `returnType` - `userdata [class]`: The return type of the method.
87+
88+
### Returns
89+
90+
- `userdata [instance]` This method builder.
91+
92+
## `methodBuilder:build()`
93+
94+
Finalize the method, preparing it for definition in `classBuilder:define()`.
95+
96+
### Returns
97+
98+
- `userdata [instance]` The class builder for which this method is being built for.

0 commit comments

Comments
 (0)